-
Notifications
You must be signed in to change notification settings - Fork 185
/
translator.go
50 lines (40 loc) · 1.79 KB
/
translator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package prometheus
import (
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/logs/metrics_collected/prometheus"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/exporter/awsemf"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/batchprocessor"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/receiver/adapter"
)
const (
pipelineName = "prometheus"
)
type translator struct {
}
var _ common.Translator[*common.ComponentTranslators] = (*translator)(nil)
func NewTranslator() common.Translator[*common.ComponentTranslators] {
return &translator{}
}
func (t *translator) ID() component.ID {
return component.NewIDWithName(component.DataTypeMetrics, pipelineName)
}
// Translate creates a pipeline for prometheus if the logs.metrics_collected.prometheus
// section is present.
func (t *translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators, error) {
key := common.ConfigKey(common.LogsKey, common.MetricsCollectedKey, common.PrometheusKey)
if conf == nil || !conf.IsSet(key) {
return nil, &common.MissingKeyError{ID: t.ID(), JsonKey: key}
}
return &common.ComponentTranslators{
Receivers: common.NewTranslatorMap(adapter.NewTranslator(prometheus.SectionKey, key, time.Minute)),
Processors: common.NewTranslatorMap(
batchprocessor.NewTranslatorWithNameAndSection(pipelineName, common.LogsKey), // prometheus sits under metrics_collected in "logs"
),
Exporters: common.NewTranslatorMap(awsemf.NewTranslatorWithName(pipelineName)),
}, nil
}