-
Notifications
You must be signed in to change notification settings - Fork 493
/
config.go
123 lines (101 loc) · 4.1 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package frontend
import (
"flag"
"time"
"net/http"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/grafana/tempo/modules/frontend/transport"
v1 "github.com/grafana/tempo/modules/frontend/v1"
v2 "github.com/grafana/tempo/modules/frontend/v2"
"github.com/grafana/tempo/pkg/usagestats"
"github.com/grafana/tempo/pkg/util"
)
var (
statWorkerConcurrency = usagestats.NewInt("frontend_worker_concurrency")
statVersion = usagestats.NewString("frontend_version")
)
type Config struct {
Config CombinedFrontendConfig `yaml:",inline"`
MaxRetries int `yaml:"max_retries,omitempty"`
QueryShards int `yaml:"query_shards,omitempty"`
TolerateFailedBlocks int `yaml:"tolerate_failed_blocks,omitempty"`
Search SearchConfig `yaml:"search"`
}
type SearchConfig struct {
Sharder SearchSharderConfig `yaml:",inline"`
}
func (cfg *Config) RegisterFlagsAndApplyDefaults(prefix string, f *flag.FlagSet) {
cfg.Config.DownstreamURL = ""
cfg.Config.Handler.LogQueriesLongerThan = 0
cfg.Config.FrontendV1.MaxOutstandingPerTenant = 100
cfg.MaxRetries = 2
cfg.QueryShards = 20
cfg.TolerateFailedBlocks = 0
cfg.Search = SearchConfig{
Sharder: SearchSharderConfig{
QueryBackendAfter: 15 * time.Minute,
QueryIngestersUntil: time.Hour,
DefaultLimit: 20,
MaxLimit: 0,
MaxDuration: 61 * time.Minute,
ConcurrentRequests: defaultConcurrentRequests,
TargetBytesPerRequest: defaultTargetBytesPerRequest,
},
}
}
type CortexNoQuerierLimits struct{}
var _ v1.Limits = (*CortexNoQuerierLimits)(nil)
func (CortexNoQuerierLimits) MaxQueriersPerUser(user string) int { return 0 }
// This struct combines several configuration options together to preserve backwards compatibility.
type CombinedFrontendConfig struct {
Handler transport.HandlerConfig `yaml:",inline"`
FrontendV1 v1.Config `yaml:",inline"`
FrontendV2 v2.Config `yaml:",inline"`
DownstreamURL string `yaml:"downstream_url"`
}
func (cfg *CombinedFrontendConfig) RegisterFlags(f *flag.FlagSet) {
cfg.Handler.RegisterFlags(f)
cfg.FrontendV1.RegisterFlags(f)
cfg.FrontendV2.RegisterFlags(f)
f.StringVar(&cfg.DownstreamURL, "frontend.downstream-url", "", "URL of downstream Prometheus.")
}
// InitFrontend initializes frontend (either V1 -- without scheduler, or V2 -- with scheduler) or no frontend at
// all if downstream Prometheus URL is used instead.
//
// Returned RoundTripper can be wrapped in more round-tripper middlewares, and then eventually registered
// into HTTP server using the Handler from this package. Returned RoundTripper is always non-nil
// (if there are no errors), and it uses the returned frontend (if any).
func InitFrontend(cfg CombinedFrontendConfig, limits v1.Limits, grpcListenPort int, log log.Logger, reg prometheus.Registerer) (http.RoundTripper, *v1.Frontend, *v2.Frontend, error) {
switch {
case cfg.DownstreamURL != "":
// If the user has specified a downstream Prometheus, then we should use that.
rt, err := NewDownstreamRoundTripper(cfg.DownstreamURL, http.DefaultTransport)
return rt, nil, nil, err
case cfg.FrontendV2.SchedulerAddress != "":
statVersion.Set("v2")
statWorkerConcurrency.Set(int64(cfg.FrontendV2.WorkerConcurrency))
// If query-scheduler address is configured, use Frontend.
if cfg.FrontendV2.Addr == "" {
addr, err := util.GetFirstAddressOf(cfg.FrontendV2.InfNames)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to get frontend address")
}
cfg.FrontendV2.Addr = addr
}
if cfg.FrontendV2.Port == 0 {
cfg.FrontendV2.Port = grpcListenPort
}
fr, err := v2.NewFrontend(cfg.FrontendV2, log, reg)
return transport.AdaptGrpcRoundTripperToHTTPRoundTripper(fr), nil, fr, err
default:
statVersion.Set("v1")
// No scheduler = use original frontend.
fr, err := v1.New(cfg.FrontendV1, limits, log, reg)
if err != nil {
return nil, nil, nil, err
}
return transport.AdaptGrpcRoundTripperToHTTPRoundTripper(fr), fr, nil, nil
}
}