mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
d19e870c17
* fix: panic when disable metrics is true Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * refactor: update otlp packages Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * update bunch of deps Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * target infos Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Co-authored-by: Chip Zoller <chipzoller@gmail.com>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package metrics
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/go-logr/logr"
|
|
"github.com/kyverno/kyverno/pkg/config"
|
|
"go.opentelemetry.io/otel/metric"
|
|
"go.opentelemetry.io/otel/metric/global"
|
|
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
|
|
"k8s.io/client-go/kubernetes"
|
|
)
|
|
|
|
func InitMetrics(
|
|
ctx context.Context,
|
|
disableMetricsExport bool,
|
|
otel string,
|
|
metricsAddr string,
|
|
otelCollector string,
|
|
metricsConfiguration config.MetricsConfiguration,
|
|
transportCreds string,
|
|
kubeClient kubernetes.Interface,
|
|
logger logr.Logger,
|
|
) (MetricsConfigManager, *http.ServeMux, *sdkmetric.MeterProvider, error) {
|
|
var err error
|
|
var metricsServerMux *http.ServeMux
|
|
if !disableMetricsExport {
|
|
var meterProvider metric.MeterProvider
|
|
if otel == "grpc" {
|
|
endpoint := otelCollector + metricsAddr
|
|
meterProvider, err = NewOTLPGRPCConfig(
|
|
ctx,
|
|
endpoint,
|
|
transportCreds,
|
|
kubeClient,
|
|
logger,
|
|
)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
} else if otel == "prometheus" {
|
|
meterProvider, metricsServerMux, err = NewPrometheusConfig(ctx, logger)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
}
|
|
if meterProvider != nil {
|
|
global.SetMeterProvider(meterProvider)
|
|
}
|
|
}
|
|
metricsConfig := MetricsConfig{
|
|
Log: logger,
|
|
config: metricsConfiguration,
|
|
}
|
|
err = metricsConfig.initializeMetrics(global.MeterProvider())
|
|
if err != nil {
|
|
logger.Error(err, "Failed initializing metrics")
|
|
return nil, nil, nil, err
|
|
}
|
|
return &metricsConfig, metricsServerMux, nil, nil
|
|
}
|