-
Notifications
You must be signed in to change notification settings - Fork 24
/
builtin_config.go
133 lines (125 loc) · 3.89 KB
/
builtin_config.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package otelconfig
import (
"crypto/tls"
"fmt"
"github.com/fluxninja/aperture/v2/pkg/info"
"github.com/fluxninja/aperture/v2/pkg/metrics"
"github.com/fluxninja/aperture/v2/pkg/net/listener"
otelconsts "github.com/fluxninja/aperture/v2/pkg/otelcollector/consts"
promapi "github.com/prometheus/client_golang/api"
)
// AddAlertsPipeline adds reusable alerts pipeline.
func AddAlertsPipeline(config *Config, cfg CommonOTelConfig, extraProcessors ...string) {
config.AddReceiver(otelconsts.ReceiverAlerts, map[string]any{})
config.AddProcessor(otelconsts.ProcessorAlertsNamespace, map[string]interface{}{
"actions": []map[string]interface{}{
{
"key": otelconsts.AlertNamespaceLabel,
"action": "insert",
"value": info.Hostname,
},
},
})
config.AddBatchProcessor(
otelconsts.ProcessorBatchAlerts,
cfg.BatchAlerts.Timeout.AsDuration(),
cfg.BatchAlerts.SendBatchSize,
cfg.BatchAlerts.SendBatchMaxSize,
)
config.AddExporter(otelconsts.ExporterAlerts, nil)
processors := []string{
otelconsts.ProcessorBatchAlerts,
otelconsts.ProcessorAlertsNamespace,
}
processors = append(processors, extraProcessors...)
config.Service.AddPipeline("logs/alerts", Pipeline{
Receivers: []string{otelconsts.ReceiverAlerts},
Processors: processors,
Exporters: []string{otelconsts.ExporterLogging, otelconsts.ExporterAlerts},
})
}
// AddPrometheusRemoteWriteExporter adds Prometheus remote write exporter which
// writes to controller Prometheus instance.
func AddPrometheusRemoteWriteExporter(config *Config, promClient promapi.Client) {
endpoint := promClient.URL("api/v1/write", nil)
// Unfortunately prometheus config structs do not have proper `mapstructure`
// tags, so they are not properly read by OTel. Need to use bare maps instead.
config.AddExporter(otelconsts.ExporterPrometheusRemoteWrite, map[string]any{
"endpoint": endpoint.String(),
"resource_to_telemetry_conversion": map[string]any{
"enabled": true,
},
})
}
// BuildApertureSelfScrapeConfig is a helper to create prometheus configuration
// which scrapes localhost.
func BuildApertureSelfScrapeConfig(
name string,
tlsConfig *tls.Config,
lis *listener.Listener,
) map[string]any {
scheme := "http"
if tlsConfig != nil {
scheme = "https"
}
return map[string]any{
"job_name": name,
"scheme": scheme,
"tls_config": map[string]any{
"insecure_skip_verify": true,
},
"metrics_path": "/metrics",
"static_configs": []map[string]any{
{
"targets": []string{lis.GetAddr()},
"labels": map[string]any{
metrics.InstanceLabel: info.Hostname,
metrics.ProcessUUIDLabel: info.UUID,
},
},
},
}
}
// BuildOTelScrapeConfig is a helper to create prometheus sonfiguration which
// scrapes OTel instance running on localhost.
func BuildOTelScrapeConfig(name string, cfg CommonOTelConfig) map[string]any {
otelDebugTarget := fmt.Sprintf(":%d", cfg.Ports.DebugPort)
return map[string]any{
"job_name": name,
"scheme": "http",
"tls_config": map[string]any{
"insecure_skip_verify": true,
},
"metrics_path": "/metrics",
"static_configs": []map[string]any{
{
"targets": []string{otelDebugTarget},
"labels": map[string]any{
metrics.InstanceLabel: info.Hostname,
metrics.ProcessUUIDLabel: info.UUID,
},
},
},
}
}
// AddHighCardinalityMetricsFilterProcessor adds filter processor which filters
// out high cardinality Aperture platform metrics.
func AddHighCardinalityMetricsFilterProcessor(config *Config) {
config.AddProcessor(otelconsts.ProcessorFilterHighCardinalityMetrics, map[string]any{
"metrics": map[string]interface{}{
"exclude": map[string]interface{}{
"match_type": "regexp",
"regexp": map[string]interface{}{
"cacheenabled": true,
"cachemaxnumentries": 1000,
},
"metric_names": []string{
"grpc_server_handled.*",
"grpc_server_handling.*",
"grpc_server_msg.*",
"grpc_server_started.*",
},
},
},
})
}