|
| 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 ide_metrics |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + |
| 10 | + "github.com/gitpod-io/gitpod/ide-metrics-api/config" |
| 11 | + "github.com/gitpod-io/gitpod/installer/pkg/common" |
| 12 | + |
| 13 | + corev1 "k8s.io/api/core/v1" |
| 14 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 15 | + "k8s.io/apimachinery/pkg/runtime" |
| 16 | +) |
| 17 | + |
| 18 | +func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { |
| 19 | + counterMetrics := make([]config.CounterMetricsConfiguration, 0) |
| 20 | + histogramMetrics := make([]config.HistogramMetricsConfiguration, 0) |
| 21 | + |
| 22 | + cfg := config.ServiceConfiguration{ |
| 23 | + Server: config.MetricsServerConfiguration{ |
| 24 | + Port: ContainerPort, |
| 25 | + // RateLimits: , // TODO(pd) ratelimit |
| 26 | + CounterMetrics: counterMetrics, |
| 27 | + HistogramMetrics: histogramMetrics, |
| 28 | + }, |
| 29 | + Prometheus: struct { |
| 30 | + Addr string `json:"addr"` |
| 31 | + }{Addr: common.LocalhostPrometheusAddr()}, |
| 32 | + } |
| 33 | + |
| 34 | + fc, err := common.ToJSONString(cfg) |
| 35 | + if err != nil { |
| 36 | + return nil, fmt.Errorf("failed to marshal ide-metrics config: %w", err) |
| 37 | + } |
| 38 | + |
| 39 | + res := []runtime.Object{ |
| 40 | + &corev1.ConfigMap{ |
| 41 | + TypeMeta: common.TypeMetaConfigmap, |
| 42 | + ObjectMeta: metav1.ObjectMeta{ |
| 43 | + Name: Component, |
| 44 | + Namespace: ctx.Namespace, |
| 45 | + Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap), |
| 46 | + Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap), |
| 47 | + }, |
| 48 | + Data: map[string]string{ |
| 49 | + "config.json": string(fc), |
| 50 | + }, |
| 51 | + }, |
| 52 | + } |
| 53 | + return res, nil |
| 54 | +} |
0 commit comments