config

package
v1.39.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 21 Imported by: 4

Documentation

Index

Constants

View Source
const DefaultLogLevel = "info"
View Source
const OtelTracerName = "go-feature-flag"

Variables

View Source
var DefaultExporter = struct {
	Format                  string
	LogFormat               string
	FileName                string
	CsvFormat               string
	FlushInterval           time.Duration
	MaxEventInMemory        int64
	ParquetCompressionCodec string
	LogLevel                string
}{
	Format:    "JSON",
	LogFormat: "[{{ .FormattedDate}}] user=\"{{ .UserKey}}\", flag=\"{{ .Key}}\", value=\"{{ .Value}}\"",
	FileName:  "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}",
	CsvFormat: "{{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};" +
		"{{ .Value}};{{ .Default}};{{ .Source}}\n",
	FlushInterval:           60000 * time.Millisecond,
	MaxEventInMemory:        100000,
	ParquetCompressionCodec: parquet.CompressionCodec_SNAPPY.String(),
	LogLevel:                DefaultLogLevel,
}
View Source
var DefaultRetriever = struct {
	Timeout    time.Duration
	HTTPMethod string
	GitBranch  string
}{
	Timeout:    10 * time.Second,
	HTTPMethod: http.MethodGet,
	GitBranch:  "main",
}

Functions

This section is empty.

Types

type APIKeys added in v1.28.0

type APIKeys struct {
	Admin      []string `mapstructure:"admin" koanf:"admin"`
	Evaluation []string `mapstructure:"evaluation" koanf:"evaluation"`
}

APIKeys is a struct to store the API keys for the different endpoints

type Config

type Config struct {
	// ListenPort (optional) is the port we are using to start the proxy
	ListenPort int `mapstructure:"listen" koanf:"listen"`

	// HideBanner (optional) if true, we don't display the go-feature-flag relay proxy banner
	HideBanner bool `mapstructure:"hideBanner" koanf:"hidebanner"`

	// Debug (optional) if true, go-feature-flag relay proxy will run on debug mode, with more logs and custom responses.
	// It will also start the pprof endpoints on the same port as the monitoring.
	// Default: false
	Debug bool `mapstructure:"debug" koanf:"debug"`

	// EnablePprof (optional) if true, go-feature-flag relay proxy will start
	// the pprof endpoints on the same port as the monitoring.
	// Default: false
	EnablePprof bool `mapstructure:"enablePprof" koanf:"enablepprof"`

	// EnableSwagger (optional) to have access to the swagger
	EnableSwagger bool `mapstructure:"enableSwagger" koanf:"enableswagger"`

	// Host should be set if you are using swagger (default is localhost)
	Host string `mapstructure:"host" koanf:"host"`

	// LogLevel (optional) sets the verbosity for logging,
	// Possible values: debug, info, warn, error, dpanic, panic, fatal
	// If level debug go-feature-flag relay proxy will run on debug mode, with more logs and custom responses
	// Default: debug
	LogLevel string `mapstructure:"logLevel" koanf:"loglevel"`

	// LogFormat (optional) sets the log message format
	// Possible values: json, logfmt
	// Default: json
	LogFormat string `mapstructure:"logFormat" koanf:"logformat"`

	// PollingInterval (optional) Poll every X time
	// The minimum possible is 1 second
	// Default: 60 seconds
	PollingInterval int `mapstructure:"pollingInterval" koanf:"pollinginterval"`

	// EnablePollingJitter (optional) set to true if you want to avoid having true periodicity when
	// retrieving your flags. It is useful to avoid having spike on your flag configuration storage
	// in case your application is starting multiple instance at the same time.
	// We ensure a deviation that is maximum + or - 10% of your polling interval.
	// Default: false
	EnablePollingJitter bool `mapstructure:"enablePollingJitter" koanf:"enablepollingjitter"`

	// DisableNotifierOnInit (optional) set to true if you do not want to call any notifier
	// when the flags are loaded.
	// This is useful if you do not want a Slack/Webhook notification saying that
	// the flags have been added every time you start the application.
	// Default is set to false for backward compatibility.
	// Default: false
	DisableNotifierOnInit bool `mapstructure:"DisableNotifierOnInit" koanf:"DisableNotifierOnInit"`

	// FileFormat (optional) is the format of the file to retrieve (available YAML, TOML and JSON)
	// Default: YAML
	FileFormat string `mapstructure:"fileFormat" koanf:"fileformat"`

	// StartWithRetrieverError (optional) If true, the relay proxy will start even if we did not get any flags from
	// the retriever. It will serve only default values until the retriever returns the flags.
	// The init method will not return any error if the flag file is unreachable.
	// Default: false
	StartWithRetrieverError bool `mapstructure:"startWithRetrieverError" koanf:"startwithretrievererror"`

	// Retriever is the configuration on how to retrieve the file
	Retriever *RetrieverConf `mapstructure:"retriever" koanf:"retriever"`

	// Retrievers is the exact same things than Retriever but allows to give more than 1 retriever at the time.
	// We are dealing with config files in order, if you have the same flag name in multiple files it will be override
	// based of the order of the retrievers in the slice.
	//
	// Note: If both Retriever and Retrievers are set, we will start by calling the Retriever and,
	// after we will use the order of Retrievers.
	Retrievers *[]RetrieverConf `mapstructure:"retrievers" koanf:"retrievers"`

	// Exporter is the configuration on how to export data
	Exporter *ExporterConf `mapstructure:"exporter" koanf:"exporter"`

	// Notifiers is the configuration on where to notify a flag change
	Notifiers []NotifierConf `mapstructure:"notifier" koanf:"notifier"`

	// RestAPITimeout is the timeout on the API.
	RestAPITimeout int `mapstructure:"restApiTimeout" koanf:"restapitimeout"`

	// Version is the version of the relay-proxy
	Version string `mapstructure:"version" koanf:"version"`

	// Deprecated: use AuthorizedKeys instead
	// APIKeys list of API keys that authorized to use endpoints
	APIKeys []string `mapstructure:"apiKeys" koanf:"apikeys"`

	// AuthorizedKeys list of API keys that authorized to use endpoints
	AuthorizedKeys APIKeys `mapstructure:"authorizedKeys" koanf:"authorizedkeys"`

	// StartAsAwsLambda (optional) if true, the relay proxy will start ready to be launched as AWS Lambda
	StartAsAwsLambda bool `mapstructure:"startAsAwsLambda" koanf:"startasawslambda"`

	// AwsLambdaAdapter (optional) is the adapter to use when the relay proxy is started as an AWS Lambda.
	// Possible values are "APIGatewayV1", "APIGatewayV2" and "ALB"
	// Default: "APIGatewayV2"
	AwsLambdaAdapter string `mapstructure:"awsLambdaAdapter" koanf:"awslambdaadapter"`

	// EvaluationContextEnrichment (optional) will be merged with the evaluation context sent during the evaluation.
	// It is useful to add common attributes to all the evaluations, such as a server version, environment, ...
	//
	// All those fields will be included in the custom attributes of the evaluation context,
	// if in the evaluation context you have a field with the same name,
	// it will be overridden by the evaluationContextEnrichment.
	// Default: nil
	EvaluationContextEnrichment map[string]interface{} `mapstructure:"evaluationContextEnrichment" koanf:"evaluationcontextenrichment"` //nolint: lll

	// OpenTelemetryOtlpEndpoint (optional) is the endpoint of the OpenTelemetry collector
	// Default: ""
	OpenTelemetryOtlpEndpoint string `mapstructure:"openTelemetryOtlpEndpoint" koanf:"opentelemetryotlpendpoint"`

	// MonitoringPort (optional) is the port we are using to expose the metrics and healthchecks
	// If not set we will use the same port as the proxy
	MonitoringPort int `mapstructure:"monitoringPort" koanf:"monitoringport"`

	// PersistentFlagConfigurationFile (optional) if set GO Feature Flag will store flags configuration in this file
	//  to be able to serve the flags even if none of the retrievers is available during starting time.
	//
	// By default, the flag configuration is not persisted and stays on the retriever system. By setting a file here,
	// you ensure that GO Feature Flag will always start with a configuration but which can be out-dated.
	PersistentFlagConfigurationFile string `mapstructure:"persistentFlagConfigurationFile" koanf:"persistentflagconfigurationfile"` //nolint: lll

	// OtelConfig is the configuration for the OpenTelemetry part of the relay proxy
	OtelConfig OpenTelemetryConfiguration `mapstructure:"otel" koanf:"otel"`

	// JaegerConfig is the configuration for the Jaeger sampling of the relay proxy
	JaegerConfig JaegerSamplerConfiguration `mapstructure:"jaeger" koanf:"jaeger"`
	// contains filtered or unexported fields
}

func New added in v1.8.1

func New(flagSet *pflag.FlagSet, log *zap.Logger, version string) (*Config, error)

New is reading the configuration file

func (*Config) APIKeyExists added in v1.7.0

func (c *Config) APIKeyExists(apiKey string) bool

APIKeyExists is checking if an API Key exist in the relay proxy configuration

func (*Config) APIKeysAdminExists added in v1.28.0

func (c *Config) APIKeysAdminExists(apiKey string) bool

APIKeysAdminExists is checking if an admin API Key exist in the relay proxy configuration

func (*Config) IsDebugEnabled added in v1.30.0

func (c *Config) IsDebugEnabled() bool

func (*Config) IsValid

func (c *Config) IsValid() error

IsValid contains all the validation of the configuration.

func (*Config) ZapLogLevel added in v1.30.0

func (c *Config) ZapLogLevel() zapcore.Level

type ExporterConf

type ExporterConf struct {
	Kind                    ExporterKind           `mapstructure:"kind" koanf:"kind"`
	OutputDir               string                 `mapstructure:"outputDir" koanf:"outputdir"`
	Format                  string                 `mapstructure:"format" koanf:"format"`
	Filename                string                 `mapstructure:"filename" koanf:"filename"`
	CsvTemplate             string                 `mapstructure:"csvTemplate" koanf:"csvtemplate"`
	Bucket                  string                 `mapstructure:"bucket" koanf:"bucket"`
	Path                    string                 `mapstructure:"path" koanf:"path"`
	EndpointURL             string                 `mapstructure:"endpointUrl" koanf:"endpointurl"`
	Secret                  string                 `mapstructure:"secret" koanf:"secret"`
	Meta                    map[string]string      `mapstructure:"meta" koanf:"meta"`
	LogFormat               string                 `mapstructure:"logFormat" koanf:"logformat"`
	FlushInterval           int64                  `mapstructure:"flushInterval" koanf:"flushinterval"`
	MaxEventInMemory        int64                  `mapstructure:"maxEventInMemory" koanf:"maxeventinmemory"`
	ParquetCompressionCodec string                 `mapstructure:"parquetCompressionCodec" koanf:"parquetcompressioncodec"`
	Headers                 map[string][]string    `mapstructure:"headers" koanf:"headers"`
	QueueURL                string                 `mapstructure:"queueUrl" koanf:"queueurl"`
	Kafka                   kafkaexporter.Settings `mapstructure:"kafka" koanf:"kafka"`
	ProjectID               string                 `mapstructure:"projectID" koanf:"projectid"`
	Topic                   string                 `mapstructure:"topic" koanf:"topic"`
	StreamArn               string                 `mapstructure:"streamArn" koanf:"streamarn"`
	StreamName              string                 `mapstructure:"streamName" koanf:"streamname"`
	AccountName             string                 `mapstructure:"accountName" koanf:"accountname"`
	AccountKey              string                 `mapstructure:"accountKey" koanf:"accountkey"`
	Container               string                 `mapstructure:"container" koanf:"container"`
}

ExporterConf contains all the field to configure an exporter

func (*ExporterConf) IsValid

func (c *ExporterConf) IsValid() error

type ExporterKind

type ExporterKind string
const (
	FileExporter          ExporterKind = "file"
	WebhookExporter       ExporterKind = "webhook"
	LogExporter           ExporterKind = "log"
	S3Exporter            ExporterKind = "s3"
	KinesisExporter       ExporterKind = "kinesis"
	GoogleStorageExporter ExporterKind = "googleStorage"
	SQSExporter           ExporterKind = "sqs"
	KafkaExporter         ExporterKind = "kafka"
	PubSubExporter        ExporterKind = "pubsub"
	AzureExporter         ExporterKind = "azureBlobStorage"
)

func (ExporterKind) IsValid

func (r ExporterKind) IsValid() error

IsValid is checking if the value is part of the enum

type JaegerSamplerConfiguration added in v1.37.0

type JaegerSamplerConfiguration struct {
	Sampler struct {
		Manager struct {
			Host struct {
				Port string `mapstructure:"port" koanf:"port"`
			} `mapstructure:"host" koanf:"host"`
		} `mapstructure:"manager" koanf:"manager"`
		Refresh struct {
			Interval string `mapstructure:"interval" koanf:"interval"`
		} `mapstructure:"refresh" koanf:"refresh"`
		Max struct {
			Operations int `mapstructure:"operations" koanf:"operations"`
		} `mapstructure:"max" koanf:"max"`
	} `mapstructure:"sampler" koanf:"sampler"`
}

JaegerSamplerConfiguration is the configuration object to configure the sampling. Most of the time this configuration is set using environment variables.

type NotifierConf

type NotifierConf struct {
	Kind NotifierKind `mapstructure:"kind" koanf:"kind"`
	// Deprecated: Use WebhookURL instead
	SlackWebhookURL string              `mapstructure:"slackWebhookUrl" koanf:"slackwebhookurl"`
	EndpointURL     string              `mapstructure:"endpointUrl" koanf:"endpointurl"`
	Secret          string              `mapstructure:"secret" koanf:"secret"`
	Meta            map[string]string   `mapstructure:"meta" koanf:"meta"`
	Headers         map[string][]string `mapstructure:"headers" koanf:"headers"`
	WebhookURL      string              `mapstructure:"webhookUrl" koanf:"webhookurl"`
}

func (*NotifierConf) IsValid

func (c *NotifierConf) IsValid() error

type NotifierKind

type NotifierKind string
const (
	SlackNotifier          NotifierKind = "slack"
	MicrosoftTeamsNotifier NotifierKind = "microsoftteams"
	WebhookNotifier        NotifierKind = "webhook"
	DiscordNotifier        NotifierKind = "discord"
)

func (NotifierKind) IsValid

func (r NotifierKind) IsValid() error

IsValid is checking if the value is part of the enum

type OpenTelemetryConfiguration added in v1.37.0

type OpenTelemetryConfiguration struct {
	SDK struct {
		Disabled bool `mapstructure:"disabled" koanf:"disabled"`
	} `mapstructure:"sdk" koanf:"sdk"`
	Exporter OtelExporter `mapstructure:"exporter" koanf:"exporter"`
	Service  struct {
		Name string `mapstructure:"name" koanf:"name"`
	} `mapstructure:"service" koanf:"service"`
	Traces struct {
		Sampler string `mapstructure:"sampler" koanf:"sampler"`
	} `mapstructure:"traces" koanf:"traces"`
	Resource OtelResource `mapstructure:"resource" koanf:"resource"`
}

OpenTelemetryConfiguration is the configuration for the OpenTelemetry part of the relay proxy It is used to configure the OpenTelemetry SDK and the OpenTelemetry Exporter Most of the time this configuration is set using environment variables.

type OtelExporter added in v1.38.0

type OtelExporter struct {
	Otlp OtelExporterOtlp `mapstructure:"otlp" koanf:"otlp"`
}

type OtelExporterOtlp added in v1.38.0

type OtelExporterOtlp struct {
	Endpoint string `mapstructure:"endpoint" koanf:"endpoint"`
	Protocol string `mapstructure:"protocol" koanf:"protocol"`
}

type OtelResource added in v1.38.0

type OtelResource struct {
	Attributes map[string]string `mapstructure:"attributes" koanf:"attributes"`
}

type RetrieverConf

type RetrieverConf struct {
	Kind           RetrieverKind `mapstructure:"kind" koanf:"kind"`
	RepositorySlug string        `mapstructure:"repositorySlug" koanf:"repositoryslug"`
	Branch         string        `mapstructure:"branch" koanf:"branch"`
	Path           string        `mapstructure:"path" koanf:"path"`
	// Deprecated: Please use AuthToken instead
	GithubToken  string              `mapstructure:"githubToken" koanf:"githubtoken"`
	URL          string              `mapstructure:"url" koanf:"url"`
	Timeout      int64               `mapstructure:"timeout" koanf:"timeout"`
	HTTPMethod   string              `mapstructure:"method" koanf:"method"`
	HTTPBody     string              `mapstructure:"body" koanf:"body"`
	HTTPHeaders  map[string][]string `mapstructure:"headers" koanf:"headers"`
	Bucket       string              `mapstructure:"bucket" koanf:"bucket"`
	Object       string              `mapstructure:"object" koanf:"object"`
	Item         string              `mapstructure:"item" koanf:"item"`
	Namespace    string              `mapstructure:"namespace" koanf:"namespace"`
	ConfigMap    string              `mapstructure:"configmap" koanf:"configmap"`
	Key          string              `mapstructure:"key" koanf:"key"`
	BaseURL      string              `mapstructure:"baseUrl" koanf:"baseurl"`
	AuthToken    string              `mapstructure:"token" koanf:"token"`
	URI          string              `mapstructure:"uri" koanf:"uri"`
	Database     string              `mapstructure:"database" koanf:"database"`
	Collection   string              `mapstructure:"collection" koanf:"collection"`
	RedisOptions *redis.Options      `mapstructure:"redisOptions" koanf:"redisOptions"`
	RedisPrefix  string              `mapstructure:"redisPrefix" koanf:"redisPrefix"`
	AccountName  string              `mapstructure:"accountName" koanf:"accountname"`
	AccountKey   string              `mapstructure:"accountKey" koanf:"accountkey"`
	Container    string              `mapstructure:"container" koanf:"container"`
}

RetrieverConf contains all the field to configure a retriever

func (*RetrieverConf) IsValid

func (c *RetrieverConf) IsValid() error

IsValid validate the configuration of the retriever nolint:gocognit

type RetrieverKind

type RetrieverKind string

RetrieverKind is an enum containing all accepted Retriever kind

const (
	HTTPRetriever          RetrieverKind = "http"
	GitHubRetriever        RetrieverKind = "github"
	GitlabRetriever        RetrieverKind = "gitlab"
	S3Retriever            RetrieverKind = "s3"
	FileRetriever          RetrieverKind = "file"
	GoogleStorageRetriever RetrieverKind = "googleStorage"
	KubernetesRetriever    RetrieverKind = "configmap"
	MongoDBRetriever       RetrieverKind = "mongodb"
	RedisRetriever         RetrieverKind = "redis"
	BitbucketRetriever     RetrieverKind = "bitbucket"
	AzBlobStorageRetriever RetrieverKind = "azureBlobStorage"
)

func (RetrieverKind) IsValid

func (r RetrieverKind) IsValid() error

IsValid is checking if the value is part of the enum

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL