Path: blob/main/pkg/integrations/v2/app_agent_receiver/config.go
5371 views
package app_agent_receiver12import (3"time"45"github.com/grafana/agent/pkg/integrations/v2"6"github.com/grafana/agent/pkg/integrations/v2/common"7)89const (10// DefaultRateLimitingRPS is the default value of Requests Per Second11// for ratelimiting12DefaultRateLimitingRPS = 10013// DefaultRateLimitingBurstiness is the default burstiness factor of the14// token bucket algorithm15DefaultRateLimitingBurstiness = 5016// DefaultMaxPayloadSize is the max payload size in bytes17DefaultMaxPayloadSize = 5e618)1920// DefaultConfig holds the default configuration of the receiver21var DefaultConfig = Config{22// Default JS agent port2324Server: ServerConfig{25Host: "127.0.0.1",26Port: 12347,27RateLimiting: RateLimitingConfig{28Enabled: true,29RPS: DefaultRateLimitingRPS,30Burstiness: DefaultRateLimitingBurstiness,31},32MaxAllowedPayloadSize: DefaultMaxPayloadSize,33},34LogsLabels: map[string]string{},35LogsSendTimeout: time.Second * 2,36SourceMaps: SourceMapConfig{37DownloadFromOrigins: []string{"*"},38DownloadTimeout: time.Second,39},40}4142// ServerConfig holds the receiver http server configuration43type ServerConfig struct {44Host string `yaml:"host,omitempty"`45Port int `yaml:"port,omitempty"`46CORSAllowedOrigins []string `yaml:"cors_allowed_origins,omitempty"`47RateLimiting RateLimitingConfig `yaml:"rate_limiting,omitempty"`48APIKey string `yaml:"api_key,omitempty"`49MaxAllowedPayloadSize int64 `yaml:"max_allowed_payload_size,omitempty"`50}5152// RateLimitingConfig holds the configuration of the rate limiter53type RateLimitingConfig struct {54Enabled bool `yaml:"enabled,omitempty"`55RPS float64 `yaml:"rps,omitempty"`56Burstiness int `yaml:"burstiness,omitempty"`57}5859// SourceMapFileLocation holds sourcemap location on file system60type SourceMapFileLocation struct {61Path string `yaml:"path"`62MinifiedPathPrefix string `yaml:"minified_path_prefix,omitempty"`63}6465// SourceMapConfig configure source map locations66type SourceMapConfig struct {67Download bool `yaml:"download"`68DownloadFromOrigins []string `yaml:"download_origins,omitempty"`69DownloadTimeout time.Duration `yaml:"download_timeout,omitempty"`70FileSystem []SourceMapFileLocation `yaml:"filesystem,omitempty"`71}7273// Config is the configuration struct of the74// integration75type Config struct {76Common common.MetricsConfig `yaml:",inline"`77Server ServerConfig `yaml:"server,omitempty"`78TracesInstance string `yaml:"traces_instance,omitempty"`79LogsInstance string `yaml:"logs_instance,omitempty"`80LogsLabels map[string]string `yaml:"logs_labels,omitempty"`81LogsSendTimeout time.Duration `yaml:"logs_send_timeout,omitempty"`82SourceMaps SourceMapConfig `yaml:"sourcemaps,omitempty"`83}8485// UnmarshalYAML implements the Unmarshaler interface86func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {87*c = DefaultConfig88c.LogsLabels = make(map[string]string)89type plain Config90return unmarshal((*plain)(c))91}9293// IntegrationName is the name of this integration94var IntegrationName = "app_agent_receiver"9596// ApplyDefaults applies runtime-specific defaults to c.97func (c *Config) ApplyDefaults(globals integrations.Globals) error {98c.Common.ApplyDefaults(globals.SubsystemOpts.Metrics.Autoscrape)99if id, err := c.Identifier(globals); err == nil {100c.Common.InstanceKey = &id101}102return nil103}104105// Name returns the name of the integration that this config represents106func (c *Config) Name() string { return IntegrationName }107108// Identifier uniquely identifies the app agent receiver integration109func (c *Config) Identifier(globals integrations.Globals) (string, error) {110if c.Common.InstanceKey != nil {111return *c.Common.InstanceKey, nil112}113return globals.AgentIdentifier, nil114}115116117