Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide-metrics-api/go/config/config.go
2499 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package config
6
7
import (
8
"bytes"
9
"encoding/json"
10
"os"
11
12
"github.com/gitpod-io/gitpod/common-go/grpc"
13
"golang.org/x/xerrors"
14
)
15
16
type LabelAllowList struct {
17
Name string `json:"name"`
18
AllowValues []string `json:"allowValues"`
19
DefaultValue string `json:"defaultValue"`
20
}
21
22
type ClientAllowList = LabelAllowList
23
24
type MetricsServerConfiguration struct {
25
Port int `json:"port"`
26
RateLimits map[string]grpc.RateLimit `json:"ratelimits"`
27
CounterMetrics []CounterMetricsConfiguration `json:"counterMetrics"`
28
HistogramMetrics []HistogramMetricsConfiguration `json:"histogramMetrics"`
29
AggregatedHistogramMetrics []HistogramMetricsConfiguration `json:"aggregatedHistogramMetrics"`
30
ErrorReporting ErrorReportingConfiguration `json:"errorReporting"`
31
}
32
33
type CounterMetricsConfiguration struct {
34
Name string `json:"name"`
35
Help string `json:"help"`
36
Labels []LabelAllowList `json:"labels"`
37
Client *ClientAllowList `json:"client"`
38
}
39
40
type HistogramMetricsConfiguration struct {
41
Name string `json:"name"`
42
Help string `json:"help"`
43
Labels []LabelAllowList `json:"labels"`
44
Buckets []float64 `json:"buckets"`
45
Client *ClientAllowList `json:"client"`
46
}
47
48
type ErrorReportingConfiguration struct {
49
AllowComponents []string `json:"allowComponents"`
50
}
51
52
type ServiceConfiguration struct {
53
Server MetricsServerConfiguration `json:"server"`
54
55
Debug bool `json:"debug"`
56
57
PProf struct {
58
Addr string `json:"addr"`
59
} `json:"pprof"`
60
61
Prometheus struct {
62
Addr string `json:"addr"`
63
} `json:"prometheus"`
64
}
65
66
func Read(fn string) (*ServiceConfiguration, error) {
67
ctnt, err := os.ReadFile(fn)
68
if err != nil {
69
return nil, xerrors.Errorf("cannot read config file: %w", err)
70
}
71
72
var cfg ServiceConfiguration
73
dec := json.NewDecoder(bytes.NewReader(ctnt))
74
dec.DisallowUnknownFields()
75
err = dec.Decode(&cfg)
76
if err != nil {
77
return nil, xerrors.Errorf("cannot parse config file: %w", err)
78
}
79
80
return &cfg, nil
81
}
82
83