Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETOBSERV-1532: add TLS support to ebpf agent metrics config #305

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func FlowsAgent(cfg *Config) (*Flows, error) {
},
Prefix: cfg.MetricsPrefix,
}
if cfg.MetricsTLSCertPath != "" && cfg.MetricsTLSKeyPath != "" {
metricsSettings.PromConnectionInfo.TLS = &metrics.PromTLS{
CertPath: cfg.MetricsTLSCertPath,
KeyPath: cfg.MetricsTLSKeyPath,
}
}
m := metrics.NewMetrics(metricsSettings)

// configure selected exporter
Expand Down
4 changes: 4 additions & 0 deletions pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ type Config struct {
MetricsServerAddress string `env:"METRICS_SERVER_ADDRESS"`
// MetricsPort is the port of the server that collects ebpf agent metrics.
MetricsPort int `env:"METRICS_SERVER_PORT" envDefault:"9090"`
// MetricsTLSCertPath is the path to the server certificate for TLS connections
MetricsTLSCertPath string `env:"METRICS_TLS_CERT_PATH"`
// MetricsTLSKeyPath is the path to the server private key for TLS connections
MetricsTLSKeyPath string `env:"METRICS_TLS_KEY_PATH"`
// MetricsPrefix is the prefix of the metrics that are sent to the server.
MetricsPrefix string `env:"METRICS_PREFIX" envDefault:"ebpf_agent_"`

Expand Down
6 changes: 6 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ type MetricDefinition struct {
Labels []string
}

type PromTLS struct {
CertPath string
KeyPath string
}

type PromConnectionInfo struct {
Address string
Port int
TLS *PromTLS
}

type Settings struct {
Expand Down
7 changes: 6 additions & 1 deletion pkg/prometheus/prom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func StartServerAsync(conn *metrics.Settings, registry *prom.Registry) *http.Ser
httpServer = defaultServer(httpServer)

go func() {
err := httpServer.ListenAndServe()
var err error
if conn.TLS != nil {
err = httpServer.ListenAndServeTLS(conn.TLS.CertPath, conn.TLS.KeyPath)
} else {
err = httpServer.ListenAndServe()
}
if err != nil && err != http.ErrServerClosed {
maybePanic("error in http.ListenAndServe: %v", err)
}
Expand Down
Loading