|
| 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