mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
3e2894b6fa
* 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>
49 lines
1.2 KiB
Go
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
|
|
}
|