mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:47:33 +00:00
feat: provide metrics endpoint (#3902)
* feat: provide metrics endpoint * config * enable otel metrics by default Co-authored-by: Florian Forster <florian@caos.ch>
This commit is contained in:
@@ -1,65 +1,30 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/metrics"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/metrics/otel"
|
||||
)
|
||||
|
||||
type MetricsConfig struct {
|
||||
type Config struct {
|
||||
Type string
|
||||
Config metrics.Config
|
||||
Config map[string]interface{} `mapstructure:",remain"`
|
||||
}
|
||||
|
||||
var meter = map[string]func() metrics.Config{
|
||||
"otel": func() metrics.Config { return &otel.Config{} },
|
||||
"none": func() metrics.Config { return &NoMetrics{} },
|
||||
"": func() metrics.Config { return &NoMetrics{} },
|
||||
var meter = map[string]func(map[string]interface{}) error{
|
||||
"otel": otel.NewTracerFromConfig,
|
||||
"none": NoMetrics,
|
||||
"": NoMetrics,
|
||||
}
|
||||
|
||||
func (c *MetricsConfig) UnmarshalJSON(data []byte) error {
|
||||
var rc struct {
|
||||
Type string
|
||||
Config json.RawMessage
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &rc); err != nil {
|
||||
return errors.ThrowInternal(err, "METER-4M9so", "error parsing config")
|
||||
}
|
||||
|
||||
c.Type = rc.Type
|
||||
|
||||
var err error
|
||||
c.Config, err = newMetricsConfig(c.Type, rc.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Config.NewMetrics()
|
||||
}
|
||||
|
||||
func newMetricsConfig(tracerType string, configData []byte) (metrics.Config, error) {
|
||||
t, ok := meter[tracerType]
|
||||
func (c *Config) NewMeter() error {
|
||||
t, ok := meter[c.Type]
|
||||
if !ok {
|
||||
return nil, errors.ThrowInternalf(nil, "METER-3M0ps", "config type %s not supported", tracerType)
|
||||
return errors.ThrowInternalf(nil, "METER-Dfqsx", "config type %s not supported", c.Type)
|
||||
}
|
||||
|
||||
metricsConfig := t()
|
||||
if len(configData) == 0 {
|
||||
return metricsConfig, nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(configData, metricsConfig); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "METER-4M9sf", "Could not read config: %v")
|
||||
}
|
||||
|
||||
return metricsConfig, nil
|
||||
return t(c.Config)
|
||||
}
|
||||
|
||||
type NoMetrics struct{}
|
||||
|
||||
func (_ *NoMetrics) NewMetrics() error {
|
||||
func NoMetrics(_ map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user