Skip to content

Commit

Permalink
Traces downsampling policy
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkay committed Sep 27, 2024
1 parent 699e3d7 commit ed4b71e
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
21 changes: 21 additions & 0 deletions charmcraft-22.04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,24 @@ config:
even if there is no integration currently requesting it.
type: boolean
default: false
charm_traces_sampling_percentage:
description: >
This property defines the percentage of charm traces that are sent to tracing backend.
Setting it to 100 would mean all charm traces are kept, setting to 0 means charm traces
aren't sent to tracing backend at all.
type: float
default: 100.0
workload_traces_sampling_percentage:
description: >
This property defines the percentage of workload traces that are sent to tracing backend.
Setting it to 100 would mean all workload traces are kept, setting to 0 means workload traces
aren't sent to tracing backend at all.
type: float
default: 1.0
error_traces_sampling_percentage:
description: >
This property defines the percentage of error traces (regardless of the type) that are sent to tracing backend.
Setting it to 100 would mean all error traces are kept, setting to 0 means error traces
aren't sent to tracing backend at all.
type: float
default: 100.0
21 changes: 21 additions & 0 deletions charmcraft-24.04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,24 @@ config:
even if there is no integration currently requesting it.
type: boolean
default: false
charm_traces_sampling_percentage:
description: >
This property defines the percentage of charm traces that are sent to tracing backend.
Setting it to 100 would mean all charm traces are kept, setting to 0 means charm traces
aren't sent to tracing backend at all.
type: float
default: 100.0
workload_traces_sampling_percentage:
description: >
This property defines the percentage of workload traces that are sent to tracing backend.
Setting it to 100 would mean all workload traces are kept, setting to 0 means workload traces
aren't sent to tracing backend at all.
type: float
default: 1.0
error_traces_sampling_percentage:
description: >
This property defines the percentage of error traces (regardless of the type) that are sent to tracing backend.
Setting it to 100 would mean all error traces are kept, setting to 0 means error traces
aren't sent to tracing backend at all.
type: float
default: 100.0
86 changes: 86 additions & 0 deletions src/grafana_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,90 @@ def _receiver_config(protocol: str):

return config


@property
def _tracing_sampling(self) -> Dict[str, Any]:
return {
"policies": [
{
"name": "error-traces-policy",
"type": "and",
"and": {
"and_sub_policy": [
{
"name": "trace-status-policy",
"type": "status_code",
"status_code": {"status_codes": ["ERROR"]},
},
{
"name": "probabilistic-policy",
"type": "probabilistic",
"probabilistic": {
"sampling_percentage": self.config.get(
"error_traces_sampling_percentage"
)
},
},
]
},
},
{
"name": "charm-traces-policy",
"type": "and",
"and": {
"and_sub_policy": [
{
"name": "service-name-policy",
"type": "string_attribute",
"string_attribute": {
"key": "service.name",
"values": [".+-charm"],
"enabled_regex_matching": True,
},
},
{
"name": "probabilistic-policy",
"type": "probabilistic",
"probabilistic": {
"sampling_percentage": self.config.get(
"charm_traces_sampling_percentage"
)
},
},
]
},
},
{
"name": "workload-traces-policy",
"type": "and",
"and": {
"and_sub_policy": [
{
"name": "service-name-policy",
"type": "string_attribute",
"string_attribute": {
"key": "service.name",
"values": [".+-charm"],
"enabled_regex_matching": True,
"invert_match": True,
},
},
{
"name": "probabilistic-policy",
"type": "probabilistic",
"probabilistic": {
"sampling_percentage": self.config.get(
"workload_traces_sampling_percentage"
)
},
},
]
},
},
]
}


@property
def _tempo_config(self) -> Dict[str, Union[Any, List[Any]]]:
"""The tracing section of the config.
Expand All @@ -877,6 +961,7 @@ def _tempo_config(self) -> Dict[str, Union[Any, List[Any]]]:
"""
endpoints = self._tempo_endpoints_with_tls()
receivers = self._tracing_receivers
sampling = self._tracing_sampling

if not receivers:
# pushing a config with an empty receivers section will cause gagent to error out
Expand All @@ -888,6 +973,7 @@ def _tempo_config(self) -> Dict[str, Union[Any, List[Any]]]:
"name": "tempo",
"remote_write": endpoints,
"receivers": receivers,
"tail_sampling": sampling,
}
]
}
Expand Down

0 comments on commit ed4b71e

Please sign in to comment.