Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging back Tracer PR without conditional check on withContext() #12867

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
089307a
initial commit
simplynaveen20 Apr 8, 2020
175222e
changing sample
simplynaveen20 Apr 8, 2020
fe03e66
adding query api tracer support
simplynaveen20 Apr 13, 2020
9f9cce8
merging with master
simplynaveen20 Apr 14, 2020
e2e8e9e
reverting change for jaeger ui local testing
simplynaveen20 Apr 14, 2020
c2fc40f
adding tracers in trigger udf and sproc
simplynaveen20 Apr 15, 2020
eb82b61
Merge branch 'latest-master' into users/nakumars/tracercosmosdb
simplynaveen20 Apr 21, 2020
e614db5
adding test case and refactoring code
simplynaveen20 Apr 21, 2020
c4ae21b
Merge branch 'latest-master' into users/nakumars/tracercosmosdb
simplynaveen20 Apr 24, 2020
eabbec9
refactoring code with PR ready version
simplynaveen20 Apr 24, 2020
36dde95
ending span on doOnComplete
simplynaveen20 Apr 24, 2020
36743ca
resolving error
simplynaveen20 May 4, 2020
cff33ad
merging with master
simplynaveen20 May 4, 2020
8ca24ec
perf improvement
simplynaveen20 May 5, 2020
21034b5
resolving merge conflict
simplynaveen20 May 6, 2020
1f9f139
fixing build error
simplynaveen20 May 6, 2020
aab85a6
resolving merge conflict
simplynaveen20 May 11, 2020
d14a0bb
resolving merge conflict
simplynaveen20 May 11, 2020
8fbad2c
check non opentelementry jar non existence in starting of all api
simplynaveen20 May 11, 2020
6b09e5c
fixing checkstyle
simplynaveen20 May 11, 2020
81040b2
resolving comments
simplynaveen20 May 11, 2020
dbc74c8
Merge branch 'latest-master' into users/nakumars/tracercosmosdb
simplynaveen20 May 11, 2020
806cdf1
check style fix as per java 8
simplynaveen20 May 11, 2020
d061db5
adding azure-core-tracing-opentelemetry in test scope
simplynaveen20 May 11, 2020
32d9172
resolving conflict
simplynaveen20 May 11, 2020
0fc0cc9
build error fix
simplynaveen20 May 11, 2020
1290ae1
test failure fix
simplynaveen20 May 12, 2020
d2a8154
test fix
simplynaveen20 May 12, 2020
30c2f89
resolving comments
simplynaveen20 May 13, 2020
e7fa831
complie error fix
simplynaveen20 May 13, 2020
3aa851d
removing query text from tracer
simplynaveen20 May 15, 2020
0debac0
resolving merge conflict
simplynaveen20 May 15, 2020
8efa451
merge with master and removing subscriber context for perf gain
simplynaveen20 May 26, 2020
e7fe8bb
resolving merge conflict
simplynaveen20 May 26, 2020
3461604
resolving merge conflict after GA
simplynaveen20 Jun 11, 2020
0984a9c
code formating change and some comment resolution
simplynaveen20 Jun 11, 2020
b9c60a2
resolving comments
simplynaveen20 Jun 11, 2020
aaabc72
moving AZ_TRACING_NAMESPACE_KEY to context from span attribute
simplynaveen20 Jun 15, 2020
8024999
updating core opentelementry jar
simplynaveen20 Jun 15, 2020
2101851
Merge branch 'latest-master' into users/nakumars/tracercosmosdb
simplynaveen20 Jul 6, 2020
1f4c6ac
Tracer code without conditional check for withContext
simplynaveen20 Jul 7, 2020
1b0becb
Merge branch 'latest-master' into users/nakumars/tracercosmosdb
simplynaveen20 Jul 7, 2020
3548215
formating chage
simplynaveen20 Jul 7, 2020
eb398d9
formating chage
simplynaveen20 Jul 7, 2020
b168fd2
Merge branch 'latest-master' into users/nakumars/tracercosmosdb
simplynaveen20 Jul 9, 2020
9c1d31f
resolving comments
simplynaveen20 Jul 9, 2020
0703a28
build error fix
simplynaveen20 Jul 9, 2020
c5283fe
Merge branch 'latest-master' into users/nakumars/tracercosmosdb
simplynaveen20 Jul 9, 2020
deb6978
resolving comment
simplynaveen20 Jul 10, 2020
8af1cc9
resolving comments
simplynaveen20 Jul 10, 2020
798839c
resolving comment
simplynaveen20 Jul 10, 2020
21c5743
resolving comment
simplynaveen20 Jul 10, 2020
42e9789
removing extra method
simplynaveen20 Jul 10, 2020
be8d7eb
removing tets dependency
simplynaveen20 Jul 10, 2020
1f9725c
adding span attribute unit test
simplynaveen20 Jul 13, 2020
fc1296f
resolving comments
simplynaveen20 Jul 13, 2020
0a7aab0
resolving comments
simplynaveen20 Jul 14, 2020
8292a83
resolving merge conflic and comments
simplynaveen20 Jul 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
resolving merge conflict
  • Loading branch information
simplynaveen20 committed May 11, 2020
commit d14a0bb5ee30f455dd35b545f564ec6b0ee5beb7
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.azure.cosmos.models.FeedOptions;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.cosmos.models.ThroughputProperties;
import com.azure.cosmos.util.CosmosPagedFlux;
import com.azure.cosmos.util.UtilBridgeInternal;
import io.micrometer.core.instrument.MeterRegistry;
Expand Down Expand Up @@ -53,6 +54,7 @@ public final class CosmosAsyncClient implements Closeable {
private final boolean sessionCapturingOverride;
private final boolean enableTransportClientSharing;
private final TracerProvider tracerProvider;
private final boolean contentResponseOnWriteEnabled;

CosmosAsyncClient(CosmosClientBuilder builder) {
this.configs = builder.configs();
Expand All @@ -66,6 +68,7 @@ public final class CosmosAsyncClient implements Closeable {
this.sessionCapturingOverride = builder.isSessionCapturingOverrideEnabled();
this.enableTransportClientSharing = builder.isConnectionReuseAcrossClientsEnabled();
this.tracerProvider = builder.getTracerProvider();
this.contentResponseOnWriteEnabled = builder.isContentResponseOnWriteEnabled();
this.asyncDocumentClient = new AsyncDocumentClient.Builder()
.withServiceEndpoint(this.serviceEndpoint)
.withMasterKeyOrResourceToken(this.keyOrResourceToken)
Expand All @@ -76,6 +79,7 @@ public final class CosmosAsyncClient implements Closeable {
.withTokenResolver(this.cosmosAuthorizationTokenResolver)
.withCosmosKeyCredential(this.cosmosKeyCredential)
.withTransportClientSharing(this.enableTransportClientSharing)
.withContentResponseOnWriteEnabled(this.contentResponseOnWriteEnabled)
.build();
}

Expand Down Expand Up @@ -168,6 +172,22 @@ CosmosKeyCredential cosmosKeyCredential() {
return cosmosKeyCredential;
}

/**
* Gets the boolean which indicates whether to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If set to false (which is by default), this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it
* on the client.
*
* By-default, this is false.
*
* @return a boolean indicating whether resource will be included in the response or not
*/
boolean isContentResponseOnWriteEnabled() {
return contentResponseOnWriteEnabled;
}

/**
* CREATE a Database if it does not already exist on the service
* <p>
Expand Down Expand Up @@ -312,6 +332,19 @@ public Mono<CosmosAsyncDatabaseResponse> createDatabase(String id, int throughpu
return createDatabase(new CosmosDatabaseProperties(id), options);
}

/**
* Creates a database.
*
* @param id the id
* @param throughputProperties the throughputProperties
* @return the mono
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabase(String id, ThroughputProperties throughputProperties) {
CosmosDatabaseRequestOptions options = new CosmosDatabaseRequestOptions();
ModelBridgeInternal.setOfferProperties(options, throughputProperties);
return createDatabase(new CosmosDatabaseProperties(id), options);
}

/**
* Reads all databases.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@
import com.azure.cosmos.models.CosmosAsyncUserResponse;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosContainerRequestOptions;
import com.azure.cosmos.models.CosmosDatabaseProperties;
import com.azure.cosmos.models.CosmosDatabaseRequestOptions;
import com.azure.cosmos.models.CosmosUserProperties;
import com.azure.cosmos.models.FeedOptions;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.cosmos.models.ThroughputProperties;
import com.azure.cosmos.models.ThroughputResponse;
import com.azure.cosmos.util.CosmosPagedFlux;
import com.azure.cosmos.util.UtilBridgeInternal;
import reactor.core.Exceptions;
import reactor.core.publisher.Mono;

import static com.azure.core.util.FluxUtil.withContext;
import java.util.Collections;
import java.util.List;

import static com.azure.cosmos.implementation.Utils.setContinuationTokenAndMaxItemCount;

/**
Expand Down Expand Up @@ -159,6 +166,22 @@ public Mono<CosmosAsyncContainerResponse> createContainer(
return createContainer(containerProperties, options);
}

/**
* Creates a container.
*
* @param containerProperties the container properties
* @param throughputProperties the throughput properties
* @param options the request options
* @return the mono
*/
public Mono<CosmosAsyncContainerResponse> createContainer(
CosmosContainerProperties containerProperties,
ThroughputProperties throughputProperties,
CosmosContainerRequestOptions options){
ModelBridgeInternal.setOfferProperties(options, throughputProperties);
return createContainer(containerProperties, options);
}

/**
* Creates a document container.
* <p>
Expand Down Expand Up @@ -615,6 +638,79 @@ public Mono<Integer> replaceProvisionedThroughput(int requestUnitsPerSecond) {
return TracerProvider.cosmosWithContext(withContext(context -> replaceProvisionedThroughput(requestUnitsPerSecond, context)), client.getTracerProvider());
}

/**
* Sets throughput provisioned for a container in measurement of
* Requests-per-Unit in the Azure Cosmos service.
*
* @param throughputProperties the throughput properties
* @return the mono
*/
public Mono<ThroughputResponse> replaceThroughput(ThroughputProperties throughputProperties) {
return this.read()
.flatMap(response -> this.getDocClientWrapper()
.queryOffers(getOfferQuerySpecFromResourceId(response.getProperties()
.getResourceId()),
new FeedOptions())
.single()
.flatMap(offerFeedResponse -> {
if (offerFeedResponse.getResults().isEmpty()) {
return Mono.error(BridgeInternal
.createCosmosClientException(
HttpConstants.StatusCodes.BADREQUEST,
"No offers found for the " +
"resource " + this.getId()));
}

Offer existingOffer = offerFeedResponse.getResults().get(0);
Offer updatedOffer =
ModelBridgeInternal.updateOfferFromProperties(existingOffer,
throughputProperties);

return this.getDocClientWrapper()
.replaceOffer(updatedOffer)
.single();
})
.map(ModelBridgeInternal::createThroughputRespose));
}

/**
* Gets the throughput of the database
*
* @return the mono containing throughput response
*/
public Mono<ThroughputResponse> readThroughput() {
return this.read()
.flatMap(response -> getDocClientWrapper()
.queryOffers(getOfferQuerySpecFromResourceId(response.getProperties()
.getResourceId()),
new FeedOptions())
.single()
.flatMap(offerFeedResponse -> {
if (offerFeedResponse.getResults().isEmpty()) {
return Mono.error(BridgeInternal
.createCosmosClientException(
HttpConstants.StatusCodes.BADREQUEST,
"No offers found for the " +
"resource " + this.getId()));
}
return getDocClientWrapper()
.readOffer(offerFeedResponse.getResults()
.get(0)
.getSelfLink())
.single();
})
.map(ModelBridgeInternal::createThroughputRespose));
}

SqlQuerySpec getOfferQuerySpecFromResourceId(String resourceId) {
String queryText = "select * from c where c.offerResourceId = @resourceId";
SqlQuerySpec querySpec = new SqlQuerySpec(queryText);
List<SqlParameter> parameters = Collections
.singletonList(new SqlParameter("@resourceId", resourceId));
querySpec.setParameters(parameters);
return querySpec;
}

CosmosAsyncClient getClient() {
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public class CosmosClientBuilder {
private CosmosKeyCredential cosmosKeyCredential;
private boolean sessionCapturingOverrideEnabled;
private boolean connectionReuseAcrossClientsEnabled;

private TracerProvider tracerProvider;
private boolean contentResponseOnWriteEnabled;

/**
* Instantiates a new Cosmos client builder.
Expand All @@ -51,6 +53,14 @@ public CosmosClientBuilder() {
this.tracerProvider = new TracerProvider(ServiceLoader.load(Tracer.class));
}

/**
* Get the tracer provider
* @return tracerProvider
*/
public TracerProvider getTracerProvider() {
return tracerProvider;
}

/**
* Session capturing is enabled by default for {@link ConsistencyLevel#SESSION}.
* For other consistency levels, it is not needed, unless if you need occasionally send requests with Session
Expand Down Expand Up @@ -297,12 +307,38 @@ public CosmosClientBuilder keyCredential(CosmosKeyCredential cosmosKeyCredential
}

/**
* Gets the tracer provider
* Gets the boolean which indicates whether to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* @return tracerProvider
* If set to false (which is by default), this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it
* on the client.
*
* By-default, this is false.
*
* @return a boolean indicating whether resource will be included in the response or not
*/
public TracerProvider getTracerProvider() {
return this.tracerProvider;
boolean isContentResponseOnWriteEnabled() {
return contentResponseOnWriteEnabled;
}

/**
* Sets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If set to false (which is by default), this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it on the client.
*
* This feature does not impact RU usage for read or write operations.
*
* By-default, this is false.
*
* @param contentResponseOnWriteEnabled a boolean indicating whether resource will be included in the response or not
* @return current cosmosClientBuilder
*/
public CosmosClientBuilder contentResponseOnWriteEnabled(boolean contentResponseOnWriteEnabled) {
this.contentResponseOnWriteEnabled = contentResponseOnWriteEnabled;
return this;
}

/**
Expand Down