Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/v2/app_agent_receiver/config.go
5371 views
1
package app_agent_receiver
2
3
import (
4
"time"
5
6
"github.com/grafana/agent/pkg/integrations/v2"
7
"github.com/grafana/agent/pkg/integrations/v2/common"
8
)
9
10
const (
11
// DefaultRateLimitingRPS is the default value of Requests Per Second
12
// for ratelimiting
13
DefaultRateLimitingRPS = 100
14
// DefaultRateLimitingBurstiness is the default burstiness factor of the
15
// token bucket algorithm
16
DefaultRateLimitingBurstiness = 50
17
// DefaultMaxPayloadSize is the max payload size in bytes
18
DefaultMaxPayloadSize = 5e6
19
)
20
21
// DefaultConfig holds the default configuration of the receiver
22
var DefaultConfig = Config{
23
// Default JS agent port
24
25
Server: ServerConfig{
26
Host: "127.0.0.1",
27
Port: 12347,
28
RateLimiting: RateLimitingConfig{
29
Enabled: true,
30
RPS: DefaultRateLimitingRPS,
31
Burstiness: DefaultRateLimitingBurstiness,
32
},
33
MaxAllowedPayloadSize: DefaultMaxPayloadSize,
34
},
35
LogsLabels: map[string]string{},
36
LogsSendTimeout: time.Second * 2,
37
SourceMaps: SourceMapConfig{
38
DownloadFromOrigins: []string{"*"},
39
DownloadTimeout: time.Second,
40
},
41
}
42
43
// ServerConfig holds the receiver http server configuration
44
type ServerConfig struct {
45
Host string `yaml:"host,omitempty"`
46
Port int `yaml:"port,omitempty"`
47
CORSAllowedOrigins []string `yaml:"cors_allowed_origins,omitempty"`
48
RateLimiting RateLimitingConfig `yaml:"rate_limiting,omitempty"`
49
APIKey string `yaml:"api_key,omitempty"`
50
MaxAllowedPayloadSize int64 `yaml:"max_allowed_payload_size,omitempty"`
51
}
52
53
// RateLimitingConfig holds the configuration of the rate limiter
54
type RateLimitingConfig struct {
55
Enabled bool `yaml:"enabled,omitempty"`
56
RPS float64 `yaml:"rps,omitempty"`
57
Burstiness int `yaml:"burstiness,omitempty"`
58
}
59
60
// SourceMapFileLocation holds sourcemap location on file system
61
type SourceMapFileLocation struct {
62
Path string `yaml:"path"`
63
MinifiedPathPrefix string `yaml:"minified_path_prefix,omitempty"`
64
}
65
66
// SourceMapConfig configure source map locations
67
type SourceMapConfig struct {
68
Download bool `yaml:"download"`
69
DownloadFromOrigins []string `yaml:"download_origins,omitempty"`
70
DownloadTimeout time.Duration `yaml:"download_timeout,omitempty"`
71
FileSystem []SourceMapFileLocation `yaml:"filesystem,omitempty"`
72
}
73
74
// Config is the configuration struct of the
75
// integration
76
type Config struct {
77
Common common.MetricsConfig `yaml:",inline"`
78
Server ServerConfig `yaml:"server,omitempty"`
79
TracesInstance string `yaml:"traces_instance,omitempty"`
80
LogsInstance string `yaml:"logs_instance,omitempty"`
81
LogsLabels map[string]string `yaml:"logs_labels,omitempty"`
82
LogsSendTimeout time.Duration `yaml:"logs_send_timeout,omitempty"`
83
SourceMaps SourceMapConfig `yaml:"sourcemaps,omitempty"`
84
}
85
86
// UnmarshalYAML implements the Unmarshaler interface
87
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
88
*c = DefaultConfig
89
c.LogsLabels = make(map[string]string)
90
type plain Config
91
return unmarshal((*plain)(c))
92
}
93
94
// IntegrationName is the name of this integration
95
var IntegrationName = "app_agent_receiver"
96
97
// ApplyDefaults applies runtime-specific defaults to c.
98
func (c *Config) ApplyDefaults(globals integrations.Globals) error {
99
c.Common.ApplyDefaults(globals.SubsystemOpts.Metrics.Autoscrape)
100
if id, err := c.Identifier(globals); err == nil {
101
c.Common.InstanceKey = &id
102
}
103
return nil
104
}
105
106
// Name returns the name of the integration that this config represents
107
func (c *Config) Name() string { return IntegrationName }
108
109
// Identifier uniquely identifies the app agent receiver integration
110
func (c *Config) Identifier(globals integrations.Globals) (string, error) {
111
if c.Common.InstanceKey != nil {
112
return *c.Common.InstanceKey, nil
113
}
114
return globals.AgentIdentifier, nil
115
}
116
117