Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 56bf32c

Browse files
committedSep 2, 2021
Introduce dedicated fields for internal metrics
Add dedicated fields to model.Transaction and model.Span for well-defined, internal transaction and span metrics. Drop unknown metrics received in metricsets with any transaction or span fields defined. Internal metrics will be indexed with strict mapping. We already have explicitly defined fields for these metrics. This PR ensures that unknown metrics do not slip through. If an agent is upgraded before the server and some new internal metric starts being produced, that must not be indexed as it would cause other internal metrics to be rejected by Elasticsearch. Drop the unused `metricset.period` field that was being added to service_destination metrics.
1 parent d2ee2dd commit 56bf32c

31 files changed

+601
-426
lines changed
 

‎beater/test_approved_es_documents/TestPublishIntegrationEvents.approved.json

+10-16
Original file line numberDiff line numberDiff line change
@@ -650,16 +650,12 @@
650650
"name": "java",
651651
"version": "1.10.0"
652652
},
653-
"byte_counter": 1,
654653
"container": {
655654
"id": "8ec7ceb990749e79b37f6dc6cd3628633618d6ce412553a552a0fa6b69419ad4"
656655
},
657-
"dotted.float.gauge": 6.12,
658-
"double_gauge": 3.141592653589793,
659656
"ecs": {
660657
"version": "1.10.0"
661658
},
662-
"float_gauge": 9.16,
663659
"host": {
664660
"architecture": "amd64",
665661
"hostname": "node-name",
@@ -669,7 +665,6 @@
669665
"platform": "Linux"
670666
}
671667
},
672-
"integer_gauge": 42767,
673668
"kubernetes": {
674669
"namespace": "default",
675670
"node": {
@@ -687,9 +682,7 @@
687682
"segment": 5,
688683
"success": true
689684
},
690-
"long_gauge": 3147483648,
691685
"metricset.name": "span_breakdown",
692-
"negative.d.o.t.t.e.d": -1022,
693686
"observer": {
694687
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
695688
"id": "fbba762a-14dd-412c-b7e9-b79f903eb492",
@@ -729,22 +722,23 @@
729722
},
730723
"version": "4.3.0"
731724
},
732-
"short_counter": 227,
733725
"span": {
726+
"self_time": {
727+
"count": 1,
728+
"sum.us": 633
729+
},
734730
"subtype": "mysql",
735731
"type": "db"
736732
},
737-
"span.self_time.count": 1,
738-
"span.self_time.sum.us": 633.288,
739733
"transaction": {
734+
"breakdown.count": 12,
735+
"duration": {
736+
"count": 2,
737+
"sum.us": 12
738+
},
740739
"name": "GET/",
741740
"type": "request"
742-
},
743-
"transaction.breakdown.count": 12,
744-
"transaction.duration.count": 2,
745-
"transaction.duration.sum.us": 12,
746-
"transaction.self_time.count": 2,
747-
"transaction.self_time.sum.us": 10
741+
}
748742
}
749743
]
750744
}

‎beater/test_approved_es_documents/TestPublishIntegrationMetricsets.approved.json

+9-15
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,20 @@
66
"name": "elastic-node",
77
"version": "3.14.0"
88
},
9-
"byte_counter": 1,
10-
"dotted.float.gauge": 6.12,
11-
"double_gauge": 3.141592653589793,
129
"ecs": {
1310
"version": "1.10.0"
1411
},
15-
"float_gauge": 9.16,
1612
"host": {
1713
"ip": "127.0.0.1"
1814
},
19-
"integer_gauge": 42767,
2015
"labels": {
2116
"code": 200,
2217
"some": "abc",
2318
"success": true,
2419
"tag1": "one",
2520
"tag2": 2
2621
},
27-
"long_gauge": 3147483648,
2822
"metricset.name": "span_breakdown",
29-
"negative.d.o.t.t.e.d": -1022,
3023
"observer": {
3124
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
3225
"id": "fbba762a-14dd-412c-b7e9-b79f903eb492",
@@ -50,22 +43,23 @@
5043
"name": "node-1"
5144
}
5245
},
53-
"short_counter": 227,
5446
"span": {
47+
"self_time": {
48+
"count": 1,
49+
"sum.us": 633
50+
},
5551
"subtype": "mysql",
5652
"type": "db"
5753
},
58-
"span.self_time.count": 1,
59-
"span.self_time.sum.us": 633.288,
6054
"transaction": {
55+
"breakdown.count": 12,
56+
"duration": {
57+
"count": 2,
58+
"sum.us": 12
59+
},
6160
"name": "GET /",
6261
"type": "request"
6362
},
64-
"transaction.breakdown.count": 12,
65-
"transaction.duration.count": 2,
66-
"transaction.duration.sum.us": 12,
67-
"transaction.self_time.count": 2,
68-
"transaction.self_time.sum.us": 10,
6963
"user": {
7064
"email": "user@mail.com",
7165
"id": "axb123hg",

‎changelogs/head.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ https://github.com/elastic/apm-server/compare/7.13\...master[View commits]
1313
- Removed unused support for top-level metricsets and metricset tags for RUMv3 {pull}6065[6065]
1414
- Removed `apm-server.mode` configuration, and "experimental" fields {pull}6086[6086]
1515
- `transaction.sampled` is now only set for sampled transactions {pull}6066[6066]
16+
- Unknown metrics are dropped when `transaction.*` or `span.*` are present in a metricset {pull}6111[6111]
17+
- Removed `metricset.period` from service_destination metrics {pull}6111[6111]
1618

1719
[float]
1820
==== Bug fixes

‎model/metricset.go

+38-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package model
1919

2020
import (
21+
"time"
22+
2123
"github.com/elastic/beats/v7/libbeat/common"
2224
)
2325

@@ -81,6 +83,12 @@ type MetricsetSample struct {
8183
// If Counts and Values are specified, then Value will be ignored.
8284
Value float64
8385

86+
// Histogram holds bucket values and counts for histogram metrics.
87+
Histogram
88+
}
89+
90+
// Histogram holds bucket values and counts for a histogram metric.
91+
type Histogram struct {
8492
// Values holds the bucket values for histogram metrics.
8593
//
8694
// These values must be provided in ascending order.
@@ -96,6 +104,35 @@ type MetricsetSample struct {
96104
Counts []int64
97105
}
98106

107+
func (h *Histogram) fields() common.MapStr {
108+
if len(h.Counts) == 0 {
109+
return nil
110+
}
111+
var fields mapStr
112+
fields.set("counts", h.Counts)
113+
fields.set("values", h.Values)
114+
return common.MapStr(fields)
115+
}
116+
117+
// AggregatedDuration holds a count and sum of aggregated durations.
118+
type AggregatedDuration struct {
119+
// Count holds the number of durations aggregated.
120+
Count int
121+
122+
// Sum holds the sum of aggregated durations.
123+
Sum time.Duration
124+
}
125+
126+
func (a *AggregatedDuration) fields() common.MapStr {
127+
if a.Count == 0 {
128+
return nil
129+
}
130+
var fields mapStr
131+
fields.set("count", a.Count)
132+
fields.set("sum.us", a.Sum.Microseconds())
133+
return common.MapStr(fields)
134+
}
135+
99136
func (me *Metricset) setFields(fields *mapStr) {
100137
if me.TimeseriesInstanceID != "" {
101138
fields.set("timeseries", common.MapStr{"instance": me.TimeseriesInstanceID})
@@ -119,10 +156,7 @@ func (me *Metricset) setFields(fields *mapStr) {
119156

120157
func (s *MetricsetSample) set(name string, fields *mapStr) {
121158
if s.Type == MetricTypeHistogram {
122-
fields.set(name, common.MapStr{
123-
"counts": s.Counts,
124-
"values": s.Values,
125-
})
159+
fields.set(name, s.Histogram.fields())
126160
} else {
127161
fields.set(name, s.Value)
128162
}

0 commit comments

Comments
 (0)
Please sign in to comment.