Dataway Tail Sampling¶
Features¶
Dataway provides tail sampling capability, with external interfaces including:
/v1/tail_sampling/v1/tail_sampling_v2/v1/tail_sampling_config
Tail sampling is used to first receive data grouped and packaged on the Dataway side, then decide whether to keep or discard it based on sampling rules, and finally write the retained data to the center.
Currently, three types of data are supported:
tracingloggingrum
The basic processing flow is as follows:
sequenceDiagram
autonumber
participant dk as Datakit/Client
participant dw as Dataway
participant ts as TailSamplingProcessor
participant kodo as Kodo
dk ->> dw: POST /v1/tail_sampling
alt config ready
dw ->> ts: ingest packet
ts ->> dw: kept packets
dw ->> kodo: write tracing/logging/rum
else config not ready
dw ->> dw: pending cache
dw -->> dk: 412 Precondition Failed
dk ->> dw: POST /v1/tail_sampling_config
dw ->> ts: update config and drain pending
end
Working Modes¶
Tail sampling and aggregation share the same set of mode configurations:
standaloneproxy
standalone¶
In standalone mode, the current Dataway directly processes tail sampling data:
- Receives protobuf-encoded
aggregate.DataPacket - Looks up tail sampling configuration based on
token + data_type - When the configuration is ready, writes directly to
TailSamplingProcessor - Periodically retrieves expired groups and sends them to the corresponding data type write interface
In the current implementation:
- Sampling window advancement period is 1 second
- Derived metric refresh period is 1 minute
- The sending phase uses a worker pool for asynchronous writes
proxy¶
In proxy mode, the current Dataway does not retain local tail sampling state:
/v1/tail_samplingand/v1/tail_sampling_v2are forwarded to backend nodes/v1/tail_sampling_configis broadcast to all backend nodes
Therefore, in proxy mode:
aggregator_endpointmust be configured- Clients need to carry a valid
Guance-Pick-Key - Backend nodes are responsible for the actual sampling and state maintenance
Warning
In Kubernetes deployments, if the frontend Dataway needs to stably forward tail sampling requests to fixed backend nodes, then aggregator_endpoint must be filled with stable, unchanging backend addresses. It is recommended here to deploy the backend Dataway using StatefulSet to ensure Pod addresses and DNS names are stable, facilitating fixed forwarding by the frontend Dataway.
Local Configuration¶
Dataway does not have separate tail sampling YAML configuration items locally; tail sampling uses the same mode configuration as aggregation:
Environment variables:
Explanation:
standalone: The current node holds the tail sampling state itselfproxy: The current node only performs forwarding or broadcasting
In Kubernetes, if the frontend Dataway serves as the entry layer and the backend Dataway is responsible for actual tail sampling, the backend nodes are more suitable for deployment using StatefulSet, and the stable addresses of the StatefulSet Pods should be written into aggregator_endpoint.
Sampling Configuration Distribution¶
Tail sampling rules are distributed via an interface, not written in dataway.yaml:
The request body is JSON, with the top-level structure as follows:
Where:
tracecorresponds to tracing tail sampling configurationloggingcorresponds to logging tail sampling configurationrumcorresponds to rum tail sampling configuration
tracing Configuration Example¶
{
"version": 1,
"trace": {
"version": 1,
"data_ttl": "5m",
"group_key": "trace_id",
"pipelines": [
{
"name": "keep-all",
"type": "probabilistic",
"rate": 1
}
],
"builtin_metrics": [
{
"name": "trace_total_count",
"enabled": true
}
]
}
}
Explanation:
trace.group_keycan currently only betrace_idtrace.data_ttldefaults to5mwhen emptypipelinessupportsconditionandprobabilisticconditionusesaction=keep/dropprobabilisticusesrate=0~1
logging Configuration Example¶
{
"version": 1,
"logging": {
"version": 1,
"data_ttl": "1m",
"group_dimensions": [
{
"group_key": "service",
"pipelines": [
{
"name": "keep-all",
"type": "probabilistic",
"rate": 1
}
]
}
]
}
}
rum Configuration Example¶
{
"version": III,
"rum": {
"version": 1,
"data_ttl": "1m",
"group_dimensions": [
{
"group_key": "session_id",
"pipelines": [
{
"name": "keep-all",
"type": "probabilistic",
"rate": 1
}
]
}
]
}
}
Info
logging and rum use group_dimensions to configure grouping dimensions; data_ttl defaults to 1m for both when empty.
Warning
The current implementation validates configuration content. trace only allows group_key=trace_id; derived_metrics is not currently supported, and configuring it will return an error.
Data Reporting Interface¶
Tail sampling data interfaces:
Explanation:
- Both interfaces currently go through the same processing logic
- In
standalonemode, the request body needs to be a protobuf-encodedaggregate.DataPacket - In
proxymode, requests are forwarded to backend nodes
412 and pending cache¶
In standalone mode, if Dataway has just started and the sampling configuration for the corresponding token + data_type has not been distributed yet:
- Dataway will first put this batch of data into the local pending cache
- Then return
412 Precondition Failed
Current behavior:
- pending cache is an in-memory cache
- Temporarily stores data by
token + data_type - After successful configuration distribution, automatically drains available data to
TailSamplingProcessor - Currently defaults to caching a maximum of
100000packets
Agreed behavior:
- After receiving
412, the client considers this batch of data to have been accepted by Dataway - The client only needs to continue sending
/v1/tail_sampling_config - The client does not need to resend this batch of data
Exception cases:
- If the pending cache is full, Dataway returns
503 - In this case, the request cannot be considered as received
Tail Sampling Built-in Metrics¶
Tail sampling configuration supports builtin_metrics. These metrics are generated by the tail sampling processor during the sampling process and written to the center during periodic refreshes.
Current built-in metrics are as follows.
tracing¶
trace_total_counttrace_kept_counttrace_dropped_counttrace_error_countspan_total_counttrace_duration
Where:
trace_durationis a duration distribution metric- Others are count metrics
logging¶
logging_total_countlogging_error_countlogging_kept_countlogging_dropped_count
rum¶
rum_total_countrum_kept_countrum_dropped_count
Explanation:
- When
builtin_metricsis empty, it currently defaults to enabling all built-in metrics supported by that data type - These metrics come from the tail sampling process itself, not Dataway's own operational metrics
Dataway Automatic Reporting Metrics¶
In addition to the sampler's own builtin_metrics, apis/metrics_special.go also automatically maintains a set of Dataway self-observation metrics to describe the processing status of the tail sampling API.
Metrics currently related to tail sampling include:
| Metric Name | Type | Tags | Description |
|---|---|---|---|
dataway_http_api_body_size_bytes_total |
Counter | api, token |
Cumulative bytes of tail sampling interface request body |
dataway_http_tail_sampling_trace_total |
Counter | token |
Number of received tracing groups |
dataway_http_tail_sampling_span_total |
Counter | token |
Total number of received tracing spans |
dataway_http_tail_sampling_packet_send_total |
Counter | token, data_type, result |
Send result statistics, result includes success, failure, drop |
These metrics will:
- Be collected every 1 minute
- Be converted to
dataway_aggregatemetric points - Be reported to
/v1/write/metricusing the Dataway default token - Reset current accumulated values after reporting
This set of metrics reflects the operational status of Dataway itself processing tail sampling traffic, not the business statistics of the sampling rules themselves.