Skip to content

Commit 301e9ed

Browse files
authored
Integrate managed identity support for benchmarks. (Azure#44857)
* Add managed identity support for account to which benchmark specific workload hits. * Add managed identity support for account to which benchmark specific workload hits. * Add managed identity support for account to which benchmark specific workload hits. * Add managed identity support for account to which benchmark specific workload hits. * Add managed identity support for account to which benchmark specific workload hits. * Add managed identity support for account to which benchmark specific workload hits.
1 parent d2ecba3 commit 301e9ed

File tree

9 files changed

+457
-321
lines changed

9 files changed

+457
-321
lines changed

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsynReadWithMultipleClients.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ private void createClients() {
197197
.preferredRegions(this.configuration.getPreferredRegionsList())
198198
.consistencyLevel(configuration.getConsistencyLevel())
199199
.connectionSharingAcrossClientsEnabled(true)
200-
.contentResponseOnWriteEnabled(configuration.isContentResponseOnWriteEnabled())
201-
.clientTelemetryEnabled(configuration.isClientTelemetryEnabled());
200+
.contentResponseOnWriteEnabled(configuration.isContentResponseOnWriteEnabled());
202201

203202
if (this.configuration.getConnectionMode().equals(ConnectionMode.DIRECT)) {
204203
cosmosClientBuilder = cosmosClientBuilder.directMode(DirectConnectionConfig.getDefaultConfig());

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncBenchmark.java

Lines changed: 226 additions & 168 deletions
Large diffs are not rendered by default.

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/Configuration.java

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.ArrayList;
3232
import java.util.Arrays;
3333
import java.util.List;
34+
import java.util.function.Function;
3435

3536
public class Configuration {
3637
public static final String SUCCESS_COUNTER_METER_NAME = "#Successful Operations";
@@ -146,6 +147,9 @@ public class Configuration {
146147
@Parameter(names = "isPartitionLevelCircuitBreakerEnabled", description = "A flag to denote whether partition level circuit breaker is enabled.")
147148
private String isPartitionLevelCircuitBreakerEnabled = String.valueOf(true);
148149

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+
149153
@Parameter(names = "-operation", description = "Type of Workload:\n"
150154
+ "\tReadThroughput- run a READ workload that prints only throughput *\n"
151155
+ "\tReadThroughputWithMultipleClients - run a READ workload that prints throughput and latency for multiple client read.*\n"
@@ -179,6 +183,10 @@ public class Configuration {
179183
@Parameter(names = "-numberOfOperations", description = "Total NUMBER Of Documents To Insert")
180184
private int numberOfOperations = 100000;
181185

186+
public Boolean isManagedIdentityRequired() {
187+
return Boolean.parseBoolean(this.isManagedIdentityRequired);
188+
}
189+
182190
static class DurationConverter implements IStringConverter<Duration> {
183191
@Override
184192
public Duration convert(String value) {
@@ -229,15 +237,6 @@ public Duration convert(String value) {
229237
@Parameter(names = "-accountNameInGraphiteReporter", description = "if set, account name with be appended in graphite reporter")
230238
private boolean accountNameInGraphiteReporter = false;
231239

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-
241240
@Parameter(names = "-pointLatencyThresholdMs", description = "Latency threshold for point operations")
242241
private int pointLatencyThresholdMs = -1;
243242

@@ -588,22 +587,10 @@ public boolean isEncryptionEnabled() {
588587
return encryptionEnabled;
589588
}
590589

591-
public boolean isClientTelemetryEnabled() {
592-
return Boolean.parseBoolean(clientTelemetryEnabled);
593-
}
594-
595590
public boolean isDefaultLog4jLoggerEnabled() {
596591
return Boolean.parseBoolean(defaultLog4jLoggerEnabled);
597592
}
598593

599-
public String getClientTelemetryEndpoint() {
600-
return clientTelemetryEndpoint;
601-
}
602-
603-
public int getClientTelemetrySchedulingInSeconds() {
604-
return clientTelemetrySchedulingInSeconds;
605-
}
606-
607594
public Integer getTupleSize() {
608595
return tupleSize;
609596
}
@@ -851,4 +838,55 @@ public String[] tagsAsPrefix() {
851838

852839
return this.graphiteMeterRegistry;
853840
}
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+
}
854892
}

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/Main.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public static void main(String[] args) throws Exception {
3838
return;
3939
}
4040

41-
if (cfg.isClientTelemetryEnabled()) {
42-
System.setProperty("COSMOS.CLIENT_TELEMETRY_ENDPOINT", cfg.getClientTelemetryEndpoint());
43-
System.setProperty("COSMOS.CLIENT_TELEMETRY_SCHEDULING_IN_SECONDS", String.valueOf(cfg.getClientTelemetrySchedulingInSeconds()));
44-
}
45-
4641
validateConfiguration(cfg);
4742

4843
if (cfg.isSync()) {

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ReadMyWriteWorkflow.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ReadMyWriteWorkflow extends AsyncBenchmark<Document> {
5959
@Override
6060
protected void init() {
6161
// TODO: move read my writes to use v4 APIs
62-
this.client = CosmosBridgeInternal.getAsyncDocumentClient(cosmosClient);
62+
this.client = CosmosBridgeInternal.getAsyncDocumentClient(benchmarkWorkloadClient);
6363
Database database = DocDBUtils.getDatabase(client, configuration.getDatabaseId());
6464
this.collection = DocDBUtils.getCollection(client, database.getSelfLink(), configuration.getCollectionId());
6565
this.nameCollectionLink = String.format("dbs/%s/colls/%s", database.getId(), collection.getId());
@@ -282,7 +282,7 @@ private Flux<Document> xPartitionQuery(SqlQuerySpec query) {
282282
options.setMaxDegreeOfParallelism(-1);
283283

284284
QueryFeedOperationState state = new QueryFeedOperationState(
285-
cosmosClient,
285+
benchmarkWorkloadClient,
286286
"xPartitionQuery",
287287
configuration.getDatabaseId(),
288288
configuration.getCollectionId(),
@@ -313,7 +313,7 @@ private Flux<Document> singlePartitionQuery(Document d) {
313313
d.getString(QUERY_FIELD_NAME)));
314314

315315
QueryFeedOperationState state = new QueryFeedOperationState(
316-
cosmosClient,
316+
benchmarkWorkloadClient,
317317
"singlePartitionQuery",
318318
configuration.getDatabaseId(),
319319
configuration.getCollectionId(),

0 commit comments

Comments
 (0)