Skip to content

Commit

Permalink
Introduce metricset.name (elastic#4857)
Browse files Browse the repository at this point in the history
* Add metricset.name field to metrics docs

* aggregation/txmetrics: set metricset.name

* aggregation/spanmetrics: set metricset.name

* Add changelog entry
# Conflicts:
#	changelogs/7.12.asciidoc
#	include/fields.go
  • Loading branch information
axw committed Mar 25, 2021
1 parent 65b640e commit 2cc87a9
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 6 deletions.
10 changes: 5 additions & 5 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Elastic APM Server
Copyright 2014-2021 Elasticsearch BV

This product includes software developed by The Apache Software
This product includes software developed by The Apache Software
Foundation (http://www.apache.org/).

================================================================================
Expand Down Expand Up @@ -19976,13 +19976,13 @@ Contents of probable licence file $GOMODCACHE/howett.net/[email protected]
Copyright (c) 2013, Dustin L. Howett. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand All @@ -19996,7 +19996,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

--------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
type: keyword
description: |
Kubernetes Pod UID
- name: metricset.name
type: keyword
description: |
Name of the set of metrics.
- name: metricset.period
type: long
description: Current data collection period for this event in milliseconds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
type: keyword
description: |
Kubernetes Pod UID
- name: metricset.name
type: keyword
description: |
Name of the set of metrics.
- name: metricset.period
type: long
description: Current data collection period for this event in milliseconds.
Expand Down
1 change: 1 addition & 0 deletions apmpackage/apm/0.1.0/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ Metrics are written to `metrics-apm.app.*`, `metrics-apm.internal.*`, and `metri
|kubernetes.pod.name|Kubernetes pod name|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
|kubernetes.pod.uid|Kubernetes Pod UID|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
|labels|A flat mapping of user-defined labels with string, boolean or number values.|object| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-yes.png) |
|metricset.name|Name of the set of metrics.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
|metricset.period|Current data collection period for this event in milliseconds.|long| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
|observer.hostname|Hostname of the APM Server.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-yes.png) |
|observer.listening|Address the server is listening on.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
Expand Down
13 changes: 13 additions & 0 deletions docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4857,6 +4857,19 @@ type: object
--
*`metricset.name`*::
+
--
Name of the set of metrics.
type: keyword
example: transaction
--
[float]
=== service
Expand Down
2 changes: 1 addition & 1 deletion include/fields.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions model/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ type Metricset struct {
// instance, such as a hash of the labels used for aggregating the
// metrics.
TimeseriesInstanceID string

// Name holds an optional name for the metricset.
Name string
}

// Sample represents a single named metric.
Expand Down Expand Up @@ -197,6 +200,10 @@ func (me *Metricset) Transform(ctx context.Context, cfg *transform.Config) []bea
fields["timeseries"] = common.MapStr{"instance": me.TimeseriesInstanceID}
}

if me.Name != "" {
fields["metricset.name"] = me.Name
}

fields["processor"] = metricsetProcessorEntry

if cfg.DataStreams {
Expand Down
9 changes: 9 additions & 0 deletions model/metricset/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
description: >
A flat mapping of user-defined labels with string, boolean or number values.
- name: metricset
type: group
fields:
- name: name
type: keyword
description: >
Name of the set of metrics.
example: transaction

- name: service
type: group
dynamic: false
Expand Down
15 changes: 15 additions & 0 deletions model/metricset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ func TestTransform(t *testing.T) {
},
Msg: "Payload with empty metric.",
},
{
Metricset: &Metricset{Timestamp: timestamp, Metadata: metadata, Name: "raj"},
Output: []common.MapStr{
{
"data_stream.type": "metrics",
"data_stream.dataset": "apm.app.myservice",
"processor": common.MapStr{"event": "metric", "name": "metric"},
"metricset.name": "raj",
"service": common.MapStr{
"name": "myservice",
},
},
},
Msg: "Payload with metricset name.",
},
{
Metricset: &Metricset{
Metadata: metadata,
Expand Down
1 change: 1 addition & 0 deletions model/modeldecoder/rumv3/metricset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestDecodeMapToMetricsetModel(t *testing.T) {
strings.HasPrefix(key, "Transaction") ||
// only set by aggregator
strings.HasPrefix(key, "Event") ||
key == "Name" ||
key == "TimeseriesInstanceID" ||
strings.HasPrefix(key, "Span.DestinationService") ||
// test Samples separately
Expand Down
1 change: 1 addition & 0 deletions model/modeldecoder/v2/metricset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestDecodeMapToMetricsetModel(t *testing.T) {
if strings.HasPrefix(key, "Metadata") ||
// only set by aggregator
strings.HasPrefix(key, "Event") ||
key == "Name" ||
key == "TimeseriesInstanceID" ||
key == "Transaction.Result" ||
key == "Transaction.Root" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"metricset": {
"period": 1000
},
"metricset.name": "service_destination",
"observer": {
"ephemeral_id": "dynamic",
"hostname": "dynamic",
Expand Down
2 changes: 2 additions & 0 deletions systemtest/approvals/TestTransactionAggregation.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"hostname": "beowulf",
"name": "beowulf"
},
"metricset.name": "transaction",
"observer": {
"ephemeral_id": "dynamic",
"hostname": "dynamic",
Expand Down Expand Up @@ -71,6 +72,7 @@
"hostname": "beowulf",
"name": "beowulf"
},
"metricset.name": "transaction",
"observer": {
"ephemeral_id": "dynamic",
"hostname": "dynamic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"hostname": "beowulf",
"name": "beowulf"
},
"metricset.name": "transaction",
"observer": {
"ephemeral_id": "dynamic",
"hostname": "dynamic",
Expand Down
5 changes: 5 additions & 0 deletions x-pack/apm-server/aggregation/spanmetrics/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/elastic/beats/v7/libbeat/logp"
)

const (
metricsetName = "service_destination"
)

// AggregatorConfig holds configuration for creating an Aggregator.
type AggregatorConfig struct {
// Report is a publish.Reporter for reporting metrics documents.
Expand Down Expand Up @@ -260,6 +264,7 @@ type spanMetrics struct {
func makeMetricset(timestamp time.Time, key aggregationKey, metrics spanMetrics, interval int64) model.Metricset {
out := model.Metricset{
Timestamp: timestamp,
Name: metricsetName,
Metadata: model.Metadata{
Service: model.Service{
Name: key.serviceName,
Expand Down
5 changes: 5 additions & 0 deletions x-pack/apm-server/aggregation/spanmetrics/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestAggregatorRun(t *testing.T) {
}

assert.ElementsMatch(t, []*model.Metricset{{
Name: "service_destination",
Metadata: model.Metadata{
Service: model.Service{Name: "service-A", Agent: model.Agent{Name: "java"}},
},
Expand All @@ -141,6 +142,7 @@ func TestAggregatorRun(t *testing.T) {
{Name: "metricset.period", Value: 10},
},
}, {
Name: "service_destination",
Metadata: model.Metadata{
Service: model.Service{Name: "service-A", Agent: model.Agent{Name: "java"}},
},
Expand All @@ -156,6 +158,7 @@ func TestAggregatorRun(t *testing.T) {
{Name: "metricset.period", Value: 10},
},
}, {
Name: "service_destination",
Metadata: model.Metadata{
Service: model.Service{Name: "service-A", Agent: model.Agent{Name: "java"}},
},
Expand All @@ -171,6 +174,7 @@ func TestAggregatorRun(t *testing.T) {
{Name: "metricset.period", Value: 10},
},
}, {
Name: "service_destination",
Metadata: model.Metadata{
Service: model.Service{Name: "service-B", Agent: model.Agent{Name: "python"}},
},
Expand Down Expand Up @@ -231,6 +235,7 @@ func TestAggregatorOverflow(t *testing.T) {

m.Timestamp = time.Time{}
assert.Equal(t, &model.Metricset{
Name: "service_destination",
Metadata: model.Metadata{
Service: model.Service{Name: "service", Agent: model.Agent{Name: "agent"}},
},
Expand Down
3 changes: 3 additions & 0 deletions x-pack/apm-server/aggregation/txmetrics/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
// tooManyGroupsLoggerRateLimit is the maximum frequency at which
// "too many groups" log messages are logged.
tooManyGroupsLoggerRateLimit = time.Minute

metricsetName = "transaction"
)

// Aggregator aggregates transaction durations, periodically publishing histogram metrics.
Expand Down Expand Up @@ -365,6 +367,7 @@ func (a *Aggregator) makeTransactionAggregationKey(tx *model.Transaction) transa
func makeMetricset(key transactionAggregationKey, hash uint64, ts time.Time, counts []int64, values []float64) model.Metricset {
out := model.Metricset{
Timestamp: ts,
Name: metricsetName,
Metadata: model.Metadata{
Service: model.Service{
Name: key.serviceName,
Expand Down
3 changes: 3 additions & 0 deletions x-pack/apm-server/aggregation/txmetrics/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func TestProcessTransformablesOverflow(t *testing.T) {

m.Timestamp = time.Time{}
assert.Equal(t, &model.Metricset{
Name: "transaction",
Metadata: model.Metadata{},
Transaction: model.MetricsetTransaction{
Name: "baz",
Expand Down Expand Up @@ -288,6 +289,7 @@ func TestAggregateRepresentativeCount(t *testing.T) {

m.Timestamp = time.Time{}
assert.Equal(t, &model.Metricset{
Name: "transaction",
Metadata: model.Metadata{},
TimeseriesInstanceID: ":foo:1db641f187113b17",
Transaction: model.MetricsetTransaction{
Expand Down Expand Up @@ -398,6 +400,7 @@ func TestAggregationFields(t *testing.T) {
var expected []model.Metricset
addExpectedCount := func(expectedCount int64) {
expected = append(expected, model.Metricset{
Name: "transaction",
Metadata: input.Metadata,
Event: model.MetricsetEventCategorization{
Outcome: input.Outcome,
Expand Down

0 comments on commit 2cc87a9

Please sign in to comment.