Skip to content

Commit 2114e10

Browse files
committed
8
1 parent 12ae350 commit 2114e10

File tree

7 files changed

+108
-75
lines changed

7 files changed

+108
-75
lines changed

components/ide-metrics-api/go/config/config.go

+21-15
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@ type LabelAllowList struct {
1818
AllowValues []string `json:"allowValues"`
1919
}
2020

21+
type MetricsServerConfiguration struct {
22+
Port int `json:"port"`
23+
RateLimits map[string]grpc.RateLimit `json:"ratelimits"`
24+
CounterMetrics []CounterMetricsConfiguration `json:"counterMetrics"`
25+
HistogramMetrics []HistogramMetricsConfiguration `json:"histogramMetrics"`
26+
}
27+
28+
type CounterMetricsConfiguration struct {
29+
Name string `json:"name"`
30+
Help string `json:"help"`
31+
Labels []LabelAllowList `json:"labels"`
32+
}
33+
34+
type HistogramMetricsConfiguration struct {
35+
Name string `json:"name"`
36+
Help string `json:"help"`
37+
Labels []LabelAllowList `json:"labels"`
38+
Buckets []float64 `json:"buckets"`
39+
}
40+
2141
type ServiceConfiguration struct {
22-
Server struct {
23-
Port int `json:"port"`
24-
RateLimits map[string]grpc.RateLimit `json:"ratelimits"`
25-
CounterMetrics []struct {
26-
Name string `json:"name"`
27-
Help string `json:"help"`
28-
Labels []LabelAllowList `json:"labels"`
29-
} `json:"counterMetrics"`
30-
HistogramMetrics []struct {
31-
Name string `json:"name"`
32-
Help string `json:"help"`
33-
Labels []LabelAllowList `json:"labels"`
34-
Buckets []float64 `json:"buckets"`
35-
} `json:"histogramMetrics"`
36-
} `json:"server"`
42+
Server MetricsServerConfiguration `json:"server"`
3743

3844
PProf struct {
3945
Addr string `json:"addr"`

components/ide-proxy/conf/Caddyfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@
7777
}
7878

7979
handle {
80-
respond "404 - Not Found" 404
80+
reverse_proxy ide-metrics.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:4000 {
81+
import upstream_headers
82+
import upstream_connection
83+
84+
flush_interval -1
85+
}
8186
}
8287
}
8388

install/installer/go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/gitpod-io/gitpod/blobserve v0.0.0-00010101000000-000000000000
1111
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
1212
github.com/gitpod-io/gitpod/content-service/api v0.0.0-00010101000000-000000000000
13+
github.com/gitpod-io/gitpod/ide-metrics-api v0.0.0-00010101000000-000000000000
1314
github.com/gitpod-io/gitpod/image-builder/api v0.0.0-00010101000000-000000000000
1415
github.com/gitpod-io/gitpod/openvsx-proxy v0.0.0-00010101000000-000000000000
1516
github.com/gitpod-io/gitpod/public-api v0.0.0-00010101000000-000000000000
@@ -277,7 +278,7 @@ require (
277278
golang.org/x/text v0.3.7 // indirect
278279
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
279280
golang.org/x/tools v0.1.8-0.20211028023602-8de2a7fd1736 // indirect
280-
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
281+
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
281282
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
282283
google.golang.org/api v0.77.0 // indirect
283284
google.golang.org/appengine v1.6.7 // indirect
@@ -346,6 +347,8 @@ replace github.com/gitpod-io/gitpod/ws-manager/api => ../../components/ws-manage
346347

347348
replace github.com/gitpod-io/gitpod/ws-proxy => ../../components/ws-proxy // leeway
348349

350+
replace github.com/gitpod-io/gitpod/ide-metrics-api => ../../components/ide-metrics-api/go // leeway
351+
349352
replace k8s.io/api => k8s.io/api v0.23.5 // leeway indirect from components/common-go:lib
350353

351354
replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.23.5 // leeway indirect from components/common-go:lib

install/installer/go.sum

+4-58
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

install/installer/pkg/components/ide-metrics/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ const (
1010
PortName = "http"
1111
ServicePort = 3000
1212
ReadinessPort = 3000
13+
VolumeConfig = "config"
1314
)

install/installer/pkg/components/ide-metrics/deployment.go

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
4848
RestartPolicy: "Always",
4949
TerminationGracePeriodSeconds: pointer.Int64(30),
5050
Containers: []corev1.Container{{
51+
Args: []string{"run", "--config", "/config/config.json"},
5152
Name: Component,
5253
Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.IDEMetrics.Version),
5354
ImagePullPolicy: corev1.PullIfNotPresent,
@@ -67,6 +68,13 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
6768
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
6869
common.DefaultEnv(&ctx.Config),
6970
)),
71+
VolumeMounts: []corev1.VolumeMount{
72+
{
73+
Name: VolumeConfig,
74+
MountPath: "/config",
75+
ReadOnly: true,
76+
},
77+
},
7078
ReadinessProbe: &corev1.Probe{
7179
ProbeHandler: corev1.ProbeHandler{
7280
TCPSocket: &corev1.TCPSocketAction{
@@ -78,6 +86,16 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
7886
TimeoutSeconds: 1,
7987
},
8088
}},
89+
Volumes: []corev1.Volume{
90+
{
91+
Name: VolumeConfig,
92+
VolumeSource: corev1.VolumeSource{
93+
ConfigMap: &corev1.ConfigMapVolumeSource{
94+
LocalObjectReference: corev1.LocalObjectReference{Name: Component},
95+
},
96+
},
97+
},
98+
},
8199
},
82100
},
83101
},

0 commit comments

Comments
 (0)