Path: blob/main/components/ide-metrics-api/go/config/config.go
2499 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package config56import (7"bytes"8"encoding/json"9"os"1011"github.com/gitpod-io/gitpod/common-go/grpc"12"golang.org/x/xerrors"13)1415type LabelAllowList struct {16Name string `json:"name"`17AllowValues []string `json:"allowValues"`18DefaultValue string `json:"defaultValue"`19}2021type ClientAllowList = LabelAllowList2223type MetricsServerConfiguration struct {24Port int `json:"port"`25RateLimits map[string]grpc.RateLimit `json:"ratelimits"`26CounterMetrics []CounterMetricsConfiguration `json:"counterMetrics"`27HistogramMetrics []HistogramMetricsConfiguration `json:"histogramMetrics"`28AggregatedHistogramMetrics []HistogramMetricsConfiguration `json:"aggregatedHistogramMetrics"`29ErrorReporting ErrorReportingConfiguration `json:"errorReporting"`30}3132type CounterMetricsConfiguration struct {33Name string `json:"name"`34Help string `json:"help"`35Labels []LabelAllowList `json:"labels"`36Client *ClientAllowList `json:"client"`37}3839type HistogramMetricsConfiguration struct {40Name string `json:"name"`41Help string `json:"help"`42Labels []LabelAllowList `json:"labels"`43Buckets []float64 `json:"buckets"`44Client *ClientAllowList `json:"client"`45}4647type ErrorReportingConfiguration struct {48AllowComponents []string `json:"allowComponents"`49}5051type ServiceConfiguration struct {52Server MetricsServerConfiguration `json:"server"`5354Debug bool `json:"debug"`5556PProf struct {57Addr string `json:"addr"`58} `json:"pprof"`5960Prometheus struct {61Addr string `json:"addr"`62} `json:"prometheus"`63}6465func Read(fn string) (*ServiceConfiguration, error) {66ctnt, err := os.ReadFile(fn)67if err != nil {68return nil, xerrors.Errorf("cannot read config file: %w", err)69}7071var cfg ServiceConfiguration72dec := json.NewDecoder(bytes.NewReader(ctnt))73dec.DisallowUnknownFields()74err = dec.Decode(&cfg)75if err != nil {76return nil, xerrors.Errorf("cannot parse config file: %w", err)77}7879return &cfg, nil80}818283