Search in sources :

Example 21 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class CoreViewIndexManager method publishDesignDocument.

/**
 * Convenience method that gets a the document from the development namespace
 * and upserts it to the production namespace.
 *
 * @param name name of the development design document
 * @throws DesignDocumentNotFoundException if the development namespace does not contain a document with the given name
 */
public CompletableFuture<Void> publishDesignDocument(String name, CoreCommonOptions options) {
    notNullOrEmpty(name, "Name", () -> new ReducedViewErrorContext(null, null, bucket));
    RequestSpan span = buildSpan(TracingIdentifiers.SPAN_REQUEST_MV_PUBLISH_DD, options.parentSpan());
    CoreCommonOptions childOptions = options.withParentSpan(span);
    return getDesignDocument(name, false, childOptions).thenCompose(doc -> upsertDesignDocument(name, doc, true, childOptions)).whenComplete((r, t) -> span.end());
}
Also used : DesignDocumentNotFoundException(com.couchbase.client.core.error.DesignDocumentNotFoundException) HttpStatusCodeException(com.couchbase.client.core.error.HttpStatusCodeException) Validators.notNull(com.couchbase.client.core.util.Validators.notNull) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) RequestTarget(com.couchbase.client.core.msg.RequestTarget) CompletableFuture(java.util.concurrent.CompletableFuture) CoreHttpPath(com.couchbase.client.core.endpoint.http.CoreHttpPath) CoreCommonOptions(com.couchbase.client.core.endpoint.http.CoreCommonOptions) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode) LinkedHashMap(java.util.LinkedHashMap) CbCollections.mapOf(com.couchbase.client.core.util.CbCollections.mapOf) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) Map(java.util.Map) CoreHttpPath.path(com.couchbase.client.core.endpoint.http.CoreHttpPath.path) Objects.requireNonNull(java.util.Objects.requireNonNull) Stability(com.couchbase.client.core.annotation.Stability) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) ObjectNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode) CbStrings.removeStart(com.couchbase.client.core.util.CbStrings.removeStart) CbTracing(com.couchbase.client.core.cnc.CbTracing) ReducedViewErrorContext(com.couchbase.client.core.error.context.ReducedViewErrorContext) Mapper(com.couchbase.client.core.json.Mapper) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) UrlQueryStringBuilder.urlEncode(com.couchbase.client.core.util.UrlQueryStringBuilder.urlEncode) InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) Validators.notNullOrEmpty(com.couchbase.client.core.util.Validators.notNullOrEmpty) ResponseStatus(com.couchbase.client.core.msg.ResponseStatus) RedactableArgument.redactMeta(com.couchbase.client.core.logging.RedactableArgument.redactMeta) CoreHttpResponse(com.couchbase.client.core.endpoint.http.CoreHttpResponse) Optional(java.util.Optional) Core(com.couchbase.client.core.Core) CoreCommonOptions(com.couchbase.client.core.endpoint.http.CoreCommonOptions) ReducedViewErrorContext(com.couchbase.client.core.error.context.ReducedViewErrorContext) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 22 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class CoreBucketManager method updateBucket.

public CompletableFuture<Void> updateBucket(Map<String, String> settings, final CoreCommonOptions options) {
    String bucketName = getBucketName(settings);
    RequestSpan span = CbTracing.newSpan(core.context(), TracingIdentifiers.SPAN_REQUEST_MB_UPDATE_BUCKET, options.parentSpan().orElse(null));
    span.attribute(TracingIdentifiers.ATTR_NAME, bucketName);
    CoreCommonOptions getAllBucketOptions = options.withParentSpan(span);
    return Mono.fromFuture(() -> getAllBuckets(getAllBucketOptions)).map(buckets -> buckets.containsKey(bucketName)).flatMap(bucketExists -> {
        if (!bucketExists) {
            return Mono.error(BucketNotFoundException.forBucket(bucketName));
        }
        return Mono.fromFuture(httpClient.post(pathForBucket(bucketName), options).form(convertSettingsToParams(settings, true)).exec(core).thenApply(response -> null));
    }).then().doOnTerminate(span::end).toFuture();
}
Also used : HttpStatusCodeException.couchbaseResponseStatus(com.couchbase.client.core.error.HttpStatusCodeException.couchbaseResponseStatus) RequestTarget(com.couchbase.client.core.msg.RequestTarget) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CoreHttpPath(com.couchbase.client.core.endpoint.http.CoreHttpPath) Function(java.util.function.Function) CoreCommonOptions(com.couchbase.client.core.endpoint.http.CoreCommonOptions) HttpStatusCodeException.httpResponseBody(com.couchbase.client.core.error.HttpStatusCodeException.httpResponseBody) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode) BucketNotFlushableException(com.couchbase.client.core.error.BucketNotFlushableException) CbCollections.mapOf(com.couchbase.client.core.util.CbCollections.mapOf) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) Map(java.util.Map) CoreHttpPath.path(com.couchbase.client.core.endpoint.http.CoreHttpPath.path) Objects.requireNonNull(java.util.Objects.requireNonNull) Stability(com.couchbase.client.core.annotation.Stability) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) CbTracing(com.couchbase.client.core.cnc.CbTracing) BucketNotFoundException(com.couchbase.client.core.error.BucketNotFoundException) CbThrowables.propagate(com.couchbase.client.core.util.CbThrowables.propagate) UrlQueryStringBuilder(com.couchbase.client.core.util.UrlQueryStringBuilder) Mapper(com.couchbase.client.core.json.Mapper) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) Mono(reactor.core.publisher.Mono) ResponseStatus(com.couchbase.client.core.msg.ResponseStatus) RedactableArgument.redactMeta(com.couchbase.client.core.logging.RedactableArgument.redactMeta) CoreHttpResponse(com.couchbase.client.core.endpoint.http.CoreHttpResponse) BucketExistsException(com.couchbase.client.core.error.BucketExistsException) Core(com.couchbase.client.core.Core) CoreCommonOptions(com.couchbase.client.core.endpoint.http.CoreCommonOptions) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 23 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class QueryRequest method toExecuteRequest.

/**
 * Returns a copy of this request tailored to execute a prepared statement.
 *
 * @param preparedStatementName name of the prepared statement
 * @param encodedPlan (nullable) query plan, or null if enhanced prepared statements are enabled.
 */
@Stability.Internal
public QueryRequest toExecuteRequest(String preparedStatementName, String encodedPlan, RequestTracer requestTracer) {
    byte[] newQuery = transformQuery(query -> {
        query.remove("statement");
        query.put("prepared", preparedStatementName);
        if (encodedPlan != null) {
            query.put("encoded_plan", encodedPlan);
        }
    });
    RequestSpan newSpan = requestTracer.requestSpan("execute", requestSpan());
    return copy(statement(), newQuery, idempotent(), newSpan);
}
Also used : RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 24 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class AsyncCollection method lookupInRequest.

/**
 * Helper method to create the underlying lookup subdoc request.
 *
 * @param id the outer document ID.
 * @param specs the spec which specifies the type of lookups to perform.
 * @param opts custom options to modify the lookup options.
 * @return the subdoc lookup request.
 */
SubdocGetRequest lookupInRequest(final String id, final List<LookupInSpec> specs, final LookupInOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNullOrEmpty(specs, "LookupInSpecs", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    ArrayList<SubdocGetRequest.Command> commands = new ArrayList<>(specs.size());
    for (int i = 0; i < specs.size(); i++) {
        LookupInSpec spec = specs.get(i);
        commands.add(spec.export(i));
    }
    // xattrs come first
    commands.sort(Comparator.comparing(v -> !v.xattr()));
    Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    byte flags = 0;
    if (opts.accessDeleted()) {
        flags |= SubdocMutateRequest.SUBDOC_DOC_FLAG_ACCESS_DELETED;
    }
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_LOOKUP_IN, opts.parentSpan().orElse(null));
    SubdocGetRequest request = new SubdocGetRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, flags, commands, span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : MutateInAccessor(com.couchbase.client.java.kv.MutateInAccessor) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) InsertOptions(com.couchbase.client.java.kv.InsertOptions) MutationResult(com.couchbase.client.java.kv.MutationResult) DEFAULT_REPLACE_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_REPLACE_OPTIONS) Validators.notNull(com.couchbase.client.core.util.Validators.notNull) PersistTo(com.couchbase.client.java.kv.PersistTo) ReplaceAccessor(com.couchbase.client.java.kv.ReplaceAccessor) TouchAccessor(com.couchbase.client.java.kv.TouchAccessor) DEFAULT_GET_AND_LOCK_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_GET_AND_LOCK_OPTIONS) CoreContext(com.couchbase.client.core.CoreContext) Duration(java.time.Duration) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) GetAndTouchOptions(com.couchbase.client.java.kv.GetAndTouchOptions) LookupInMacro(com.couchbase.client.java.kv.LookupInMacro) BucketConfig(com.couchbase.client.core.config.BucketConfig) GetAllReplicasOptions(com.couchbase.client.java.kv.GetAllReplicasOptions) TouchRequest(com.couchbase.client.core.msg.kv.TouchRequest) RemoveOptions(com.couchbase.client.java.kv.RemoveOptions) ExistsOptions(com.couchbase.client.java.kv.ExistsOptions) InsertAccessor(com.couchbase.client.java.kv.InsertAccessor) DEFAULT_INSERT_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_INSERT_OPTIONS) GetAndTouchRequest(com.couchbase.client.core.msg.kv.GetAndTouchRequest) GetReplicaResult(com.couchbase.client.java.kv.GetReplicaResult) ExistsResult(com.couchbase.client.java.kv.ExistsResult) UnlockAccessor(com.couchbase.client.java.kv.UnlockAccessor) InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) Validators.notNullOrEmpty(com.couchbase.client.core.util.Validators.notNullOrEmpty) ReplicaHelper(com.couchbase.client.core.service.kv.ReplicaHelper) Expiry(com.couchbase.client.java.kv.Expiry) List(java.util.List) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest) GetAndLockRequest(com.couchbase.client.core.msg.kv.GetAndLockRequest) LookupInOptions(com.couchbase.client.java.kv.LookupInOptions) SubdocMutateRequest(com.couchbase.client.core.msg.kv.SubdocMutateRequest) GetAccessor(com.couchbase.client.java.kv.GetAccessor) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) Optional(java.util.Optional) ReplaceRequest(com.couchbase.client.core.msg.kv.ReplaceRequest) DEFAULT_GET_ALL_REPLICAS_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_GET_ALL_REPLICAS_OPTIONS) DEFAULT_MUTATE_IN_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_MUTATE_IN_OPTIONS) GetOptions(com.couchbase.client.java.kv.GetOptions) UpsertAccessor(com.couchbase.client.java.kv.UpsertAccessor) RemoveAccessor(com.couchbase.client.java.kv.RemoveAccessor) GetResult(com.couchbase.client.java.kv.GetResult) ExistsAccessor(com.couchbase.client.java.kv.ExistsAccessor) TouchOptions(com.couchbase.client.java.kv.TouchOptions) UnlockOptions(com.couchbase.client.java.kv.UnlockOptions) DEFAULT_GET_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_GET_OPTIONS) RemoveRequest(com.couchbase.client.core.msg.kv.RemoveRequest) StoreSemantics(com.couchbase.client.java.kv.StoreSemantics) CompletableFuture(java.util.concurrent.CompletableFuture) CommonDurabilityOptions(com.couchbase.client.java.kv.CommonDurabilityOptions) GetMetaRequest(com.couchbase.client.core.msg.kv.GetMetaRequest) ArrayList(java.util.ArrayList) DEFAULT_TOUCH_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_TOUCH_OPTIONS) GetAnyReplicaOptions(com.couchbase.client.java.kv.GetAnyReplicaOptions) ReplaceOptions(com.couchbase.client.java.kv.ReplaceOptions) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) GetAndLockOptions(com.couchbase.client.java.kv.GetAndLockOptions) DEFAULT_REMOVE_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_REMOVE_OPTIONS) MutateInSpec(com.couchbase.client.java.kv.MutateInSpec) Stability(com.couchbase.client.core.annotation.Stability) DEFAULT_EXISTS_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_EXISTS_OPTIONS) DEFAULT_GET_ANY_REPLICA_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_GET_ANY_REPLICA_OPTIONS) UpsertOptions(com.couchbase.client.java.kv.UpsertOptions) LookupInResult(com.couchbase.client.java.kv.LookupInResult) MutateInOptions(com.couchbase.client.java.kv.MutateInOptions) MutateInResult(com.couchbase.client.java.kv.MutateInResult) DEFAULT_UPSERT_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_UPSERT_OPTIONS) UnlockRequest(com.couchbase.client.core.msg.kv.UnlockRequest) LookupInAccessor(com.couchbase.client.java.kv.LookupInAccessor) DEFAULT_GET_AND_TOUCH_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_GET_AND_TOUCH_OPTIONS) UpsertRequest(com.couchbase.client.core.msg.kv.UpsertRequest) LookupInSpec(com.couchbase.client.java.kv.LookupInSpec) DEFAULT_LOOKUP_IN_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_LOOKUP_IN_OPTIONS) Transcoder(com.couchbase.client.java.codec.Transcoder) DurabilityLevel(com.couchbase.client.core.msg.kv.DurabilityLevel) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) Core(com.couchbase.client.core.Core) ReducedKeyValueErrorContext(com.couchbase.client.core.error.context.ReducedKeyValueErrorContext) Comparator(java.util.Comparator) DEFAULT_UNLOCK_OPTIONS(com.couchbase.client.java.ReactiveCollection.DEFAULT_UNLOCK_OPTIONS) TimeoutConfig(com.couchbase.client.core.env.TimeoutConfig) SubdocCommandType(com.couchbase.client.core.msg.kv.SubdocCommandType) BucketConfigUtil(com.couchbase.client.core.util.BucketConfigUtil) ArrayList(java.util.ArrayList) LookupInSpec(com.couchbase.client.java.kv.LookupInSpec) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest)

Example 25 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class AsyncCollection method replaceRequest.

/**
 * Helper method to generate the replace request.
 *
 * @param id the document id to replace.
 * @param content the document content to replace.
 * @param opts custom options to customize the replace behavior.
 * @return the replace request.
 */
ReplaceRequest replaceRequest(final String id, final Object content, final ReplaceOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(content, "Content", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
    final RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_REPLACE, opts.parentSpan().orElse(null));
    final RequestSpan encodeSpan = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ENCODING, span);
    long start = System.nanoTime();
    Transcoder.EncodedValue encoded;
    try {
        encoded = transcoder.encode(content);
    } finally {
        encodeSpan.end();
    }
    long end = System.nanoTime();
    long expiry = opts.expiry().encode();
    ReplaceRequest request = new ReplaceRequest(id, encoded.encoded(), expiry, opts.preserveExpiry(), encoded.flags(), timeout, opts.cas(), coreContext, collectionIdentifier, retryStrategy, opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext()).encodeLatency(end - start);
    return request;
}
Also used : ReplaceRequest(com.couchbase.client.core.msg.kv.ReplaceRequest) Duration(java.time.Duration) Transcoder(com.couchbase.client.java.codec.Transcoder) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

RequestSpan (com.couchbase.client.core.cnc.RequestSpan)42 Duration (java.time.Duration)30 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)28 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 Stability (com.couchbase.client.core.annotation.Stability)10 Validators.notNullOrEmpty (com.couchbase.client.core.util.Validators.notNullOrEmpty)10 List (java.util.List)10 Core (com.couchbase.client.core.Core)9 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 BucketConfig (com.couchbase.client.core.config.BucketConfig)8 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)8 Objects.requireNonNull (java.util.Objects.requireNonNull)8 Mono (reactor.core.publisher.Mono)8 Reactor (com.couchbase.client.core.Reactor)7 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)7 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)7 Function (java.util.function.Function)7 CoreContext (com.couchbase.client.core.CoreContext)6