Skip to content

Commit

Permalink
NETOBSERV-1532: add TLS support to ebpf agent metrics config (#305)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 authored Mar 28, 2024
1 parent b63f1dd commit 5f3c1b2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
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

0 comments on commit 5f3c1b2

Please sign in to comment.