blob: 6d14ec689fcaccd455bb5f00281b422b5d40cc33 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.streamingvisitors;
import com.yahoo.vespa.streamingvisitors.tracing.LoggingTraceExporter;
import com.yahoo.vespa.streamingvisitors.tracing.MaxSamplesPerPeriod;
import com.yahoo.vespa.streamingvisitors.tracing.MonotonicNanoClock;
import com.yahoo.vespa.streamingvisitors.tracing.ProbabilisticSampleRate;
import com.yahoo.vespa.streamingvisitors.tracing.SamplingStrategy;
import com.yahoo.vespa.streamingvisitors.tracing.SamplingTraceExporter;
import com.yahoo.vespa.streamingvisitors.tracing.TraceExporter;
import java.util.concurrent.TimeUnit;
/**
* Encapsulates all trace-related components and options used by the streaming search Searcher.
*
* Provides a DEFAULT static instance which has the following characteristics:
* - Approximately 1 query every second is traced
* - Trace level is set to 7 for traced queries
* - Only emits traces for queries that have timed out and where the elapsed time is at least 2x
* of the timeout specified in the query itself
* - Emits traces to the Vespa log
* - Only 2 traces every 10 seconds may be emitted to the log
*/
public class TracingOptions {
private final SamplingStrategy samplingStrategy;
private final TraceExporter traceExporter;
private final MonotonicNanoClock clock;
private final int traceLevelOverride;
private final double traceTimeoutMultiplierThreshold;
/**
* @param samplingStrategy used for choosing if a query should have its trace level implicitly altered.
* @param traceExporter used for emitting a visitor session trace to someplace it may be debugged later.
* @param clock monotonic clock used for relative time tracking.
* @param traceLevelOverride if a query is trace-sampled, its traceLevel will be set to this value
* @param traceTimeoutMultiplierThreshold only export traces if the elapsed time is greater than the query timeout * this value
*/
public TracingOptions(SamplingStrategy samplingStrategy, TraceExporter traceExporter,
MonotonicNanoClock clock, int traceLevelOverride, double traceTimeoutMultiplierThreshold)
{
this.samplingStrategy = samplingStrategy;
this.traceExporter = traceExporter;
this.clock = clock;
this.traceLevelOverride = traceLevelOverride;
this.traceTimeoutMultiplierThreshold = traceTimeoutMultiplierThreshold;
}
public static final TracingOptions DEFAULT;
public static final int DEFAULT_TRACE_LEVEL_OVERRIDE = 7; // TODO determine appropriate trace level
// Traces won't be exported unless the query has timed out with a duration that is > timeout * multiplier
public static final double TRACE_TIMEOUT_MULTIPLIER_THRESHOLD = 2.0;
static {
SamplingStrategy queryTraceSampler = ProbabilisticSampleRate.withSystemDefaults(1);
SamplingStrategy logExportSampler = MaxSamplesPerPeriod.withSteadyClock(TimeUnit.SECONDS.toNanos(10), 2);
TraceExporter traceExporter = new SamplingTraceExporter(new LoggingTraceExporter(), logExportSampler);
DEFAULT = new TracingOptions(queryTraceSampler, traceExporter, System::nanoTime,
DEFAULT_TRACE_LEVEL_OVERRIDE, TRACE_TIMEOUT_MULTIPLIER_THRESHOLD);
}
public SamplingStrategy getSamplingStrategy() {
return samplingStrategy;
}
public TraceExporter getTraceExporter() {
return traceExporter;
}
public MonotonicNanoClock getClock() {
return clock;
}
public int getTraceLevelOverride() {
return traceLevelOverride;
}
public double getTraceTimeoutMultiplierThreshold() {
return traceTimeoutMultiplierThreshold;
}
}
|