Skip to content

Commit

Permalink
feat: Enable pprof for metric agent (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Khalash authored and skhalash committed Apr 18, 2024
1 parent dceb3b0 commit bac402a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 84 deletions.
34 changes: 34 additions & 0 deletions internal/otelcollector/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package config

import (
"fmt"

"github.com/kyma-project/telemetry-manager/internal/otelcollector/ports"
)

type Base struct {
Extensions Extensions `yaml:"extensions"`
Service Service `yaml:"service"`
Expand Down Expand Up @@ -41,3 +47,31 @@ type Logs struct {
Level string `yaml:"level"`
Encoding string `yaml:"encoding"`
}

func DefaultService(pipelines Pipelines) Service {
telemetry := Telemetry{
Metrics: Metrics{
Address: fmt.Sprintf("${%s}:%d", EnvVarCurrentPodIP, ports.Metrics),
},
Logs: Logs{
Level: "info",
Encoding: "json",
},
}
return Service{
Pipelines: pipelines,
Telemetry: telemetry,
Extensions: []string{"health_check", "pprof"},
}
}

func DefaultExtensions() Extensions {
return Extensions{
HealthCheck: Endpoint{
Endpoint: fmt.Sprintf("${%s}:%d", EnvVarCurrentPodIP, ports.HealthCheck),
},
Pprof: Endpoint{
Endpoint: fmt.Sprintf("127.0.0.1:%d", ports.Pprof),
},
}
}
28 changes: 2 additions & 26 deletions internal/otelcollector/config/metric/agent/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func MakeConfig(gatewayServiceName types.NamespacedName, pipelines []telemetryv1

return &Config{
Base: config.Base{
Extensions: makeExtensionsConfig(),
Service: makeServiceConfig(inputs),
Service: config.DefaultService(makePipelinesConfig(inputs)),
Extensions: config.DefaultExtensions(),
},
Receivers: makeReceiversConfig(inputs, isIstioActive),
Processors: makeProcessorsConfig(inputs),
Expand Down Expand Up @@ -85,30 +85,6 @@ func makeExportersConfig(gatewayServiceName types.NamespacedName) Exporters {
}
}

func makeExtensionsConfig() config.Extensions {
return config.Extensions{
HealthCheck: config.Endpoint{
Endpoint: fmt.Sprintf("${%s}:%d", config.EnvVarCurrentPodIP, ports.HealthCheck),
},
}
}

func makeServiceConfig(inputs inputSources) config.Service {
return config.Service{
Pipelines: makePipelinesConfig(inputs),
Telemetry: config.Telemetry{
Metrics: config.Metrics{
Address: fmt.Sprintf("${%s}:%d", config.EnvVarCurrentPodIP, ports.Metrics),
},
Logs: config.Logs{
Level: "info",
Encoding: "json",
},
},
Extensions: []string{"health_check"},
}
}

func makePipelinesConfig(inputs inputSources) config.Pipelines {
pipelinesConfig := make(config.Pipelines)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extensions:
health_check:
endpoint: ${MY_POD_IP}:13133
pprof:
endpoint: 127.0.0.1:1777
service:
pipelines:
metrics/istio:
Expand Down Expand Up @@ -43,6 +45,7 @@ service:
encoding: json
extensions:
- health_check
- pprof
receivers:
kubeletstats:
collection_interval: 30s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extensions:
health_check:
endpoint: ${MY_POD_IP}:13133
pprof:
endpoint: 127.0.0.1:1777
service:
pipelines:
metrics/istio:
Expand Down Expand Up @@ -43,6 +45,7 @@ service:
encoding: json
extensions:
- health_check
- pprof
receivers:
kubeletstats:
collection_interval: 30s
Expand Down
31 changes: 2 additions & 29 deletions internal/otelcollector/config/metric/gateway/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
func MakeConfig(ctx context.Context, c client.Reader, pipelines []telemetryv1alpha1.MetricPipeline) (*Config, otlpexporter.EnvVars, error) {
cfg := &Config{
Base: config.Base{
Service: makeServiceConfig(),
Extensions: makeExtensionsConfig(),
Service: config.DefaultService(make(config.Pipelines)),
Extensions: config.DefaultExtensions(),
},
Receivers: makeReceiversConfig(),
Processors: makeProcessorsConfig(),
Expand Down Expand Up @@ -61,33 +61,6 @@ func makeReceiversConfig() Receivers {
}
}

func makeExtensionsConfig() config.Extensions {
return config.Extensions{
HealthCheck: config.Endpoint{
Endpoint: fmt.Sprintf("${%s}:%d", config.EnvVarCurrentPodIP, ports.HealthCheck),
},
Pprof: config.Endpoint{
Endpoint: fmt.Sprintf("127.0.0.1:%d", ports.Pprof),
},
}
}

func makeServiceConfig() config.Service {
return config.Service{
Pipelines: make(config.Pipelines),
Telemetry: config.Telemetry{
Metrics: config.Metrics{
Address: fmt.Sprintf("${%s}:%d", config.EnvVarCurrentPodIP, ports.Metrics),
},
Logs: config.Logs{
Level: "info",
Encoding: "json",
},
},
Extensions: []string{"health_check", "pprof"},
}
}

// declareComponentsForMetricPipeline enriches a Config (exporters, processors, etc.) with components for a given telemetryv1alpha1.MetricPipeline.
func declareComponentsForMetricPipeline(ctx context.Context, otlpExporterBuilder *otlpexporter.ConfigBuilder, pipeline *telemetryv1alpha1.MetricPipeline, cfg *Config, envVars otlpexporter.EnvVars) error {
declareDiagnosticMetricsDropFilters(pipeline, cfg)
Expand Down
31 changes: 2 additions & 29 deletions internal/otelcollector/config/trace/gateway/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
func MakeConfig(ctx context.Context, c client.Reader, pipelines []telemetryv1alpha1.TracePipeline) (*Config, otlpexporter.EnvVars, error) {
cfg := &Config{
Base: config.Base{
Service: makeServiceConfig(),
Extensions: makeExtensionsConfig(),
Service: config.DefaultService(make(config.Pipelines)),
Extensions: config.DefaultExtensions(),
},
Receivers: makeReceiversConfig(),
Processors: makeProcessorsConfig(),
Expand Down Expand Up @@ -61,33 +61,6 @@ func makeReceiversConfig() Receivers {
}
}

func makeExtensionsConfig() config.Extensions {
return config.Extensions{
HealthCheck: config.Endpoint{
Endpoint: fmt.Sprintf("${%s}:%d", config.EnvVarCurrentPodIP, ports.HealthCheck),
},
Pprof: config.Endpoint{
Endpoint: fmt.Sprintf("127.0.0.1:%d", ports.Pprof),
},
}
}

func makeServiceConfig() config.Service {
return config.Service{
Pipelines: make(config.Pipelines),
Telemetry: config.Telemetry{
Metrics: config.Metrics{
Address: fmt.Sprintf("${%s}:%d", config.EnvVarCurrentPodIP, ports.Metrics),
},
Logs: config.Logs{
Level: "info",
Encoding: "json",
},
},
Extensions: []string{"health_check", "pprof"},
}
}

// addComponentsForTracePipeline enriches a Config (exporters, processors, etc.) with components for a given telemetryv1alpha1.TracePipeline.
func addComponentsForTracePipeline(ctx context.Context, otlpExporterBuilder *otlpexporter.ConfigBuilder, pipeline *telemetryv1alpha1.TracePipeline, cfg *Config, envVars otlpexporter.EnvVars) error {
otlpExporterConfig, otlpExporterEnvVars, err := otlpExporterBuilder.MakeConfig(ctx)
Expand Down

0 comments on commit bac402a

Please sign in to comment.