Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions modules/core/src/main/java/org/apache/ignite/Ignite.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.lang.IgniteExperimental;
import org.apache.ignite.spi.tracing.TracingConfigurationManager;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.lang.IgniteProductVersion;
import org.apache.ignite.plugin.IgnitePlugin;
import org.apache.ignite.plugin.PluginNotFoundException;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

/**
* Main entry-point for all Ignite APIs.
Expand Down Expand Up @@ -741,4 +744,18 @@ public <T> IgniteQueue<T> queue(String name, int cap, @Nullable CollectionConfig
* @return Snapshot manager.
*/
public IgniteSnapshot snapshot();

/**
* Returns the {@link TracingConfigurationManager} instance that allows to
* <ul>
* <li>Configure tracing parameters such as sampling rate for the specific tracing coordinates
* such as scope and label.</li>
* <li>Retrieve the most specific tracing parameters for the specified tracing coordinates (scope and label)</li>
* <li>Restore the tracing parameters for the specified tracing coordinates to the default.</li>
* <li>List all pairs of tracing configuration coordinates and tracing configuration parameters.</li>
* </ul>
* @return {@link TracingConfigurationManager} instance.
*/
@IgniteExperimental
public @NotNull TracingConfigurationManager tracingConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
import org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor;
import org.apache.ignite.internal.processors.task.GridTaskProcessor;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
import org.apache.ignite.spi.tracing.TracingConfigurationManager;
import org.apache.ignite.internal.suggestions.GridPerformanceSuggestions;
import org.apache.ignite.internal.suggestions.JvmConfigurationSuggestions;
import org.apache.ignite.internal.suggestions.OsConfigurationSuggestions;
Expand Down Expand Up @@ -233,6 +234,7 @@
import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.IgniteSystemProperties.IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2;
Expand Down Expand Up @@ -4003,6 +4005,18 @@ private Collection<BaselineNode> baselineNodes() {
}
}

/** {@inheritDoc} */
@Override public @NotNull TracingConfigurationManager tracingConfiguration() {
guard();

try {
return ctx.tracing().configuration();
}
finally {
unguard();
}
}

/** {@inheritDoc} */
@Override public IgniteEncryption encryption() {
return ctx.encryption();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.ignite.internal.managers.tracing;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.ignite.IgniteCheckedException;
Expand All @@ -28,22 +27,28 @@
import org.apache.ignite.internal.processors.tracing.DeferredSpan;
import org.apache.ignite.internal.processors.tracing.NoopSpan;
import org.apache.ignite.internal.processors.tracing.NoopTracing;
import org.apache.ignite.internal.processors.tracing.Span;
import org.apache.ignite.internal.processors.tracing.SpanImpl;
import org.apache.ignite.internal.processors.tracing.configuration.GridTracingConfigurationManager;
import org.apache.ignite.spi.tracing.NoopTracingSpi;
import org.apache.ignite.spi.tracing.Scope;
import org.apache.ignite.internal.processors.tracing.Span;
import org.apache.ignite.internal.processors.tracing.SpanTags;
import org.apache.ignite.internal.processors.tracing.SpanType;
import org.apache.ignite.internal.processors.tracing.Tracing;
import org.apache.ignite.spi.tracing.SpiSpecificSpan;
import org.apache.ignite.spi.tracing.TracingConfigurationCoordinates;
import org.apache.ignite.spi.tracing.TracingConfigurationManager;
import org.apache.ignite.spi.tracing.TracingSpi;
import org.apache.ignite.spi.tracing.TracingConfigurationParameters;
import org.apache.ignite.internal.processors.tracing.messages.TraceableMessagesHandler;
import org.apache.ignite.internal.util.typedef.internal.LT;
import org.apache.ignite.logger.NullLogger;
import org.apache.ignite.spi.IgniteSpiException;
import org.apache.ignite.spi.tracing.NoopTracingSpi;
import org.apache.ignite.spi.tracing.Scope;
import org.apache.ignite.spi.tracing.TracingSpi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.processors.tracing.SpanTags.NODE;
import static org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER;
import static org.apache.ignite.internal.util.GridClientByteUtils.bytesToInt;
import static org.apache.ignite.internal.util.GridClientByteUtils.bytesToShort;
import static org.apache.ignite.internal.util.GridClientByteUtils.intToBytes;
Expand Down Expand Up @@ -86,6 +91,9 @@ public class GridTracingManager extends GridManagerAdapter<TracingSpi> implement
/** Traceable messages handler. */
private final TraceableMessagesHandler msgHnd;

/** Tracing configuration */
private final TracingConfigurationManager tracingConfiguration;

/**
* Major span serialization protocol version.
* Within same major protocol version span serialization should be backward compatible.
Expand Down Expand Up @@ -114,6 +122,8 @@ public GridTracingManager(GridKernalContext ctx, boolean useNoopTracingSpi) {
super(ctx, useNoopTracingSpi ? new NoopTracingSpi() : ctx.config().getTracingSpi());

msgHnd = new TraceableMessagesHandler(this, ctx.log(GridTracingManager.class));

tracingConfiguration = new GridTracingConfigurationManager(ctx);
}

/**
Expand Down Expand Up @@ -168,9 +178,16 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {

/** {@inheritDoc} */
@Override public Span create(@NotNull SpanType spanType, @Nullable Span parentSpan) {
// Optimization for noop spi.
if (noop)
return NoopSpan.INSTANCE;

// Optimization for zero sampling rate == 0.
if ((parentSpan == NoopSpan.INSTANCE || parentSpan == null) &&
tracingConfiguration.get(new TracingConfigurationCoordinates.Builder(spanType.scope()).build()).
samplingRate() == SAMPLING_RATE_NEVER)
return NoopSpan.INSTANCE;

return enrichWithLocalNodeParameters(
generateSpan(
parentSpan,
Expand All @@ -180,9 +197,16 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {

/** {@inheritDoc} */
@Override public Span create(@NotNull SpanType spanType, @Nullable byte[] serializedParentSpan) {
// Optimization for noop spi.
if (noop)
return NoopSpan.INSTANCE;

// Optimization for zero sampling rate == 0.
if ((serializedParentSpan.length == 0 || serializedParentSpan == null) &&
tracingConfiguration.get(new TracingConfigurationCoordinates.Builder(spanType.scope()).build()).
samplingRate() == SAMPLING_RATE_NEVER)
return NoopSpan.INSTANCE;

// 1 byte: special flags;
// 1 bytes: spi type;
// 2 bytes: major protocol version;
Expand All @@ -196,7 +220,7 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {
Span span;

try {
if (serializedParentSpan == null || serializedParentSpan == NoopTracing.NOOP_SERIALIZED_SPAN)
if (serializedParentSpan == null || serializedParentSpan.length == 0)
return create(spanType, NoopSpan.INSTANCE);

// First byte of the serializedSpan is reserved for special flags - it's not used right now.
Expand Down Expand Up @@ -311,9 +335,17 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {
@Nullable Span parentSpan,
@Nullable String lb
) {
// Optimization for noop spi.
if (noop)
return NoopSpan.INSTANCE;

// Optimization for zero sampling rate == 0.
if ((parentSpan == NoopSpan.INSTANCE || parentSpan == null) &&
tracingConfiguration.get(
new TracingConfigurationCoordinates.Builder(spanType.scope()).withLabel(lb).build()).
samplingRate() == SAMPLING_RATE_NEVER)
return NoopSpan.INSTANCE;

return enrichWithLocalNodeParameters(
generateSpan(
parentSpan,
Expand All @@ -322,10 +354,16 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public byte[] serialize(@NotNull Span span) {
// Optimization for noop spi.
if (noop)
return NoopTracing.NOOP_SERIALIZED_SPAN;

// Optimization for NoopSpan.
if (span == NoopSpan.INSTANCE)
return NoopTracing.NOOP_SERIALIZED_SPAN;

// 1 byte: special flags;
// 1 bytes: spi type;
// 2 bytes: major protocol version;
Expand All @@ -339,10 +377,6 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {
if (span instanceof DeferredSpan)
return ((DeferredSpan)span).serializedSpan();

// Optimization for NoopSpan.
if (span == NoopSpan.INSTANCE)
return NoopTracing.NOOP_SERIALIZED_SPAN;

// Spi specific serialized span.
byte[] spiSpecificSerializedSpan = getSpi().serialize(((SpanImpl)span).spiSpecificSpan());

Expand Down Expand Up @@ -422,6 +456,7 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {
* @param spanTypeToCreate Span type to create.
* @param lb Label.
*/
@SuppressWarnings("unchecked")
private @NotNull Span generateSpan(
@Nullable Span parentSpan,
@NotNull SpanType spanTypeToCreate,
Expand All @@ -430,16 +465,20 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {
if (parentSpan instanceof DeferredSpan)
return create(spanTypeToCreate, ((DeferredSpan)parentSpan).serializedSpan());

if (parentSpan == null || parentSpan == NoopSpan.INSTANCE) {
if (parentSpan == NoopSpan.INSTANCE || parentSpan == null) {
if (spanTypeToCreate.rootSpan()) {

return new SpanImpl(
getSpi().create(
spanTypeToCreate.spanName(),
null,
1),
spanTypeToCreate,
Collections.emptySet());
// Get tracing configuration.
TracingConfigurationParameters tracingConfigurationParameters = tracingConfiguration.get(
new TracingConfigurationCoordinates.Builder(spanTypeToCreate.scope()).withLabel(lb).build());

return shouldSample(tracingConfigurationParameters.samplingRate()) ?
new SpanImpl(
getSpi().create(
spanTypeToCreate.spanName(),
(SpiSpecificSpan)null),
spanTypeToCreate,
tracingConfigurationParameters.includedScopes()) :
NoopSpan.INSTANCE;
}
else
return NoopSpan.INSTANCE;
Expand All @@ -457,8 +496,7 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {
return new SpanImpl(
getSpi().create(
spanTypeToCreate.spanName(),
((SpanImpl)parentSpan).spiSpecificSpan(),
1),
((SpanImpl)parentSpan).spiSpecificSpan()),
spanTypeToCreate,
mergedIncludedScopes);
}
Expand All @@ -471,9 +509,26 @@ private Span enrichWithLocalNodeParameters(@Nullable Span span) {

/** {@inheritDoc} */
@Override public TraceableMessagesHandler messages() {
// Optimization for noop spi.
if (noop)
return NOOP_TRACEABLE_MSG_HANDLER;

return msgHnd;
}
}

/** {@inheritDoc} */
@Override public @NotNull TracingConfigurationManager configuration() {
return tracingConfiguration;
}

/**
* @param samlingRate Sampling rate.
* @return {@code true} if according to given sampling-rate span should be sampled.
*/
private boolean shouldSample(double samlingRate) {
if (samlingRate == SAMPLING_RATE_NEVER)
return false;

return Math.random() <= samlingRate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.ignite.internal.processors.tracing;

import org.apache.ignite.internal.processors.tracing.configuration.NoopTracingConfigurationManager;
import org.apache.ignite.spi.tracing.TracingConfigurationManager;
import org.apache.ignite.internal.processors.tracing.messages.TraceableMessagesHandler;
import org.apache.ignite.logger.NullLogger;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -66,4 +68,9 @@ public NoopTracing() {
@Override public byte[] serialize(@NotNull Span span) {
return NOOP_SERIALIZED_SPAN;
}

/** {@inheritDoc} */
@Override public @NotNull TracingConfigurationManager configuration() {
return NoopTracingConfigurationManager.INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.apache.ignite.internal.processors.tracing;

import org.apache.ignite.internal.processors.tracing.messages.TraceableMessagesHandler;
import org.apache.ignite.spi.tracing.TracingConfigurationManager;
import org.jetbrains.annotations.NotNull;

/**
* Tracing sub-system interface.
Expand All @@ -27,4 +29,17 @@ public interface Tracing extends SpanManager {
* @return Helper to handle traceable messages.
*/
public TraceableMessagesHandler messages();

/**
* Returns the {@link TracingConfigurationManager} instance that allows to
* <ul>
* <li>Configure tracing parameters such as sampling rate for the specific tracing coordinates
* such as scope and label.</li>
* <li>Retrieve the most specific tracing parameters for the specified tracing coordinates (scope and label)</li>
* <li>Restore the tracing parameters for the specified tracing coordinates to the default.</li>
* <li>List all pairs of tracing configuration coordinates and tracing configuration parameters.</li>
* </ul>
* @return {@link TracingConfigurationManager} instance.
*/
public @NotNull TracingConfigurationManager configuration();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.processors.tracing.configuration;

import java.util.HashMap;
import org.apache.ignite.internal.processors.configuration.distributed.SimpleDistributedProperty;
import org.apache.ignite.spi.tracing.TracingConfigurationCoordinates;
import org.apache.ignite.spi.tracing.TracingConfigurationParameters;
import org.apache.ignite.internal.processors.configuration.distributed.DistributedConfigurationProcessor;

/**
* The wrapper of {@code HashMap<TracingConfigurationCoordinates, TracingConfigurationParameters>}
* for the distributed metastorage binding.
*/
public class DistributedTracingConfiguration
extends SimpleDistributedProperty<HashMap<TracingConfigurationCoordinates, TracingConfigurationParameters>> {
/** */
private static final String TRACING_CONFIGURATION_DISTRIBUTED_METASTORE_KEY = "tr.config";

/**
* Constructor.
*/
public DistributedTracingConfiguration() {
super(TRACING_CONFIGURATION_DISTRIBUTED_METASTORE_KEY);
}

/**
* @return A new property that is detached from {@link DistributedConfigurationProcessor}.
* This means distributed updates are not accessible.
*/
public static DistributedTracingConfiguration detachedProperty() {
return new DistributedTracingConfiguration();
}
}
Loading