1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/metrics/init.go
Tathagata Paul 3e2894b6fa
feat: Opentelemetry support for metrics and traces (#3910)
* integrating opentelemetry

Signed-off-by: Tathagata Paul <tathagatapaul7@gmail.com>

* fix multiple imports

Signed-off-by: Tathagata Paul <tathagatapaul7@gmail.com>

* fixed cli help statement

Signed-off-by: Tathagata Paul <tathagatapaul7@gmail.com>

* added init file for metrics

Signed-off-by: Tathagata Paul <tathagatapaul7@gmail.com>

Co-authored-by: shuting <shuting@nirmata.com>
2022-07-11 17:49:47 +00:00

49 lines
1.2 KiB
Go

package metrics
import (
"net/http"
"github.com/go-logr/logr"
"github.com/kyverno/kyverno/pkg/config"
"k8s.io/client-go/kubernetes"
)
func InitMetrics(
disableMetricsExport bool,
otel string,
metricsAddr string,
otelCollector string,
metricsConfigData *config.MetricsConfigData,
transportCreds string,
kubeClient kubernetes.Interface,
log logr.Logger) (*MetricsConfig, *http.ServeMux, error) {
var metricsConfig *MetricsConfig
var err error
var metricsServerMux *http.ServeMux
if !disableMetricsExport {
if otel == "grpc" {
// Otlpgrpc metrics will be served on port 4317: default port for otlpgrpcmetrics
log.Info("Enabling Metrics for Kyverno", "address", metricsAddr)
endpoint := otelCollector + metricsAddr
metricsConfig, err = NewOTLPGRPCConfig(
endpoint,
metricsConfigData,
transportCreds,
kubeClient,
log,
)
if err != nil {
return nil, nil, err
}
} else if otel == "prometheus" {
// Prometheus Server will serve metrics on metrics-port
metricsConfig, metricsServerMux, err = NewPrometheusConfig(metricsConfigData, log)
if err != nil {
return nil, nil, err
}
}
}
return metricsConfig, metricsServerMux, nil
}