Search in sources :

Example 1 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler in project java by wavefrontHQ.

the class PushAgent method startListeners.

@Override
protected void startListeners() throws Exception {
    blockedPointsLogger = Logger.getLogger(proxyConfig.getBlockedPointsLoggerName());
    blockedHistogramsLogger = Logger.getLogger(proxyConfig.getBlockedHistogramsLoggerName());
    blockedSpansLogger = Logger.getLogger(proxyConfig.getBlockedSpansLoggerName());
    if (proxyConfig.getSoLingerTime() >= 0) {
        childChannelOptions.put(ChannelOption.SO_LINGER, proxyConfig.getSoLingerTime());
    }
    hostnameResolver = new CachingHostnameLookupResolver(proxyConfig.isDisableRdnsLookup(), ExpectedAgentMetric.RDNS_CACHE_SIZE.metricName);
    if (proxyConfig.isSqsQueueBuffer()) {
        taskQueueFactory = new SQSQueueFactoryImpl(proxyConfig.getSqsQueueNameTemplate(), proxyConfig.getSqsQueueRegion(), proxyConfig.getSqsQueueIdentifier(), proxyConfig.isPurgeBuffer());
    } else {
        taskQueueFactory = new TaskQueueFactoryImpl(proxyConfig.getBufferFile(), proxyConfig.isPurgeBuffer(), proxyConfig.isDisableBufferSharding(), proxyConfig.getBufferShardSize());
    }
    remoteHostAnnotator = new SharedGraphiteHostAnnotator(proxyConfig.getCustomSourceTags(), hostnameResolver);
    queueingFactory = new QueueingFactoryImpl(apiContainer, agentId, taskQueueFactory, entityProps);
    senderTaskFactory = new SenderTaskFactoryImpl(apiContainer, agentId, taskQueueFactory, queueingFactory, entityProps);
    if (proxyConfig.isHistogramPassthroughRecompression()) {
        histogramRecompressor = new HistogramRecompressor(() -> entityProps.getGlobalProperties().getHistogramStorageAccuracy());
    }
    handlerFactory = new ReportableEntityHandlerFactoryImpl(senderTaskFactory, proxyConfig.getPushBlockedSamples(), validationConfiguration, blockedPointsLogger, blockedHistogramsLogger, blockedSpansLogger, histogramRecompressor, entityProps);
    if (proxyConfig.isTrafficShaping()) {
        new TrafficShapingRateLimitAdjuster(entityProps, proxyConfig.getTrafficShapingWindowSeconds(), proxyConfig.getTrafficShapingHeadroom()).start();
    }
    healthCheckManager = new HealthCheckManagerImpl(proxyConfig);
    tokenAuthenticator = configureTokenAuthenticator();
    shutdownTasks.add(() -> senderTaskFactory.shutdown());
    shutdownTasks.add(() -> senderTaskFactory.drainBuffersToQueue(null));
    // sampler for spans
    rateSampler.setSamplingRate(entityProps.getGlobalProperties().getTraceSamplingRate());
    Sampler durationSampler = SpanSamplerUtils.getDurationSampler(proxyConfig.getTraceSamplingDuration());
    List<Sampler> samplers = SpanSamplerUtils.fromSamplers(rateSampler, durationSampler);
    SpanSampler spanSampler = new SpanSampler(new CompositeSampler(samplers), () -> entityProps.getGlobalProperties().getActiveSpanSamplingPolicies());
    if (proxyConfig.getAdminApiListenerPort() > 0) {
        startAdminListener(proxyConfig.getAdminApiListenerPort());
    }
    csvToList(proxyConfig.getHttpHealthCheckPorts()).forEach(strPort -> startHealthCheckListener(Integer.parseInt(strPort)));
    csvToList(proxyConfig.getPushListenerPorts()).forEach(strPort -> {
        startGraphiteListener(strPort, handlerFactory, remoteHostAnnotator, spanSampler);
        logger.info("listening on port: " + strPort + " for Wavefront metrics");
    });
    csvToList(proxyConfig.getDeltaCountersAggregationListenerPorts()).forEach(strPort -> {
        startDeltaCounterListener(strPort, remoteHostAnnotator, senderTaskFactory, spanSampler);
        logger.info("listening on port: " + strPort + " for Wavefront delta counter metrics");
    });
    {
        // Histogram bootstrap.
        List<String> histMinPorts = csvToList(proxyConfig.getHistogramMinuteListenerPorts());
        List<String> histHourPorts = csvToList(proxyConfig.getHistogramHourListenerPorts());
        List<String> histDayPorts = csvToList(proxyConfig.getHistogramDayListenerPorts());
        List<String> histDistPorts = csvToList(proxyConfig.getHistogramDistListenerPorts());
        int activeHistogramAggregationTypes = (histDayPorts.size() > 0 ? 1 : 0) + (histHourPorts.size() > 0 ? 1 : 0) + (histMinPorts.size() > 0 ? 1 : 0) + (histDistPorts.size() > 0 ? 1 : 0);
        if (activeHistogramAggregationTypes > 0) {
            /*Histograms enabled*/
            histogramExecutor = Executors.newScheduledThreadPool(1 + activeHistogramAggregationTypes, new NamedThreadFactory("histogram-service"));
            histogramFlushExecutor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() / 2, new NamedThreadFactory("histogram-flush"));
            managedExecutors.add(histogramExecutor);
            managedExecutors.add(histogramFlushExecutor);
            File baseDirectory = new File(proxyConfig.getHistogramStateDirectory());
            // Central dispatch
            ReportableEntityHandler<ReportPoint, String> pointHandler = handlerFactory.getHandler(HandlerKey.of(ReportableEntityType.HISTOGRAM, "histogram_ports"));
            startHistogramListeners(histMinPorts, pointHandler, remoteHostAnnotator, Granularity.MINUTE, proxyConfig.getHistogramMinuteFlushSecs(), proxyConfig.isHistogramMinuteMemoryCache(), baseDirectory, proxyConfig.getHistogramMinuteAccumulatorSize(), proxyConfig.getHistogramMinuteAvgKeyBytes(), proxyConfig.getHistogramMinuteAvgDigestBytes(), proxyConfig.getHistogramMinuteCompression(), proxyConfig.isHistogramMinuteAccumulatorPersisted(), spanSampler);
            startHistogramListeners(histHourPorts, pointHandler, remoteHostAnnotator, Granularity.HOUR, proxyConfig.getHistogramHourFlushSecs(), proxyConfig.isHistogramHourMemoryCache(), baseDirectory, proxyConfig.getHistogramHourAccumulatorSize(), proxyConfig.getHistogramHourAvgKeyBytes(), proxyConfig.getHistogramHourAvgDigestBytes(), proxyConfig.getHistogramHourCompression(), proxyConfig.isHistogramHourAccumulatorPersisted(), spanSampler);
            startHistogramListeners(histDayPorts, pointHandler, remoteHostAnnotator, Granularity.DAY, proxyConfig.getHistogramDayFlushSecs(), proxyConfig.isHistogramDayMemoryCache(), baseDirectory, proxyConfig.getHistogramDayAccumulatorSize(), proxyConfig.getHistogramDayAvgKeyBytes(), proxyConfig.getHistogramDayAvgDigestBytes(), proxyConfig.getHistogramDayCompression(), proxyConfig.isHistogramDayAccumulatorPersisted(), spanSampler);
            startHistogramListeners(histDistPorts, pointHandler, remoteHostAnnotator, null, proxyConfig.getHistogramDistFlushSecs(), proxyConfig.isHistogramDistMemoryCache(), baseDirectory, proxyConfig.getHistogramDistAccumulatorSize(), proxyConfig.getHistogramDistAvgKeyBytes(), proxyConfig.getHistogramDistAvgDigestBytes(), proxyConfig.getHistogramDistCompression(), proxyConfig.isHistogramDistAccumulatorPersisted(), spanSampler);
        }
    }
    if (StringUtils.isNotBlank(proxyConfig.getGraphitePorts()) || StringUtils.isNotBlank(proxyConfig.getPicklePorts())) {
        if (tokenAuthenticator.authRequired()) {
            logger.warning("Graphite mode is not compatible with HTTP authentication, ignoring");
        } else {
            Preconditions.checkNotNull(proxyConfig.getGraphiteFormat(), "graphiteFormat must be supplied to enable graphite support");
            Preconditions.checkNotNull(proxyConfig.getGraphiteDelimiters(), "graphiteDelimiters must be supplied to enable graphite support");
            GraphiteFormatter graphiteFormatter = new GraphiteFormatter(proxyConfig.getGraphiteFormat(), proxyConfig.getGraphiteDelimiters(), proxyConfig.getGraphiteFieldsToRemove());
            csvToList(proxyConfig.getGraphitePorts()).forEach(strPort -> {
                preprocessors.getSystemPreprocessor(strPort).forPointLine().addTransformer(0, graphiteFormatter);
                startGraphiteListener(strPort, handlerFactory, null, spanSampler);
                logger.info("listening on port: " + strPort + " for graphite metrics");
            });
            csvToList(proxyConfig.getPicklePorts()).forEach(strPort -> startPickleListener(strPort, handlerFactory, graphiteFormatter));
        }
    }
    csvToList(proxyConfig.getOpentsdbPorts()).forEach(strPort -> startOpenTsdbListener(strPort, handlerFactory));
    if (proxyConfig.getDataDogJsonPorts() != null) {
        HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setUserAgent(proxyConfig.getHttpUserAgent()).setConnectionTimeToLive(1, TimeUnit.MINUTES).setMaxConnPerRoute(100).setMaxConnTotal(100).setRetryHandler(new DefaultHttpRequestRetryHandler(proxyConfig.getHttpAutoRetries(), true)).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(proxyConfig.getHttpConnectTimeout()).setConnectionRequestTimeout(proxyConfig.getHttpConnectTimeout()).setSocketTimeout(proxyConfig.getHttpRequestTimeout()).build()).build();
        csvToList(proxyConfig.getDataDogJsonPorts()).forEach(strPort -> startDataDogListener(strPort, handlerFactory, httpClient));
    }
    csvToList(proxyConfig.getTraceListenerPorts()).forEach(strPort -> startTraceListener(strPort, handlerFactory, spanSampler));
    csvToList(proxyConfig.getCustomTracingListenerPorts()).forEach(strPort -> startCustomTracingListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler));
    csvToList(proxyConfig.getTraceJaegerListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceJaegerListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getTraceJaegerGrpcListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceJaegerGrpcListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getTraceJaegerHttpListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceJaegerHttpListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getTraceZipkinListenerPorts()).forEach(strPort -> {
        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("point.spanSanitize", "count", "port", strPort)), null, null);
        preprocessors.getSystemPreprocessor(strPort).forSpan().addTransformer(new SpanSanitizeTransformer(ruleMetrics));
        startTraceZipkinListener(strPort, handlerFactory, new InternalProxyWavefrontClient(handlerFactory, strPort), spanSampler);
    });
    csvToList(proxyConfig.getPushRelayListenerPorts()).forEach(strPort -> startRelayListener(strPort, handlerFactory, remoteHostAnnotator));
    csvToList(proxyConfig.getJsonListenerPorts()).forEach(strPort -> startJsonListener(strPort, handlerFactory));
    csvToList(proxyConfig.getWriteHttpJsonListenerPorts()).forEach(strPort -> startWriteHttpJsonListener(strPort, handlerFactory));
    // Logs ingestion.
    if (proxyConfig.getFilebeatPort() > 0 || proxyConfig.getRawLogsPort() > 0) {
        if (loadLogsIngestionConfig() != null) {
            logger.info("Initializing logs ingestion");
            try {
                final LogsIngester logsIngester = new LogsIngester(handlerFactory, this::loadLogsIngestionConfig, proxyConfig.getPrefix());
                logsIngester.start();
                if (proxyConfig.getFilebeatPort() > 0) {
                    startLogsIngestionListener(proxyConfig.getFilebeatPort(), logsIngester);
                }
                if (proxyConfig.getRawLogsPort() > 0) {
                    startRawLogsIngestionListener(proxyConfig.getRawLogsPort(), logsIngester);
                }
            } catch (ConfigurationException e) {
                logger.log(Level.SEVERE, "Cannot start logsIngestion", e);
            }
        } else {
            logger.warning("Cannot start logsIngestion: invalid configuration or no config specified");
        }
    }
    setupMemoryGuard();
}
Also used : DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) SharedGraphiteHostAnnotator(com.wavefront.agent.channel.SharedGraphiteHostAnnotator) CompositeSampler(com.wavefront.sdk.entities.tracing.sampling.CompositeSampler) TaggedMetricName(com.wavefront.common.TaggedMetricName) ReportableEntityHandler(com.wavefront.agent.handlers.ReportableEntityHandler) ReportableEntityHandlerFactoryImpl(com.wavefront.agent.handlers.ReportableEntityHandlerFactoryImpl) DelegatingReportableEntityHandlerFactoryImpl(com.wavefront.agent.handlers.DelegatingReportableEntityHandlerFactoryImpl) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) ConfigurationException(com.wavefront.agent.config.ConfigurationException) HistogramRecompressor(com.wavefront.agent.histogram.HistogramRecompressor) ArrayList(java.util.ArrayList) Utils.csvToList(com.wavefront.common.Utils.csvToList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) HealthCheckManagerImpl(com.wavefront.agent.channel.HealthCheckManagerImpl) LogsIngester(com.wavefront.agent.logsharvesting.LogsIngester) TaskQueueFactoryImpl(com.wavefront.agent.queueing.TaskQueueFactoryImpl) GraphiteFormatter(com.wavefront.agent.formatter.GraphiteFormatter) NamedThreadFactory(com.wavefront.common.NamedThreadFactory) SpanSampler(com.wavefront.agent.sampler.SpanSampler) SQSQueueFactoryImpl(com.wavefront.agent.queueing.SQSQueueFactoryImpl) TrafficShapingRateLimitAdjuster(com.wavefront.agent.handlers.TrafficShapingRateLimitAdjuster) QueueingFactoryImpl(com.wavefront.agent.queueing.QueueingFactoryImpl) CachingHostnameLookupResolver(com.wavefront.agent.channel.CachingHostnameLookupResolver) SenderTaskFactoryImpl(com.wavefront.agent.handlers.SenderTaskFactoryImpl) CompositeSampler(com.wavefront.sdk.entities.tracing.sampling.CompositeSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Sampler(com.wavefront.sdk.entities.tracing.sampling.Sampler) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) HttpClient(org.apache.http.client.HttpClient) SpanSanitizeTransformer(com.wavefront.agent.preprocessor.SpanSanitizeTransformer) File(java.io.File) InternalProxyWavefrontClient(com.wavefront.agent.handlers.InternalProxyWavefrontClient)

Example 2 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler in project java by wavefrontHQ.

the class PushAgent method startDeltaCounterListener.

@VisibleForTesting
protected void startDeltaCounterListener(String strPort, SharedGraphiteHostAnnotator hostAnnotator, SenderTaskFactory senderTaskFactory, SpanSampler sampler) {
    final int port = Integer.parseInt(strPort);
    registerPrefixFilter(strPort);
    registerTimestampFilter(strPort);
    if (proxyConfig.isHttpHealthCheckAllPorts())
        healthCheckManager.enableHealthcheck(port);
    if (this.deltaCounterHandlerFactory == null) {
        this.deltaCounterHandlerFactory = new ReportableEntityHandlerFactory() {

            private final Map<String, ReportableEntityHandler<?, ?>> handlers = new ConcurrentHashMap<>();

            @Override
            public <T, U> ReportableEntityHandler<T, U> getHandler(HandlerKey handlerKey) {
                // noinspection unchecked
                return (ReportableEntityHandler<T, U>) handlers.computeIfAbsent(handlerKey.getHandle(), k -> new DeltaCounterAccumulationHandlerImpl(handlerKey, proxyConfig.getPushBlockedSamples(), senderTaskFactory.createSenderTasks(handlerKey), validationConfiguration, proxyConfig.getDeltaCountersAggregationIntervalSeconds(), rate -> entityProps.get(ReportableEntityType.POINT).reportReceivedRate(handlerKey.getHandle(), rate), blockedPointsLogger, VALID_POINTS_LOGGER));
            }

            @Override
            public void shutdown(@Nonnull String handle) {
                if (handlers.containsKey(handle)) {
                    handlers.values().forEach(ReportableEntityHandler::shutdown);
                }
            }
        };
    }
    shutdownTasks.add(() -> deltaCounterHandlerFactory.shutdown(strPort));
    WavefrontPortUnificationHandler wavefrontPortUnificationHandler = new WavefrontPortUnificationHandler(strPort, tokenAuthenticator, healthCheckManager, decoderSupplier.get(), deltaCounterHandlerFactory, hostAnnotator, preprocessors.get(strPort), () -> false, () -> false, () -> false, sampler);
    startAsManagedThread(port, new TcpIngester(createInitializer(wavefrontPortUnificationHandler, port, proxyConfig.getPushListenerMaxReceivedLength(), proxyConfig.getPushListenerHttpBufferSize(), proxyConfig.getListenerIdleConnectionTimeout(), getSslContext(strPort), getCorsConfig(strPort)), port).withChildChannelOptions(childChannelOptions), "listener-deltaCounter-" + port);
}
Also used : HandlerKey(com.wavefront.agent.handlers.HandlerKey) QueueingReason(com.wavefront.agent.data.QueueingReason) CustomTracingPortUnificationHandler(com.wavefront.agent.listeners.tracing.CustomTracingPortUnificationHandler) CompositeSampler(com.wavefront.sdk.entities.tracing.sampling.CompositeSampler) EntityProperties(com.wavefront.agent.data.EntityProperties) NettyServerBuilder(io.grpc.netty.NettyServerBuilder) RequestConfig(org.apache.http.client.config.RequestConfig) StringUtils(org.apache.commons.lang3.StringUtils) SpanSanitizeTransformer(com.wavefront.agent.preprocessor.SpanSanitizeTransformer) BooleanUtils(org.apache.commons.lang.BooleanUtils) InetAddress(java.net.InetAddress) SQSQueueFactoryImpl(com.wavefront.agent.queueing.SQSQueueFactoryImpl) PointHandlerDispatcher(com.wavefront.agent.histogram.PointHandlerDispatcher) Map(java.util.Map) HandlerKey(com.wavefront.agent.handlers.HandlerKey) ByteArrayDecoder(io.netty.handler.codec.bytes.ByteArrayDecoder) RecyclableRateLimiter(com.google.common.util.concurrent.RecyclableRateLimiter) HealthCheckManagerImpl(com.wavefront.agent.channel.HealthCheckManagerImpl) HistogramKey(com.wavefront.agent.histogram.HistogramKey) AdminPortUnificationHandler(com.wavefront.agent.listeners.AdminPortUnificationHandler) ChronicleMap(net.openhft.chronicle.map.ChronicleMap) ProxyUtil.createInitializer(com.wavefront.agent.ProxyUtil.createInitializer) Executors(java.util.concurrent.Executors) AgentDigestFactory(com.wavefront.agent.histogram.accumulator.AgentDigestFactory) ByteOrder(java.nio.ByteOrder) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) OpenTSDBDecoder(com.wavefront.ingester.OpenTSDBDecoder) ReportPointTimestampInRangeFilter(com.wavefront.agent.preprocessor.ReportPointTimestampInRangeFilter) AccumulationCache(com.wavefront.agent.histogram.accumulator.AccumulationCache) HealthCheckManager(com.wavefront.agent.channel.HealthCheckManager) ChannelOption(io.netty.channel.ChannelOption) SpanSampler(com.wavefront.agent.sampler.SpanSampler) TChannel(com.uber.tchannel.api.TChannel) Supplier(java.util.function.Supplier) RelayPortUnificationHandler(com.wavefront.agent.listeners.RelayPortUnificationHandler) TcpIngester(com.wavefront.ingester.TcpIngester) ArrayList(java.util.ArrayList) HttpClient(org.apache.http.client.HttpClient) SharedGraphiteHostAnnotator(com.wavefront.agent.channel.SharedGraphiteHostAnnotator) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConfigurationException(com.wavefront.agent.config.ConfigurationException) Utils.lazySupplier(com.wavefront.common.Utils.lazySupplier) Utils.csvToList(com.wavefront.common.Utils.csvToList) Server(org.logstash.beats.Server) TokenAuthenticatorBuilder(com.wavefront.agent.auth.TokenAuthenticatorBuilder) MapLoader(com.wavefront.agent.histogram.MapLoader) Nullable(javax.annotation.Nullable) HistogramUtils(com.wavefront.agent.histogram.HistogramUtils) DataDogPortUnificationHandler(com.wavefront.agent.listeners.DataDogPortUnificationHandler) SslContext(io.netty.handler.ssl.SslContext) WavefrontSender(com.wavefront.sdk.common.WavefrontSender) NO_RATE_LIMIT(com.wavefront.agent.data.EntityProperties.NO_RATE_LIMIT) WavefrontPortUnificationHandler(com.wavefront.agent.listeners.WavefrontPortUnificationHandler) File(java.io.File) CachingHostnameLookupResolver(com.wavefront.agent.channel.CachingHostnameLookupResolver) NamedThreadFactory(com.wavefront.common.NamedThreadFactory) GraphiteFormatter(com.wavefront.agent.formatter.GraphiteFormatter) ReportSourceTagDecoder(com.wavefront.ingester.ReportSourceTagDecoder) ReportableEntityDecoder(com.wavefront.ingester.ReportableEntityDecoder) VALID_POINTS_LOGGER(com.wavefront.agent.handlers.ReportableEntityHandlerFactoryImpl.VALID_POINTS_LOGGER) Preconditions(com.google.common.base.Preconditions) WriteHttpJsonPortUnificationHandler(com.wavefront.agent.listeners.WriteHttpJsonPortUnificationHandler) Metrics(com.yammer.metrics.Metrics) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) QueueingFactory(com.wavefront.agent.queueing.QueueingFactory) SpanSamplerUtils(com.wavefront.agent.sampler.SpanSamplerUtils) ReportPointDecoder(com.wavefront.ingester.ReportPointDecoder) LogsIngester(com.wavefront.agent.logsharvesting.LogsIngester) SpanLogsDecoder(com.wavefront.ingester.SpanLogsDecoder) Sampler(com.wavefront.sdk.entities.tracing.sampling.Sampler) ZipkinPortUnificationHandler(com.wavefront.agent.listeners.tracing.ZipkinPortUnificationHandler) TaskQueueFactory(com.wavefront.agent.queueing.TaskQueueFactory) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TokenAuthenticator(com.wavefront.agent.auth.TokenAuthenticator) ReportableEntityHandler(com.wavefront.agent.handlers.ReportableEntityHandler) HistogramAccumulationHandlerImpl(com.wavefront.agent.handlers.HistogramAccumulationHandlerImpl) Granularity(com.wavefront.agent.histogram.Granularity) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) ReportPoint(wavefront.report.ReportPoint) WavefrontInternalReporter(com.wavefront.internal.reporter.WavefrontInternalReporter) HistogramRecompressor(com.wavefront.agent.histogram.HistogramRecompressor) CorsConfigBuilder(io.netty.handler.codec.http.cors.CorsConfigBuilder) FilebeatIngester(com.wavefront.agent.logsharvesting.FilebeatIngester) PickleProtocolDecoder(com.wavefront.ingester.PickleProtocolDecoder) JaegerPortUnificationHandler(com.wavefront.agent.listeners.tracing.JaegerPortUnificationHandler) IdentityHashMap(java.util.IdentityHashMap) TaggedMetricName(com.wavefront.common.TaggedMetricName) ImmutableMap(com.google.common.collect.ImmutableMap) HttpHealthCheckEndpointHandler(com.wavefront.agent.listeners.HttpHealthCheckEndpointHandler) Accumulator(com.wavefront.agent.histogram.accumulator.Accumulator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Logger(java.util.logging.Logger) ReportableEntityHandlerFactoryImpl(com.wavefront.agent.handlers.ReportableEntityHandlerFactoryImpl) Collectors(java.util.stream.Collectors) ReportableEntityType(com.wavefront.data.ReportableEntityType) List(java.util.List) ExpectedAgentMetric(com.wavefront.metrics.ExpectedAgentMetric) ChannelByteArrayHandler(com.wavefront.agent.listeners.ChannelByteArrayHandler) QueueingFactoryImpl(com.wavefront.agent.queueing.QueueingFactoryImpl) JaegerTChannelCollectorHandler(com.wavefront.agent.listeners.tracing.JaegerTChannelCollectorHandler) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) HistogramDecoder(com.wavefront.ingester.HistogramDecoder) HashMap(java.util.HashMap) BindException(java.net.BindException) Function(java.util.function.Function) OpenTSDBPortUnificationHandler(com.wavefront.agent.listeners.OpenTSDBPortUnificationHandler) Level(java.util.logging.Level) JsonMetricsPortUnificationHandler(com.wavefront.agent.listeners.JsonMetricsPortUnificationHandler) TaskQueueFactoryImpl(com.wavefront.agent.queueing.TaskQueueFactoryImpl) ReportPointAddPrefixTransformer(com.wavefront.agent.preprocessor.ReportPointAddPrefixTransformer) ImmutableList(com.google.common.collect.ImmutableList) TrafficShapingRateLimitAdjuster(com.wavefront.agent.handlers.TrafficShapingRateLimitAdjuster) ObjectUtils(org.apache.commons.lang3.ObjectUtils) RawLogsIngesterPortUnificationHandler(com.wavefront.agent.listeners.RawLogsIngesterPortUnificationHandler) HistogramKeyMarshaller(com.wavefront.agent.histogram.HistogramUtils.HistogramKeyMarshaller) EventDecoder(com.wavefront.ingester.EventDecoder) ReportPointDecoderWrapper(com.wavefront.ingester.ReportPointDecoderWrapper) Nonnull(javax.annotation.Nonnull) InternalProxyWavefrontClient(com.wavefront.agent.handlers.InternalProxyWavefrontClient) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) Counter(com.yammer.metrics.core.Counter) SenderTaskFactory(com.wavefront.agent.handlers.SenderTaskFactory) AgentDigestMarshaller(com.tdunning.math.stats.AgentDigest.AgentDigestMarshaller) DelegatingReportableEntityHandlerFactoryImpl(com.wavefront.agent.handlers.DelegatingReportableEntityHandlerFactoryImpl) SpanDecoder(com.wavefront.ingester.SpanDecoder) CorsConfig(io.netty.handler.codec.http.cors.CorsConfig) VALID_HISTOGRAMS_LOGGER(com.wavefront.agent.handlers.ReportableEntityHandlerFactoryImpl.VALID_HISTOGRAMS_LOGGER) HttpMethod(io.netty.handler.codec.http.HttpMethod) AgentDigest(com.tdunning.math.stats.AgentDigest) DeltaCounterAccumulationHandlerImpl(com.wavefront.agent.handlers.DeltaCounterAccumulationHandlerImpl) TracePortUnificationHandler(com.wavefront.agent.listeners.tracing.TracePortUnificationHandler) TimeUnit(java.util.concurrent.TimeUnit) Connection(com.uber.tchannel.channels.Connection) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) ReportableEntityHandlerFactory(com.wavefront.agent.handlers.ReportableEntityHandlerFactory) SenderTaskFactoryImpl(com.wavefront.agent.handlers.SenderTaskFactoryImpl) JaegerGrpcCollectorHandler(com.wavefront.agent.listeners.tracing.JaegerGrpcCollectorHandler) ChannelHandler(io.netty.channel.ChannelHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Histogram(wavefront.report.Histogram) WavefrontPortUnificationHandler(com.wavefront.agent.listeners.WavefrontPortUnificationHandler) ReportPoint(wavefront.report.ReportPoint) ReportableEntityHandler(com.wavefront.agent.handlers.ReportableEntityHandler) NO_RATE_LIMIT(com.wavefront.agent.data.EntityProperties.NO_RATE_LIMIT) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DeltaCounterAccumulationHandlerImpl(com.wavefront.agent.handlers.DeltaCounterAccumulationHandlerImpl) ReportableEntityHandlerFactory(com.wavefront.agent.handlers.ReportableEntityHandlerFactory) TcpIngester(com.wavefront.ingester.TcpIngester) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler in project java by wavefrontHQ.

the class PushAgentTest method testWavefrontUnifiedPortHandlerPlaintextOverHttp.

@Test
public void testWavefrontUnifiedPortHandlerPlaintextOverHttp() throws Exception {
    port = findAvailablePort(2888);
    int securePort = findAvailablePort(2889);
    int healthCheckPort = findAvailablePort(8881);
    proxy.proxyConfig.privateCertPath = getClass().getClassLoader().getResource("demo.cert").getPath();
    proxy.proxyConfig.privateKeyPath = getClass().getClassLoader().getResource("demo.key").getPath();
    proxy.proxyConfig.tlsPorts = "1,23 , 4,   , " + securePort + "  ,6";
    proxy.initSslContext();
    proxy.proxyConfig.pushListenerPorts = port + "," + securePort;
    proxy.proxyConfig.httpHealthCheckPath = "/health";
    proxy.proxyConfig.httpHealthCheckPorts = String.valueOf(healthCheckPort);
    proxy.proxyConfig.httpHealthCheckAllPorts = true;
    proxy.healthCheckManager = new HealthCheckManagerImpl(proxy.proxyConfig);
    SpanSampler sampler = new SpanSampler(new RateSampler(1.0D), () -> null);
    proxy.startGraphiteListener(String.valueOf(port), mockHandlerFactory, null, sampler);
    proxy.startGraphiteListener(String.valueOf(securePort), mockHandlerFactory, null, sampler);
    proxy.startHealthCheckListener(healthCheckPort);
    waitUntilListenerIsOnline(port);
    waitUntilListenerIsOnline(securePort);
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test2").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test3").setTimestamp((startTime + 2) * 1000).setValue(2.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // try http connection
    String payloadStr = "metric3.test 0 " + startTime + " source=test1\n" + "metric3.test 1 " + (startTime + 1) + " source=test2\n" + "metric3.test 2 " + (startTime + 2) + // note the lack of newline at the end!
    " source=test3";
    assertEquals(202, httpPost("http://localhost:" + port, payloadStr));
    assertEquals(200, httpGet("http://localhost:" + port + "/health"));
    assertEquals(202, httpGet("http://localhost:" + port + "/health2"));
    assertEquals(200, httpGet("http://localhost:" + healthCheckPort + "/health"));
    assertEquals(404, httpGet("http://localhost:" + healthCheckPort + "/health2"));
    verify(mockPointHandler);
    // secure test
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test4").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test5").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric3.test").setHost("test6").setTimestamp((startTime + 2) * 1000).setValue(2.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // try http connection
    payloadStr = "metric3.test 0 " + startTime + " source=test4\n" + "metric3.test 1 " + (startTime + 1) + " source=test5\n" + "metric3.test 2 " + (startTime + 2) + // note the lack of newline at the end!
    " source=test6";
    assertEquals(202, httpPost("https://localhost:" + securePort, payloadStr));
    verify(mockPointHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) HealthCheckManagerImpl(com.wavefront.agent.channel.HealthCheckManagerImpl) ReportPoint(wavefront.report.ReportPoint) Test(org.junit.Test)

Example 4 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler in project java by wavefrontHQ.

the class PushAgentTest method testWavefrontHandlerAsDDIEndpoint.

@Test
public void testWavefrontHandlerAsDDIEndpoint() throws Exception {
    port = findAvailablePort(2978);
    proxy.proxyConfig.pushListenerPorts = String.valueOf(port);
    proxy.proxyConfig.dataBackfillCutoffHours = 8640;
    proxy.startGraphiteListener(proxy.proxyConfig.getPushListenerPorts(), mockHandlerFactory, null, new SpanSampler(new DurationSampler(5000), () -> null));
    waitUntilListenerIsOnline(port);
    String traceId = UUID.randomUUID().toString();
    long timestamp1 = startTime * 1000000 + 12345;
    long timestamp2 = startTime * 1000000 + 23456;
    String payloadStr = "metric4.test 0 " + startTime + " source=test1\n" + "metric4.test 1 " + (startTime + 1) + " source=test2\n" + "metric4.test 2 " + (startTime + 2) + // note the lack of newline at the end!
    " source=test3";
    String histoData = "!M " + startTime + " #5 10.0 #10 100.0 metric.test.histo source=test1\n" + "!M " + (startTime + 60) + " #5 20.0 #6 30.0 #7 40.0 metric.test.histo source=test2";
    String spanData = "testSpanName parent=parent1 source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" parent=parent2 " + startTime + " " + (startTime + 10);
    String spanDataToDiscard = "testSpanName parent=parent1 source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" parent=parent2 " + startTime + " " + (startTime + 1);
    String spanLogData = "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]}\n";
    String spanLogDataWithSpanField = "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\"}}]," + "\"span\":\"" + escapeSpanData(spanData) + "\"}\n";
    String spanLogDataWithSpanFieldToDiscard = "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}}]," + "\"span\":\"" + escapeSpanData(spanDataToDiscard) + "\"}\n";
    String mixedData = "@SourceTag action=save source=testSource newtag1 newtag2\n" + "@Event " + startTime + " \"Event name for testing\" host=host1 host=host2 tag=tag1 " + "severity=INFO multi=bar multi=baz\n" + "!M " + (startTime + 60) + " #5 20.0 #6 30.0 #7 40.0 metric.test.histo source=test2\n" + "metric4.test 0 " + startTime + " source=test1\n" + spanLogData + spanLogDataWithSpanField;
    String invalidData = "{\"spanId\"}\n@SourceTag\n@Event\n!M #5\nmetric.name\n" + "metric5.test 0 1234567890 source=test1\n";
    reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall().times(2);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test2").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall().times(2);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test3").setTimestamp((startTime + 2) * 1000).setValue(2.0d).build());
    expectLastCall().times(2);
    replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report", payloadStr));
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=wavefront", payloadStr));
    verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    mockHistogramHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test.histo").setHost("test1").setTimestamp(startTime * 1000).setValue(Histogram.newBuilder().setType(HistogramType.TDIGEST).setDuration(60000).setBins(ImmutableList.of(10.0d, 100.0d)).setCounts(ImmutableList.of(5, 10)).build()).build());
    expectLastCall();
    mockHistogramHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test.histo").setHost("test2").setTimestamp((startTime + 60) * 1000).setValue(Histogram.newBuilder().setType(HistogramType.TDIGEST).setDuration(60000).setBins(ImmutableList.of(20.0d, 30.0d, 40.0d)).setCounts(ImmutableList.of(5, 6, 7)).build()).build());
    expectLastCall();
    replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=histogram", histoData));
    verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3")).build())).build());
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime * 1000).setDuration(10000).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("parent", "parent1"), new Annotation("parent", "parent2"))).build());
    expectLastCall();
    replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=trace", spanData));
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogData));
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogDataWithSpanField));
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=trace", spanDataToDiscard));
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogDataWithSpanFieldToDiscard));
    verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    mockSourceTagHandler.report(ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).setAction(SourceTagAction.SAVE).setSource("testSource").setAnnotations(ImmutableList.of("newtag1", "newtag2")).build());
    expectLastCall();
    mockEventHandler.report(ReportEvent.newBuilder().setStartTime(startTime * 1000).setEndTime(startTime * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setTags(ImmutableList.of("tag1")).setAnnotations(ImmutableMap.of("severity", "INFO")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    proxy.entityProps.get(ReportableEntityType.HISTOGRAM).setFeatureDisabled(true);
    assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=histogram", histoData));
    proxy.entityProps.get(ReportableEntityType.TRACE).setFeatureDisabled(true);
    assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=trace", spanData));
    proxy.entityProps.get(ReportableEntityType.TRACE_SPAN_LOGS).setFeatureDisabled(true);
    assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogData));
    assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogDataWithSpanField));
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report", mixedData));
    verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    mockSourceTagHandler.report(ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).setAction(SourceTagAction.SAVE).setSource("testSource").setAnnotations(ImmutableList.of("newtag1", "newtag2")).build());
    expectLastCall();
    mockEventHandler.report(ReportEvent.newBuilder().setStartTime(startTime * 1000).setEndTime(startTime * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setTags(ImmutableList.of("tag1")).setAnnotations(ImmutableMap.of("severity", "INFO")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockSourceTagHandler.reject(eq("@SourceTag"), anyString());
    expectLastCall();
    mockEventHandler.reject(eq("@Event"), anyString());
    expectLastCall();
    mockPointHandler.reject(eq("metric.name"), anyString());
    expectLastCall();
    mockPointHandler.reject(eq(ReportPoint.newBuilder().setTable("dummy").setMetric("metric5.test").setHost("test1").setTimestamp(1234567890000L).setValue(0.0d).build()), startsWith("WF-402: Point outside of reasonable timeframe"));
    expectLastCall();
    replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
    assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report", mixedData + "\n" + invalidData));
    verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
}
Also used : SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) Annotation(wavefront.report.Annotation) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) Test(org.junit.Test)

Example 5 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler in project java by wavefrontHQ.

the class PushAgentTest method testCustomTraceUnifiedPortHandlerPlaintext.

@Test
public void testCustomTraceUnifiedPortHandlerPlaintext() throws Exception {
    customTracePort = findAvailablePort(50000);
    proxy.proxyConfig.customTracingListenerPorts = String.valueOf(customTracePort);
    proxy.startCustomTracingListener(proxy.proxyConfig.getCustomTracingListenerPorts(), mockHandlerFactory, mockWavefrontSender, new SpanSampler(new RateSampler(1.0D), () -> null));
    waitUntilListenerIsOnline(customTracePort);
    reset(mockTraceHandler);
    reset(mockTraceSpanLogsHandler);
    reset(mockWavefrontSender);
    String traceId = UUID.randomUUID().toString();
    long timestamp1 = startTime * 1000000 + 12345;
    long timestamp2 = startTime * 1000000 + 23456;
    String spanData = "testSpanName source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" application=application1 service=service1 " + startTime + " " + (startTime + 1) + "\n";
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime * 1000).setDuration(1000).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("application", "application1"), new Annotation("service", "service1"))).build());
    expectLastCall();
    Capture<HashMap<String, String>> tagsCapture = EasyMock.newCapture();
    mockWavefrontSender.sendMetric(eq(HEART_BEAT_METRIC), eq(1.0), anyLong(), eq("testsource"), EasyMock.capture(tagsCapture));
    EasyMock.expectLastCall().anyTimes();
    replay(mockTraceHandler, mockTraceSpanLogsHandler, mockWavefrontSender);
    Socket socket = SocketFactory.getDefault().createSocket("localhost", customTracePort);
    BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream());
    String payloadStr = spanData + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]}\n" + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]," + "\"span\":\"" + escapeSpanData(spanData) + "\"}\n";
    stream.write(payloadStr.getBytes());
    stream.flush();
    socket.close();
    verifyWithTimeout(500, mockTraceHandler, mockTraceSpanLogsHandler, mockWavefrontSender);
    HashMap<String, String> tagsReturned = tagsCapture.getValue();
    assertEquals("application1", tagsReturned.get(APPLICATION_TAG_KEY));
    assertEquals("service1", tagsReturned.get(SERVICE_TAG_KEY));
    assertEquals("none", tagsReturned.get(CLUSTER_TAG_KEY));
    assertEquals("none", tagsReturned.get(SHARD_TAG_KEY));
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) HashMap(java.util.HashMap) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) BufferedOutputStream(java.io.BufferedOutputStream) Annotation(wavefront.report.Annotation) Socket(java.net.Socket) Test(org.junit.Test)

Aggregations

SpanSampler (com.wavefront.agent.sampler.SpanSampler)47 Test (org.junit.Test)42 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)38 Annotation (wavefront.report.Annotation)32 Span (wavefront.report.Span)18 EasyMock.anyString (org.easymock.EasyMock.anyString)14 Batch (io.jaegertracing.thriftjava.Batch)12 ByteString (com.google.protobuf.ByteString)11 Process (io.jaegertracing.thriftjava.Process)11 Tag (io.jaegertracing.thriftjava.Tag)11 Model (io.opentelemetry.exporters.jaeger.proto.api_v2.Model)11 ByteBuffer (java.nio.ByteBuffer)11 Collector (io.opentelemetry.exporters.jaeger.proto.api_v2.Collector)10 Socket (java.net.Socket)10 Collector (io.jaegertracing.thriftjava.Collector)9 BufferedOutputStream (java.io.BufferedOutputStream)9 HashMap (java.util.HashMap)9 ReportPoint (wavefront.report.ReportPoint)9 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)7 ByteBuf (io.netty.buffer.ByteBuf)7