Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static mode tracing: Generate spanmetrics after load balancing. #5889

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Main (unreleased)

- Update `pyroscope.ebpf` to produce more optimal pprof profiles for python processes https://github.com/grafana/pyroscope/pull/2788 (@korniltsev)

- In Static mode's `traces` subsystem, `spanmetrics` used to be generated prior to load balancing.
This could lead to inaccurate metrics. This issue only affects Agents using both `spanmetrics` and
`load_balancing`, when running in a load balanced cluster with more than one Agent instance. (@ptodev)

v0.38.1 (2023-11-30)
--------------------

Expand Down
7 changes: 5 additions & 2 deletions pkg/traces/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func (c *InstanceConfig) extensions() (map[string]interface{}, error) {

func resolver(config map[string]interface{}) (map[string]interface{}, error) {
if len(config) == 0 {
return nil, fmt.Errorf("must configure one resolver (dns or static)")
return nil, fmt.Errorf("must configure one resolver (dns, static, or kubernetes)")
}
resolverCfg := make(map[string]interface{})
for typ, cfg := range config {
Expand Down Expand Up @@ -950,7 +950,9 @@ func tracingFactories() (otelcol.Factories, error) {
// sets: before and after load balancing
func orderProcessors(processors []string, splitPipelines bool) [][]string {
order := map[string]int{
"attributes": 0,
"attributes": 0,
// Spanmetrics should be before tail_sampling so that
// metrics are generated using as many spans as possible.
"spanmetrics": 1,
"service_graphs": 2,
"tail_sampling": 3,
Expand Down Expand Up @@ -978,6 +980,7 @@ func orderProcessors(processors []string, splitPipelines bool) [][]string {
if processor == "batch" ||
processor == "tail_sampling" ||
processor == "automatic_logging" ||
processor == "spanmetrics" ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this is the main bug fix, so that if we encounter the spanmetrics processor, we order it accordingly, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's the main bugfix.

if we encounter the spanmetrics processor, we order it accordingly, right?

I suppose your question is for Flow, since static mode automatically orders them? In Flow, if there are two Agents which ingest traces in a load balanced way, they need to be behind a load balancing exporter for spanmetrics to work ok.

processor == "service_graphs" {

foundAt = i
Expand Down
9 changes: 5 additions & 4 deletions pkg/traces/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1664,9 +1664,9 @@ service_graphs:
expectedProcessors: map[component.ID][]component.ID{
component.NewIDWithName("traces", "0"): {
component.NewID("attributes"),
component.NewID("spanmetrics"),
},
component.NewIDWithName("traces", "1"): {
component.NewID("spanmetrics"),
component.NewID("service_graphs"),
component.NewID("tail_sampling"),
component.NewID("automatic_logging"),
Expand Down Expand Up @@ -1715,9 +1715,9 @@ load_balancing:
expectedProcessors: map[component.ID][]component.ID{
component.NewIDWithName("traces", "0"): {
component.NewID("attributes"),
component.NewID("spanmetrics"),
},
component.NewIDWithName("traces", "1"): {
component.NewID("spanmetrics"),
component.NewID("automatic_logging"),
component.NewID("batch"),
},
Expand Down Expand Up @@ -1819,9 +1819,9 @@ func TestOrderProcessors(t *testing.T) {
expected: [][]string{
{
"attributes",
"spanmetrics",
},
{
"spanmetrics",
"tail_sampling",
"automatic_logging",
"batch",
Expand Down Expand Up @@ -1853,9 +1853,10 @@ func TestOrderProcessors(t *testing.T) {
expected: [][]string{
{
"attributes",
},
{
"spanmetrics",
},
{},
},
},
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/traces/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ func (i *Instance) buildAndStartPipeline(ctx context.Context, cfg InstanceConfig
}

if cfg.LoadBalancing == nil && (cfg.TailSampling != nil || cfg.ServiceGraphs != nil) {
i.logger.Warn("Configuring tail_sampling and/or service_graphs without load_balance." +
"Load balancing is required for those features to properly work in multi agent deployments")
i.logger.Warn("Configuring tail_sampling and/or service_graphs without load_balancing." +
"Load balancing via trace ID is required for those features to work properly in multi agent deployments")
}

if cfg.LoadBalancing == nil && cfg.SpanMetrics != nil {
i.logger.Warn("Configuring spanmetrics without load_balancing." +
"Load balancing via service name is required for spanmetrics to work properly in multi agent deployments")
}

if cfg.AutomaticLogging != nil && cfg.AutomaticLogging.Backend != automaticloggingprocessor.BackendStdout {
Expand Down