Skip to content

Commit 4f05a5d

Browse files
cheina97adamjensenbot
authored andcommitted
Network: gateway prometheus metrics
1 parent a99b0b7 commit 4f05a5d

File tree

20 files changed

+435
-64
lines changed

20 files changed

+435
-64
lines changed

cmd/gateway/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func run(cmd *cobra.Command, _ []string) error {
110110
MapperProvider: mapper.LiqoMapperProvider(scheme),
111111
Scheme: scheme,
112112
Metrics: server.Options{
113-
BindAddress: "0", // Metrics are exposed by "connection" container.
113+
BindAddress: connoptions.GwOptions.MetricsAddress,
114114
},
115115
HealthProbeBindAddress: connoptions.GwOptions.ProbeAddr,
116116
LeaderElection: connoptions.GwOptions.LeaderElection,

cmd/gateway/wireguard/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/client/config"
3434
"sigs.k8s.io/controller-runtime/pkg/event"
3535
"sigs.k8s.io/controller-runtime/pkg/log"
36+
"sigs.k8s.io/controller-runtime/pkg/metrics"
3637
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3738

3839
ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1"
@@ -167,6 +168,19 @@ func run(cmd *cobra.Command, _ []string) error {
167168
return fmt.Errorf("unable to init wireguard link: %w", err)
168169
}
169170

171+
// Create the Prometheus collector and register it inside the controller-runtime metrics server.
172+
promcollect, err := wireguard.NewPrometheusCollector(mgr.GetClient(), &wireguard.MetricsOptions{
173+
RemoteClusterID: options.GwOptions.RemoteClusterID,
174+
Namespace: options.GwOptions.Namespace,
175+
WgImplementation: options.Implementation,
176+
})
177+
if err != nil {
178+
return fmt.Errorf("unable to create prometheus collector: %w", err)
179+
}
180+
if err := metrics.Registry.Register(promcollect); err != nil {
181+
return fmt.Errorf("unable to register prometheus collector: %w", err)
182+
}
183+
170184
// Start the manager.
171185
return mgr.Start(cmd.Context())
172186
}

deployments/liqo/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
| metricAgent.pod.labels | object | `{}` | Labels for the metricAgent pod. |
7575
| metricAgent.pod.priorityClassName | string | `""` | PriorityClassName (https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#pod-priority) for the metricAgent pod. |
7676
| metricAgent.pod.resources | object | `{"limits":{},"requests":{}}` | Resource requests and limits (https://kubernetes.io/docs/user-guide/compute-resources/) for the metricAgent pod. |
77+
| metrics.enabled | bool | `false` | Enable/Disable the metrics server in every liqo component. |
78+
| metrics.prometheusOperator.enabled | bool | `false` | Enable/Disable the creation of a Prometheus servicemonitor/podmonitor for the metrics servers. Turn on this flag when the Prometheus Operator runs in your cluster. |
7779
| nameOverride | string | `""` | Override the standard name used by Helm and associated to Kubernetes/Liqo resources. |
7880
| networking.clientResources | list | `[{"apiVersion":"networking.liqo.io/v1alpha1","resource":"wggatewayclients"}]` | Set the list of resources that implement the GatewayClient |
7981
| networking.enabled | bool | `true` | Use the default Liqo networking module. |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
{{- $gatewayConfig := (merge (dict "name" "gateway" "module" "networking" ) .) -}}
3+
4+
{{- if and (.Values.networking.enabled) (.Values.metrics.enabled) (.Values.metrics.prometheusOperator.enabled) }}
5+
6+
apiVersion: monitoring.coreos.com/v1
7+
kind: PodMonitor
8+
metadata:
9+
name: gateway
10+
labels:
11+
{{- include "liqo.labels" $gatewayConfig | nindent 4 }}
12+
spec:
13+
podMetricsEndpoints:
14+
- port: gw-metrics
15+
path: /metrics
16+
- port: wg-metrics
17+
path: /metrics
18+
- port: gv-metrics
19+
path: /metrics
20+
selector:
21+
matchLabels:
22+
networking.liqo.io/component: gateway
23+
namespaceSelector:
24+
any: true
25+
26+
{{- end }}

deployments/liqo/templates/liqo-wireguard-gateway-client-template.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ spec:
4646
- --gateway-uid={{"{{ .GatewayUID }}"}}
4747
- --node-name={{"$(NODE_NAME)"}}
4848
- --mode=client
49+
{{- if .Values.metrics.enabled }}
4950
- --metrics-address=:8080
51+
{{- end }}
5052
- --health-probe-bind-address=:8081
5153
- --ping-enabled=true
5254
- --ping-loss-threshold={{ .Values.networking.gatewayTemplates.ping.lossThreshold }}
@@ -55,6 +57,11 @@ spec:
5557
{{- if gt .Values.networking.gatewayTemplates.replicas 1.0 }}
5658
- --leader-election=true
5759
{{- end }}
60+
{{- if .Values.metrics.enabled }}
61+
ports:
62+
- containerPort: 8080
63+
name: gw-metrics
64+
{{- end }}
5865
env:
5966
- name: NODE_NAME
6067
valueFrom:
@@ -78,9 +85,16 @@ spec:
7885
- --mtu={{"{{ .Spec.MTU }}"}}
7986
- --endpoint-address={{"{{ index .Spec.Endpoint.Addresses 0 }}"}}
8087
- --endpoint-port={{"{{ .Spec.Endpoint.Port }}"}}
88+
{{- if .Values.metrics.enabled }}
8189
- --metrics-address=:8082
90+
{{- end }}
8291
- --health-probe-bind-address=:8083
8392
- --implementation={{ .Values.networking.gatewayTemplates.wireguard.implementation }}
93+
{{- if .Values.metrics.enabled }}
94+
ports:
95+
- containerPort: 8082
96+
name: wg-metrics
97+
{{- end }}
8498
securityContext:
8599
capabilities:
86100
add:
@@ -99,9 +113,16 @@ spec:
99113
- --gateway-uid={{"{{ .GatewayUID }}"}}
100114
- --node-name={{"$(NODE_NAME)"}}
101115
- --mode=server
116+
{{- if .Values.metrics.enabled }}
102117
- --metrics-address=:8084
118+
{{- end }}
103119
- --health-probe-bind-address=:8085
104120
- --enable-arp=true
121+
{{- if .Values.metrics.enabled }}
122+
ports:
123+
- containerPort: 8084
124+
name: gv-metrics
125+
{{- end }}
105126
env:
106127
- name: NODE_NAME
107128
valueFrom:

deployments/liqo/templates/liqo-wireguard-gateway-server-template.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ spec:
6464
- --node-name={{"$(NODE_NAME)"}}
6565
- --gateway-uid={{"{{ .GatewayUID }}"}}
6666
- --mode=server
67+
{{- if .Values.metrics.enabled }}
6768
- --metrics-address=:8080
69+
{{- end }}
6870
- --health-probe-bind-address=:8081
6971
- --ping-enabled=true
7072
- --ping-loss-threshold={{ .Values.networking.gatewayTemplates.ping.lossThreshold }}
@@ -73,6 +75,11 @@ spec:
7375
{{- if gt .Values.networking.gatewayTemplates.replicas 1.0 }}
7476
- --leader-election=true
7577
{{- end }}
78+
{{- if .Values.metrics.enabled }}
79+
ports:
80+
- containerPort: 8080
81+
name: gw-metrics
82+
{{- end }}
7683
env:
7784
- name: NODE_NAME
7885
valueFrom:
@@ -95,9 +102,16 @@ spec:
95102
- --mode=server
96103
- --mtu={{"{{ .Spec.MTU }}"}}
97104
- --listen-port={{"{{ .Spec.Endpoint.Port }}"}}
105+
{{- if .Values.metrics.enabled }}
98106
- --metrics-address=:8082
107+
{{- end }}
99108
- --health-probe-bind-address=:8083
100109
- --implementation={{ .Values.networking.gatewayTemplates.wireguard.implementation }}
110+
{{- if .Values.metrics.enabled }}
111+
ports:
112+
- containerPort: 8082
113+
name: wg-metrics
114+
{{- end }}
101115
securityContext:
102116
capabilities:
103117
add:
@@ -116,9 +130,16 @@ spec:
116130
- --node-name={{"$(NODE_NAME)"}}
117131
- --gateway-uid={{"{{ .GatewayUID }}"}}
118132
- --mode=server
133+
{{- if .Values.metrics.enabled }}
119134
- --metrics-address=:8084
135+
{{- end }}
120136
- --health-probe-bind-address=:8085
121137
- --enable-arp=true
138+
{{- if .Values.metrics.enabled }}
139+
ports:
140+
- containerPort: 8084
141+
name: gv-metrics
142+
{{- end }}
122143
env:
123144
- name: NODE_NAME
124145
valueFrom:

deployments/liqo/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ nameOverride: ""
1010
# -- Override the standard full name used by Helm and associated to Kubernetes/Liqo resources.
1111
fullnameOverride: ""
1212

13+
metrics:
14+
# -- Enable/Disable the metrics server in every liqo component.
15+
enabled: false
16+
prometheusOperator:
17+
# -- Enable/Disable the creation of a Prometheus servicemonitor/podmonitor for the metrics servers.
18+
# Turn on this flag when the Prometheus Operator runs in your cluster.
19+
enabled: false
20+
1321
apiServer:
1422
# -- The address that must be used to contact your API server, it needs to be reachable from the clusters that you will peer with (defaults to your master IP).
1523
address: ""

0 commit comments

Comments
 (0)