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

[connector/servicegraph] Coalesce different attr sets into single ScopeMetrics metric entry #34070

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
107 changes: 57 additions & 50 deletions connector/servicegraphconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,44 +472,48 @@ func (p *serviceGraphConnector) buildMetrics() (pmetric.Metrics, error) {
}

func (p *serviceGraphConnector) collectCountMetrics(ilm pmetric.ScopeMetrics) error {
for key, c := range p.reqTotal {
if len(p.reqTotal) > 0 {
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)
for key, c := range p.reqTotal {
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)
}
dimensions, ok := p.dimensionsForSeries(key)
if !ok {
return fmt.Errorf("failed to find dimensions for key %s", key)
}

dimensions.CopyTo(dpCalls.Attributes())
dimensions.CopyTo(dpCalls.Attributes())
}
}

for key, c := range p.reqFailedTotal {
if len(p.reqFailedTotal) > 0 {
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(c)
for key, c := range p.reqFailedTotal {
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)
}
dimensions, ok := p.dimensionsForSeries(key)
if !ok {
return fmt.Errorf("failed to find dimensions for key %s", key)
}

dimensions.CopyTo(dpCalls.Attributes())
dimensions.CopyTo(dpCalls.Attributes())
}
}

return nil
Expand All @@ -529,57 +533,60 @@ func (p *serviceGraphConnector) collectLatencyMetrics(ilm pmetric.ScopeMetrics)
}

func (p *serviceGraphConnector) collectClientLatencyMetrics(ilm pmetric.ScopeMetrics) error {
for key := range p.reqServerDurationSecondsCount {
if len(p.reqServerDurationSecondsCount) > 0 {
mDuration := ilm.Metrics().AppendEmpty()
mDuration.SetName("traces_service_graph_request_client_seconds")
// TODO: Support other aggregation temporalities
mDuration.SetEmptyHistogram().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)

timestamp := pcommon.NewTimestampFromTime(time.Now())

dpDuration := mDuration.Histogram().DataPoints().AppendEmpty()
dpDuration.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime))
dpDuration.SetTimestamp(timestamp)
dpDuration.ExplicitBounds().FromRaw(p.reqDurationBounds)
dpDuration.BucketCounts().FromRaw(p.reqServerDurationSecondsBucketCounts[key])
dpDuration.SetCount(p.reqServerDurationSecondsCount[key])
dpDuration.SetSum(p.reqServerDurationSecondsSum[key])
for key := range p.reqServerDurationSecondsCount {
dpDuration := mDuration.Histogram().DataPoints().AppendEmpty()
dpDuration.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime))
dpDuration.SetTimestamp(timestamp)
dpDuration.ExplicitBounds().FromRaw(p.reqDurationBounds)
dpDuration.BucketCounts().FromRaw(p.reqServerDurationSecondsBucketCounts[key])
dpDuration.SetCount(p.reqServerDurationSecondsCount[key])
dpDuration.SetSum(p.reqServerDurationSecondsSum[key])

// TODO: Support exemplars
dimensions, ok := p.dimensionsForSeries(key)
if !ok {
return fmt.Errorf("failed to find dimensions for key %s", key)
}

// TODO: Support exemplars
dimensions, ok := p.dimensionsForSeries(key)
if !ok {
return fmt.Errorf("failed to find dimensions for key %s", key)
dimensions.CopyTo(dpDuration.Attributes())
}

dimensions.CopyTo(dpDuration.Attributes())
}
return nil
}

func (p *serviceGraphConnector) collectServerLatencyMetrics(ilm pmetric.ScopeMetrics, mName string) error {
for key := range p.reqServerDurationSecondsCount {
if len(p.reqServerDurationSecondsCount) > 0 {
mDuration := ilm.Metrics().AppendEmpty()
mDuration.SetName(mName)
// TODO: Support other aggregation temporalities
mDuration.SetEmptyHistogram().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)

timestamp := pcommon.NewTimestampFromTime(time.Now())

dpDuration := mDuration.Histogram().DataPoints().AppendEmpty()
dpDuration.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime))
dpDuration.SetTimestamp(timestamp)
dpDuration.ExplicitBounds().FromRaw(p.reqDurationBounds)
dpDuration.BucketCounts().FromRaw(p.reqClientDurationSecondsBucketCounts[key])
dpDuration.SetCount(p.reqClientDurationSecondsCount[key])
dpDuration.SetSum(p.reqClientDurationSecondsSum[key])
for key := range p.reqServerDurationSecondsCount {

// TODO: Support exemplars
dimensions, ok := p.dimensionsForSeries(key)
if !ok {
return fmt.Errorf("failed to find dimensions for key %s", key)
}
dpDuration := mDuration.Histogram().DataPoints().AppendEmpty()
dpDuration.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime))
dpDuration.SetTimestamp(timestamp)
dpDuration.ExplicitBounds().FromRaw(p.reqDurationBounds)
dpDuration.BucketCounts().FromRaw(p.reqClientDurationSecondsBucketCounts[key])
dpDuration.SetCount(p.reqClientDurationSecondsCount[key])
dpDuration.SetSum(p.reqClientDurationSecondsSum[key])

// TODO: Support exemplars
dimensions, ok := p.dimensionsForSeries(key)
if !ok {
return fmt.Errorf("failed to find dimensions for key %s", key)
}

dimensions.CopyTo(dpDuration.Attributes())
dimensions.CopyTo(dpDuration.Attributes())
}
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion connector/servicegraphconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func TestConnectorConsume(t *testing.T) {
assert.NoError(t, conn.Shutdown(context.Background()))
})
t.Run("test fix failed label not work", func(t *testing.T) {
t.Skip("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33998 skip flaky test")
cfg := &Config{
Store: StoreConfig{MaxItems: 10},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ resourceMetrics:
stringValue: bar
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
isMonotonic: true
- name: traces_service_graph_request_total
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "1"
attributes:
- key: client
Expand Down Expand Up @@ -77,7 +72,7 @@ resourceMetrics:
stringValue: ""
- key: failed
value:
boolValue: false
boolValue: true
- key: server
value:
stringValue: bar
Expand All @@ -92,14 +87,14 @@ resourceMetrics:
- "0"
- "0"
- "0"
- "2"
- "1"
- "0"
- "0"
- "0"
- "0"
- "0"
- "0"
count: "2"
count: "1"
explicitBounds:
- 0.002
- 0.004
Expand All @@ -118,12 +113,8 @@ resourceMetrics:
- 10
- 15
startTimeUnixNano: "1000000"
sum: 2
sum: 1
timeUnixNano: "2000000"
name: traces_service_graph_request_server_seconds
- histogram:
aggregationTemporality: 2
dataPoints:
- attributes:
- key: client
value:
Expand All @@ -133,7 +124,7 @@ resourceMetrics:
stringValue: ""
- key: failed
value:
boolValue: true
boolValue: false
- key: server
value:
stringValue: bar
Expand All @@ -148,14 +139,14 @@ resourceMetrics:
- "0"
- "0"
- "0"
- "1"
- "2"
- "0"
- "0"
- "0"
- "0"
- "0"
- "0"
count: "1"
count: "2"
explicitBounds:
- 0.002
- 0.004
Expand All @@ -174,7 +165,7 @@ resourceMetrics:
- 10
- 15
startTimeUnixNano: "1000000"
sum: 1
sum: 2
timeUnixNano: "2000000"
name: traces_service_graph_request_server_seconds
- histogram:
Expand All @@ -189,7 +180,7 @@ resourceMetrics:
stringValue: ""
- key: failed
value:
boolValue: false
boolValue: true
- key: server
value:
stringValue: bar
Expand All @@ -204,14 +195,14 @@ resourceMetrics:
- "0"
- "0"
- "0"
- "2"
- "1"
- "0"
- "0"
- "0"
- "0"
- "0"
- "0"
count: "2"
count: "1"
explicitBounds:
- 0.002
- 0.004
Expand All @@ -230,12 +221,8 @@ resourceMetrics:
- 10
- 15
startTimeUnixNano: "1000000"
sum: 2
sum: 1
timeUnixNano: "2000000"
name: traces_service_graph_request_client_seconds
- histogram:
aggregationTemporality: 2
dataPoints:
- attributes:
- key: client
value:
Expand All @@ -245,7 +232,7 @@ resourceMetrics:
stringValue: ""
- key: failed
value:
boolValue: true
boolValue: false
- key: server
value:
stringValue: bar
Expand All @@ -260,14 +247,14 @@ resourceMetrics:
- "0"
- "0"
- "0"
- "1"
- "2"
- "0"
- "0"
- "0"
- "0"
- "0"
- "0"
count: "1"
count: "2"
explicitBounds:
- 0.002
- 0.004
Expand All @@ -286,7 +273,7 @@ resourceMetrics:
- 10
- 15
startTimeUnixNano: "1000000"
sum: 1
sum: 2
timeUnixNano: "2000000"
name: traces_service_graph_request_client_seconds
scope:
Expand Down