diff --git a/.chloggen/service_graph_fix.yaml b/.chloggen/service_graph_fix.yaml new file mode 100644 index 0000000000000..7049bc90b1cf4 --- /dev/null +++ b/.chloggen/service_graph_fix.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: servicegraphprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: fix servicegraph failed to find dimensions + +# One or more tracking issues related to the change +issues: [] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/processor/servicegraphprocessor/processor.go b/processor/servicegraphprocessor/processor.go index 7f361ae21fd99..a55a8abb1cf04 100644 --- a/processor/servicegraphprocessor/processor.go +++ b/processor/servicegraphprocessor/processor.go @@ -308,14 +308,6 @@ func (p *processor) updateSeries(key string, dimensions pcommon.Map) { } } -func (p *processor) dimensionsForSeries(key string) (pcommon.Map, bool) { - if series, ok := p.keyToMetric[key]; ok { - return series.dimensions, true - } - - return pcommon.Map{}, false -} - func (p *processor) updateCountMetrics(key string) { p.reqTotal[key]++ } func (p *processor) updateErrorMetrics(key string) { p.reqFailedTotal[key]++ } @@ -363,29 +355,13 @@ func (p *processor) buildMetrics() (pmetric.Metrics, error) { } func (p *processor) collectCountMetrics(ilm pmetric.ScopeMetrics) error { - for key, c := range p.reqTotal { - mCount := ilm.Metrics().AppendEmpty() - mCount.SetName("traces_service_graph_request_total") - mCount.SetEmptySum().SetIsMonotonic(true) - // TODO: Support other aggregation temporalities - mCount.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) - - dpCalls := mCount.Sum().DataPoints().AppendEmpty() - dpCalls.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime)) - dpCalls.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) - dpCalls.SetIntValue(c) - - dimensions, ok := p.dimensionsForSeries(key) + for key, series := range p.keyToMetric { + value, ok := p.reqTotal[key] if !ok { - return fmt.Errorf("failed to find dimensions for key %s", key) + return fmt.Errorf("value not found in reqTotal by key %s", key) } - - dimensions.CopyTo(dpCalls.Attributes()) - } - - for key, c := range p.reqFailedTotal { mCount := ilm.Metrics().AppendEmpty() - mCount.SetName("traces_service_graph_request_failed_total") + mCount.SetName("traces_service_graph_request_total") mCount.SetEmptySum().SetIsMonotonic(true) // TODO: Support other aggregation temporalities mCount.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) @@ -393,21 +369,34 @@ func (p *processor) collectCountMetrics(ilm pmetric.ScopeMetrics) error { dpCalls := mCount.Sum().DataPoints().AppendEmpty() dpCalls.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime)) dpCalls.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) - dpCalls.SetIntValue(c) - - dimensions, ok := p.dimensionsForSeries(key) - if !ok { - return fmt.Errorf("failed to find dimensions for key %s", key) + dpCalls.SetIntValue(value) + series.dimensions.CopyTo(dpCalls.Attributes()) + + value, ok = p.reqFailedTotal[key] + if ok { + mCount = ilm.Metrics().AppendEmpty() + mCount.SetName("traces_service_graph_request_failed_total") + mCount.SetEmptySum().SetIsMonotonic(true) + // TODO: Support other aggregation temporalities + mCount.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + + dpCalls = mCount.Sum().DataPoints().AppendEmpty() + dpCalls.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime)) + dpCalls.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) + dpCalls.SetIntValue(value) + series.dimensions.CopyTo(dpCalls.Attributes()) } - - dimensions.CopyTo(dpCalls.Attributes()) } return nil } func (p *processor) collectLatencyMetrics(ilm pmetric.ScopeMetrics) error { - for key := range p.reqDurationSecondsCount { + for key, series := range p.keyToMetric { + _, ok := p.reqDurationSecondsCount[key] + if !ok { + return fmt.Errorf("value not found in reqDurationSecondsCount by key %s", key) + } mDuration := ilm.Metrics().AppendEmpty() mDuration.SetName("traces_service_graph_request_duration_seconds") // TODO: Support other aggregation temporalities @@ -425,13 +414,10 @@ func (p *processor) collectLatencyMetrics(ilm pmetric.ScopeMetrics) error { // TODO: Support exemplars - dimensions, ok := p.dimensionsForSeries(key) - if !ok { - return fmt.Errorf("failed to find dimensions for key %s", key) - } + series.dimensions.CopyTo(dpDuration.Attributes()) - dimensions.CopyTo(dpDuration.Attributes()) } + return nil }