Skip to content

Commit

Permalink
NETOBSERV-1532: add TLS support to ebpf agent metrics config
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Mar 25, 2024
1 parent 3a12ba2 commit 3450ec1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func FlowsAgent(cfg *Config) (*Flows, error) {
PromConnectionInfo: metrics.PromConnectionInfo{
Address: cfg.MetricsServerAddress,
Port: cfg.MetricsPort,
TLS: &metrics.PromTLS{
CertPath: cfg.MetricsTLSCACertPath,
KeyPath: cfg.MetricsTLSKeyPath,
},
},
Prefix: cfg.MetricsPrefix,
}
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"`
// MetricsTLSCACertPath is the path to the server certificate for TLS connections
MetricsTLSCACertPath string `env:"METRICS_TLS_CA_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 3450ec1

Please sign in to comment.