-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
factory.go
69 lines (58 loc) · 1.74 KB
/
factory.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package prometheusexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter"
import (
"context"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
)
// NewFactory creates a new Prometheus exporter factory.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability))
}
func createDefaultConfig() component.Config {
return &Config{
ConstLabels: map[string]string{},
SendTimestamps: false,
MetricExpiration: time.Minute * 5,
EnableOpenMetrics: false,
AddMetricSuffixes: true,
}
}
func createMetricsExporter(
ctx context.Context,
set exporter.CreateSettings,
cfg component.Config,
) (exporter.Metrics, error) {
pcfg := cfg.(*Config)
prometheus, err := newPrometheusExporter(pcfg, set)
if err != nil {
return nil, err
}
exporter, err := exporterhelper.NewMetricsExporter(
ctx,
set,
cfg,
prometheus.ConsumeMetrics,
exporterhelper.WithStart(prometheus.Start),
exporterhelper.WithShutdown(prometheus.Shutdown),
)
if err != nil {
return nil, err
}
return &wrapMetricsExporter{
Metrics: resourcetotelemetry.WrapMetricsExporter(pcfg.ResourceToTelemetrySettings, exporter),
exporter: prometheus,
}, nil
}
type wrapMetricsExporter struct {
exporter.Metrics
exporter *prometheusExporter
}