mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-30 23:22:00 +08:00

### Summary A config package based on https://github.com/open-telemetry/opentelemetry-collector/blob/main/confmap/confmap.go for signoz. #### Related Issues / PR's This is a part of https://github.com/SigNoz/signoz/pull/5710
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"go.opentelemetry.io/collector/confmap"
|
|
)
|
|
|
|
// Provides the configuration for signoz.
|
|
type Provider interface {
|
|
// Get returns the configuration, or error otherwise.
|
|
Get(ctx context.Context) (*Config, error)
|
|
}
|
|
|
|
type provider struct {
|
|
resolver *confmap.Resolver
|
|
}
|
|
|
|
// ProviderSettings are the settings to configure the behavior of the Provider.
|
|
type ProviderSettings struct {
|
|
// ResolverSettings are the settings to configure the behavior of the confmap.Resolver.
|
|
ResolverSettings confmap.ResolverSettings
|
|
}
|
|
|
|
// NewProvider returns a new Provider that provides the entire configuration.
|
|
// See https://github.com/open-telemetry/opentelemetry-collector/blob/main/otelcol/configprovider.go for
|
|
// more details
|
|
func NewProvider(settings ProviderSettings) (Provider, error) {
|
|
resolver, err := confmap.NewResolver(settings.ResolverSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &provider{
|
|
resolver: resolver,
|
|
}, nil
|
|
}
|
|
|
|
func (provider *provider) Get(ctx context.Context) (*Config, error) {
|
|
conf, err := provider.resolver.Resolve(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot resolve configuration: %w", err)
|
|
}
|
|
|
|
config, err := unmarshal(conf)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot unmarshal configuration: %w", err)
|
|
}
|
|
|
|
return config, nil
|
|
}
|