• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blind-oracle / cortex-tenant / 14759730518

30 Apr 2025 04:28PM UTC coverage: 68.056%. Remained the same
14759730518

Pull #87

github

seapasulli
update schema validation to include annotations
Pull Request #87: Expose annotations for service

245 of 360 relevant lines covered (68.06%)

4.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.27
/config.go
1
package main
2

3
import (
4
        "fmt"
5
        "os"
6
        "time"
7

8
        "github.com/caarlos0/env/v8"
9
        "github.com/pkg/errors"
10
        fhu "github.com/valyala/fasthttp/fasthttputil"
11
        "gopkg.in/yaml.v2"
12
)
13

14
type config struct {
15
        Listen               string `env:"CT_LISTEN"`
16
        ListenPprof          string `yaml:"listen_pprof" env:"CT_LISTEN_PPROF"`
17
        ListenMetricsAddress string `yaml:"listen_metrics_address" env:"CT_LISTEN_METRICS_ADDRESS"`
18
        MetricsIncludeTenant bool   `yaml:"metrics_include_tenant" env:"CT_METRICS_INCLUDE_TENANT"`
19

20
        Target     string `env:"CT_TARGET"`
21
        EnableIPv6 bool   `yaml:"enable_ipv6" env:"CT_ENABLE_IPV6"`
22

23
        LogLevel          string        `yaml:"log_level" env:"CT_LOG_LEVEL"`
24
        Timeout           time.Duration `env:"CT_TIMEOUT"`
25
        TimeoutShutdown   time.Duration `yaml:"timeout_shutdown" env:"CT_TIMEOUT_SHUTDOWN"`
26
        Concurrency       int           `env:"CT_CONCURRENCY"`
27
        Metadata          bool          `env:"CT_METADATA"`
28
        LogResponseErrors bool          `yaml:"log_response_errors" env:"CT_LOG_RESPONSE_ERRORS"`
29
        MaxConnDuration   time.Duration `yaml:"max_connection_duration" env:"CT_MAX_CONN_DURATION"`
30
        MaxConnsPerHost   int           `env:"CT_MAX_CONNS_PER_HOST" yaml:"max_conns_per_host"`
31

32
        Auth struct {
33
                Egress struct {
34
                        Username string `env:"CT_AUTH_EGRESS_USERNAME"`
35
                        Password string `env:"CT_AUTH_EGRESS_PASSWORD"`
36
                }
37
        }
38

39
        Tenant struct {
40
                Label              string   `env:"CT_TENANT_LABEL"`
41
                LabelList          []string `yaml:"label_list" env:"CT_TENANT_LABEL_LIST" envSeparator:","`
42
                Prefix             string   `yaml:"prefix" env:"CT_TENANT_PREFIX"`
43
                PrefixPreferSource bool     `yaml:"prefix_prefer_source" env:"CT_TENANT_PREFIX_PREFER_SOURCE"`
44
                LabelRemove        bool     `yaml:"label_remove" env:"CT_TENANT_LABEL_REMOVE"`
45
                Header             string   `env:"CT_TENANT_HEADER"`
46
                Default            string   `env:"CT_TENANT_DEFAULT"`
47
                AcceptAll          bool     `yaml:"accept_all" env:"CT_TENANT_ACCEPT_ALL"`
48
        }
49

50
        pipeIn  *fhu.InmemoryListener
51
        pipeOut *fhu.InmemoryListener
52
}
53

54
func configLoad(file string) (*config, error) {
9✔
55
        cfg := &config{}
9✔
56

9✔
57
        if file != "" {
18✔
58
                y, err := os.ReadFile(file)
9✔
59
                if err != nil {
9✔
60
                        return nil, errors.Wrap(err, "Unable to read config")
×
61
                }
×
62

63
                if err := yaml.UnmarshalStrict(y, cfg); err != nil {
9✔
64
                        return nil, errors.Wrap(err, "Unable to parse config")
×
65
                }
×
66
        }
67

68
        if err := env.Parse(cfg); err != nil {
9✔
69
                return nil, errors.Wrap(err, "Unable to parse env vars")
×
70
        }
×
71

72
        if cfg.Listen == "" {
9✔
73
                cfg.Listen = "127.0.0.1:8081"
×
74
        }
×
75

76
        if cfg.ListenMetricsAddress == "" {
16✔
77
                cfg.ListenMetricsAddress = "0.0.0.0:9090"
7✔
78
        }
7✔
79

80
        if cfg.LogLevel == "" {
9✔
81
                cfg.LogLevel = "warn"
×
82
        }
×
83

84
        if cfg.Target == "" {
9✔
85
                cfg.Target = "127.0.0.1:9090"
×
86
        }
×
87

88
        if cfg.Timeout == 0 {
9✔
89
                cfg.Timeout = 10 * time.Second
×
90
        }
×
91

92
        if cfg.Concurrency == 0 {
16✔
93
                cfg.Concurrency = 512
7✔
94
        }
7✔
95

96
        if cfg.Tenant.Header == "" {
16✔
97
                cfg.Tenant.Header = "X-Scope-OrgID"
7✔
98
        }
7✔
99

100
        if cfg.Tenant.Label == "" {
16✔
101
                cfg.Tenant.Label = "__tenant__"
7✔
102
        }
7✔
103

104
        // Default to the Label if list is empty
105
        if len(cfg.Tenant.LabelList) == 0 {
9✔
106
                cfg.Tenant.LabelList = append(cfg.Tenant.LabelList, cfg.Tenant.Label)
×
107
        }
×
108

109
        if cfg.Auth.Egress.Username != "" {
11✔
110
                if cfg.Auth.Egress.Password == "" {
2✔
111
                        return nil, fmt.Errorf("egress auth user specified, but the password is not")
×
112
                }
×
113
        }
114

115
        if cfg.MaxConnsPerHost == 0 {
10✔
116
                cfg.MaxConnsPerHost = 64
1✔
117
        }
1✔
118

119
        return cfg, nil
9✔
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc