|
31 | 31 | import java.util.ArrayList; |
32 | 32 | import java.util.Arrays; |
33 | 33 | import java.util.List; |
| 34 | +import java.util.function.Function; |
34 | 35 |
|
35 | 36 | public class Configuration { |
36 | 37 | public static final String SUCCESS_COUNTER_METER_NAME = "#Successful Operations"; |
@@ -146,6 +147,9 @@ public class Configuration { |
146 | 147 | @Parameter(names = "isPartitionLevelCircuitBreakerEnabled", description = "A flag to denote whether partition level circuit breaker is enabled.") |
147 | 148 | private String isPartitionLevelCircuitBreakerEnabled = String.valueOf(true); |
148 | 149 |
|
| 150 | + @Parameter(names = "-isManagedIdentityRequired", description = "A flag to denote whether benchmark-specific CosmosClient instance should use Managed Identity to authenticate.") |
| 151 | + private String isManagedIdentityRequired = String.valueOf(false); |
| 152 | + |
149 | 153 | @Parameter(names = "-operation", description = "Type of Workload:\n" |
150 | 154 | + "\tReadThroughput- run a READ workload that prints only throughput *\n" |
151 | 155 | + "\tReadThroughputWithMultipleClients - run a READ workload that prints throughput and latency for multiple client read.*\n" |
@@ -179,6 +183,10 @@ public class Configuration { |
179 | 183 | @Parameter(names = "-numberOfOperations", description = "Total NUMBER Of Documents To Insert") |
180 | 184 | private int numberOfOperations = 100000; |
181 | 185 |
|
| 186 | + public Boolean isManagedIdentityRequired() { |
| 187 | + return Boolean.parseBoolean(this.isManagedIdentityRequired); |
| 188 | + } |
| 189 | + |
182 | 190 | static class DurationConverter implements IStringConverter<Duration> { |
183 | 191 | @Override |
184 | 192 | public Duration convert(String value) { |
@@ -229,15 +237,6 @@ public Duration convert(String value) { |
229 | 237 | @Parameter(names = "-accountNameInGraphiteReporter", description = "if set, account name with be appended in graphite reporter") |
230 | 238 | private boolean accountNameInGraphiteReporter = false; |
231 | 239 |
|
232 | | - @Parameter(names = "-clientTelemetryEnabled", description = "Switch to enable client telemetry") |
233 | | - private String clientTelemetryEnabled = String.valueOf(false); |
234 | | - |
235 | | - @Parameter(names = "-clientTelemetrySchedulingInSeconds", description = "Client telemetry scheduling intervals in seconds") |
236 | | - private int clientTelemetrySchedulingInSeconds = 10 * 60; |
237 | | - |
238 | | - @Parameter(names = "-clientTelemetryEndpoint", description = "Client Telemetry Juno endpoint") |
239 | | - private String clientTelemetryEndpoint; |
240 | | - |
241 | 240 | @Parameter(names = "-pointLatencyThresholdMs", description = "Latency threshold for point operations") |
242 | 241 | private int pointLatencyThresholdMs = -1; |
243 | 242 |
|
@@ -588,22 +587,10 @@ public boolean isEncryptionEnabled() { |
588 | 587 | return encryptionEnabled; |
589 | 588 | } |
590 | 589 |
|
591 | | - public boolean isClientTelemetryEnabled() { |
592 | | - return Boolean.parseBoolean(clientTelemetryEnabled); |
593 | | - } |
594 | | - |
595 | 590 | public boolean isDefaultLog4jLoggerEnabled() { |
596 | 591 | return Boolean.parseBoolean(defaultLog4jLoggerEnabled); |
597 | 592 | } |
598 | 593 |
|
599 | | - public String getClientTelemetryEndpoint() { |
600 | | - return clientTelemetryEndpoint; |
601 | | - } |
602 | | - |
603 | | - public int getClientTelemetrySchedulingInSeconds() { |
604 | | - return clientTelemetrySchedulingInSeconds; |
605 | | - } |
606 | | - |
607 | 594 | public Integer getTupleSize() { |
608 | 595 | return tupleSize; |
609 | 596 | } |
@@ -851,4 +838,55 @@ public String[] tagsAsPrefix() { |
851 | 838 |
|
852 | 839 | return this.graphiteMeterRegistry; |
853 | 840 | } |
| 841 | + |
| 842 | + public static String getAadLoginUri() { |
| 843 | + return getOptionalConfigProperty( |
| 844 | + "AAD_LOGIN_ENDPOINT", |
| 845 | + "https://login.microsoftonline.com/", |
| 846 | + v -> v); |
| 847 | + } |
| 848 | + |
| 849 | + public static String getAadManagedIdentityId() { |
| 850 | + return getOptionalConfigProperty("AAD_MANAGED_IDENTITY_ID", null, v -> v); |
| 851 | + } |
| 852 | + |
| 853 | + public static String getAadTenantId() { |
| 854 | + return getOptionalConfigProperty("AAD_TENANT_ID", null, v -> v); |
| 855 | + } |
| 856 | + |
| 857 | + private static <T> T getOptionalConfigProperty(String name, T defaultValue, Function<String, T> conversion) { |
| 858 | + String textValue = getConfigPropertyOrNull(name); |
| 859 | + |
| 860 | + if (textValue == null) { |
| 861 | + return defaultValue; |
| 862 | + } |
| 863 | + |
| 864 | + T returnValue = conversion.apply(textValue); |
| 865 | + return returnValue != null ? returnValue : defaultValue; |
| 866 | + } |
| 867 | + |
| 868 | + private static String getConfigPropertyOrNull(String name) { |
| 869 | + String systemPropertyName = "COSMOS." + name; |
| 870 | + String environmentVariableName = "COSMOS_" + name; |
| 871 | + String fromSystemProperty = emptyToNull(System.getProperty(systemPropertyName)); |
| 872 | + if (fromSystemProperty != null) { |
| 873 | + return fromSystemProperty; |
| 874 | + } |
| 875 | + |
| 876 | + return emptyToNull(System.getenv().get(environmentVariableName)); |
| 877 | + } |
| 878 | + |
| 879 | + /** |
| 880 | + * Returns the given string if it is nonempty; {@code null} otherwise. |
| 881 | + * |
| 882 | + * @param string the string to test and possibly return |
| 883 | + * @return {@code string} itself if it is nonempty; {@code null} if it is empty or null |
| 884 | + */ |
| 885 | + private static String emptyToNull(String string) { |
| 886 | + if (string == null || string.isEmpty()) { |
| 887 | + return null; |
| 888 | + } |
| 889 | + |
| 890 | + return string; |
| 891 | + } |
854 | 892 | } |
0 commit comments