Files
ab99a1bb2e Use the standard errors package to create, wrap, and handle errors (#2955)
* Standardise error formatting using standard library errors package

* Standardise improve non-idiomatic error messages

* Make github.com/pkg/errors an indirect dependency

Co-authored-by: A. Stoewer <[email protected]>
2023-09-26 17:39:47 +10:00

55 lines
1.0 KiB
Go

package forwarder
import (
"errors"
"fmt"
"github.com/grafana/tempo/modules/distributor/forwarder/otlpgrpc"
)
const (
OTLPGRPCBackend = "otlpgrpc"
)
type Config struct {
Name string `yaml:"name"`
Backend string `yaml:"backend"`
OTLPGRPC otlpgrpc.Config `yaml:"otlpgrpc"`
Filter FilterConfig `yaml:"filter"`
}
type FilterConfig struct {
Traces TraceFiltersConfig `yaml:"traces"`
}
type TraceFiltersConfig struct {
SpanConditions []string `yaml:"span"`
SpanEventConditions []string `yaml:"spanevent"`
}
func (cfg *Config) Validate() error {
if cfg.Name == "" {
return errors.New("name is empty")
}
switch cfg.Backend {
case OTLPGRPCBackend:
return cfg.OTLPGRPC.Validate()
default:
}
return fmt.Errorf("%s backend is not supported", cfg.Backend)
}
type ConfigList []Config
func (cfgs ConfigList) Validate() error {
for i, cfg := range cfgs {
if err := cfg.Validate(); err != nil {
return fmt.Errorf("failed to validate config at index=%d: %w", i, err)
}
}
return nil
}