Skip to content

Commit 5747c1d

Browse files
authored
Set metricset.name for breakdown metrics (#4910)
* Set metricset.name for breakdown metrics Introduce model/modelprocessor.SetMetricsetName, which sets metricset.name for all agent metrics. Breakdown metrics get a specific name, everything else is named "app". Also, add Go system tests for metrics and get rid of a couple of Python-based ones. * tests/system: reinstate metricset system test tests/system/metricset.approved.json is used for generating docs. Until we change hat, we can't get rid of this test.
1 parent 26ea4e9 commit 5747c1d

14 files changed

Lines changed: 613 additions & 15 deletions

File tree

apmpackage/apm/0.1.0/docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ Metrics are written to `metrics-apm.app.*`, `metrics-apm.internal.*` and `metric
505505
"tag1": "one",
506506
"tag2": 2
507507
},
508+
"metricset.name": "app",
508509
"observer": {
509510
"ephemeral_id": "8785cbe1-7f89-4279-84c2-6c33979531fb",
510511
"hostname": "ix.lan",

beater/beater.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ func (s *serverRunner) run() error {
408408
}
409409

410410
func (s *serverRunner) wrapRunServerWithPreprocessors(runServer RunServerFunc) RunServerFunc {
411-
var processors []model.BatchProcessor
411+
processors := []model.BatchProcessor{
412+
// Set metricset.name for well-known agent metrics.
413+
modelprocessor.SetMetricsetName{},
414+
}
412415
if s.config.DefaultServiceEnvironment != "" {
413416
processors = append(processors, &modelprocessor.SetDefaultServiceEnvironment{
414417
DefaultServiceEnvironment: s.config.DefaultServiceEnvironment,

beater/test_approved_es_documents/TestPublishIntegrationEvents.approved.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@
400400
"success": true
401401
},
402402
"long_gauge": 3147483648,
403+
"metricset.name": "span_breakdown",
403404
"negative": {
404405
"d": {
405406
"o": {

beater/test_approved_es_documents/TestPublishIntegrationMetricsets.approved.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"tag2": 2
3030
},
3131
"long_gauge": 3147483648,
32+
"metricset.name": "span_breakdown",
3233
"negative": {
3334
"d": {
3435
"o": {
@@ -127,6 +128,7 @@
127128
"tag1": "one",
128129
"tag2": 2
129130
},
131+
"metricset.name": "app",
130132
"observer": {
131133
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
132134
"hostname": "",
@@ -173,6 +175,7 @@
173175
"tag1": "one",
174176
"tag2": 2
175177
},
178+
"metricset.name": "app",
176179
"observer": {
177180
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
178181
"hostname": "",

beater/test_approved_es_documents/TestPublishIntegrationMinimalEvents.approved.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"host": {
164164
"ip": "127.0.0.1"
165165
},
166+
"metricset.name": "app",
166167
"observer": {
167168
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
168169
"hostname": "",

changelogs/head.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ https://github.com/elastic/apm-server/compare/7.12\...master[View commits]
2020
* Transaction histogram metrics are now recorded by default {pull}4882[4882]
2121
* Add `error.grouping_name` field to speed up error grouping aggregations {pull}4886[4886]
2222
* Add support for OpenTelemetry exception span events {pull}4876[4876]
23+
* Set metricset.name for breakdown metrics {pull}4910[4910]
2324

2425
[float]
2526
==== Deprecated

docs/data/elasticsearch/generated/metricsets.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"tag1": "one",
2828
"tag2": 2
2929
},
30+
"metricset.name": "app",
3031
"observer": {
3132
"ephemeral_id": "8785cbe1-7f89-4279-84c2-6c33979531fb",
3233
"hostname": "ix.lan",
@@ -76,6 +77,7 @@
7677
"tag1": "one",
7778
"tag2": 2
7879
},
80+
"metricset.name": "app",
7981
"observer": {
8082
"ephemeral_id": "2f30050f-81e6-491a-a54f-e7d94eec17b5",
8183
"hostname": "simmac.net",
@@ -154,6 +156,7 @@
154156
"tag2": 2
155157
},
156158
"long_gauge": 3147483648.0,
159+
"metricset.name": "span_breakdown",
157160
"negative": {
158161
"d": {
159162
"o": {
@@ -227,4 +230,4 @@
227230
"name": "logged-in-user"
228231
}
229232
}
230-
]
233+
]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package modelprocessor
19+
20+
import (
21+
"context"
22+
"strings"
23+
24+
"github.com/elastic/apm-server/model"
25+
)
26+
27+
const (
28+
spanBreakdownMetricsetName = "span_breakdown"
29+
transactionBreakdownMetricsetName = "transaction_breakdown"
30+
appMetricsetName = "app"
31+
)
32+
33+
// SetMetricsetName is a transform.Processor that sets a name for
34+
// metricsets containing well-known agent metrics, such as breakdown
35+
// metrics.
36+
type SetMetricsetName struct{}
37+
38+
// ProcessBatch sets the name for metricsets. Well-defined metrics (breakdowns)
39+
// will be given a specific name, while all other metrics will be given the name
40+
// "app".
41+
func (SetMetricsetName) ProcessBatch(ctx context.Context, b *model.Batch) error {
42+
for _, ms := range b.Metricsets {
43+
if ms.Name != "" || len(ms.Samples) == 0 {
44+
continue
45+
}
46+
ms.Name = appMetricsetName
47+
if ms.Transaction.Type == "" {
48+
// Not a breakdown metricset.
49+
continue
50+
}
51+
if ms.Span.Type != "" {
52+
for _, sample := range ms.Samples {
53+
if strings.HasPrefix(sample.Name, "span.self_time.") {
54+
ms.Name = spanBreakdownMetricsetName
55+
break
56+
}
57+
}
58+
} else {
59+
for _, sample := range ms.Samples {
60+
if strings.HasPrefix(sample.Name, "transaction.breakdown.") {
61+
ms.Name = transactionBreakdownMetricsetName
62+
break
63+
}
64+
}
65+
}
66+
}
67+
return nil
68+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package modelprocessor_test
19+
20+
import (
21+
"context"
22+
"testing"
23+
24+
"github.com/stretchr/testify/assert"
25+
26+
"github.com/elastic/apm-server/model"
27+
"github.com/elastic/apm-server/model/modelprocessor"
28+
)
29+
30+
func TestSetMetricsetName(t *testing.T) {
31+
tests := []struct {
32+
metricset model.Metricset
33+
name string
34+
}{{
35+
metricset: model.Metricset{},
36+
name: "",
37+
}, {
38+
metricset: model.Metricset{Name: "already_set"},
39+
name: "already_set",
40+
}, {
41+
metricset: model.Metricset{Transaction: model.MetricsetTransaction{Type: "request"}},
42+
name: "",
43+
}, {
44+
metricset: model.Metricset{
45+
Samples: []model.Sample{{
46+
Name: "transaction.breakdown.count",
47+
}},
48+
},
49+
name: "app",
50+
}, {
51+
metricset: model.Metricset{
52+
Transaction: model.MetricsetTransaction{Type: "request"},
53+
Samples: []model.Sample{{
54+
Name: "transaction.duration.count",
55+
}, {
56+
Name: "transaction.breakdown.count",
57+
}},
58+
},
59+
name: "transaction_breakdown",
60+
}, {
61+
metricset: model.Metricset{
62+
Transaction: model.MetricsetTransaction{Type: "request"},
63+
Span: model.MetricsetSpan{Type: "app"},
64+
Samples: []model.Sample{{
65+
Name: "span.self_time.count",
66+
}},
67+
},
68+
name: "span_breakdown",
69+
}}
70+
71+
for _, test := range tests {
72+
batch := &model.Batch{Metricsets: []*model.Metricset{&test.metricset}}
73+
processor := modelprocessor.SetMetricsetName{}
74+
err := processor.ProcessBatch(context.Background(), batch)
75+
assert.NoError(t, err)
76+
assert.Equal(t, test.name, batch.Metricsets[0].Name)
77+
}
78+
79+
}

0 commit comments

Comments
 (0)