Skip to content

Commit 6ff0ad2

Browse files
authored
fix: prevent potential misconfiguration of metricsInterval (#284) (#638)
# Description I have added a new field `metricsIntervalDuration` of type `time.Duration`. It will super cede the `metricsInterval` configuration of the same type. The older key is not removed to keep backward compatibility. The change is done to prevent potential misconfiguration that can happen by assigning a duration to `metricsInterval` when it is converted to seconds. ## Related Issue Issue #284 ## Checklist - [X] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [X] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [X] I have correctly attributed the author(s) of the code. - [X] I have tested the changes locally. - [X] I have followed the project's style guidelines. - [X] I have updated the documentation, if necessary. - [X] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed The logs showing that retina agent runs successffully after making the changes. ![retina-after-chnage](https://github.com/user-attachments/assets/b4b1c643-6ebe-421f-9d32-f0f3d5dac8f6) This shows the log line that `metricsInterval` should not be used. ![retina-using-metrics-interval](https://github.com/user-attachments/assets/9345ac4e-339e-4818-9571-324c38124abd) ## Additional Notes I was not able to us the `zap` logger as it is probably not initialized when the `GetConfig` is called or I might be missing how to use it so i used the go `log` library. Do let me know if we need to change that. --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project. Signed-off-by: Ritwik Ranjan <[email protected]>
1 parent e17cb5e commit 6ff0ad2

File tree

11 files changed

+30
-16
lines changed

11 files changed

+30
-16
lines changed

deploy/hubble/manifests/controller/helm/retina/templates/agent/configmap.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ data:
105105
logLevel: {{ .Values.logLevel }}
106106
enabledPlugin: {{ .Values.enabledPlugin_linux }}
107107
metricsInterval: {{ .Values.metricsInterval }}
108+
metricsIntervalDuration: {{ .Values.metricsIntervalDuration }}
108109
enableTelemetry: {{ .Values.enableTelemetry }}
109110
enablePodLevel: {{ .Values.enablePodLevel }}
110111
remoteContext: {{ .Values.remoteContext }}
@@ -128,6 +129,7 @@ data:
128129
logLevel: {{ .Values.logLevel }}
129130
enabledPlugin: {{ .Values.enabledPlugin_win }}
130131
metricsInterval: {{ .Values.metricsInterval }}
132+
metricsIntervalDuration: {{ .Values.metricsIntervalDuration }}
131133
enableTelemetry: {{ .Values.enableTelemetry }}
132134
enablePodLevel: {{ .Values.enablePodLevel }}
133135
remoteContext: {{ .Values.remoteContext }}

deploy/hubble/manifests/controller/helm/retina/values.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ enabledPlugin_win: '["hnsstats"]'
8686

8787
enableTelemetry: true
8888

89-
# Interval, in seconds, to scrape/publish metrics.
90-
metricsInterval: 10
89+
# Interval, in duration, to scrape/publish metrics.
90+
metricsIntervalDuration: "10s"
9191

9292
azure:
9393
appinsights:

deploy/legacy/manifests/controller/helm/retina/templates/configmap.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ data:
1616
logLevel: {{ .Values.logLevel }}
1717
enabledPlugin: {{ .Values.enabledPlugin_linux }}
1818
metricsInterval: {{ .Values.metricsInterval }}
19+
metricsIntervalDuration: {{ .Values.metricsIntervalDuration }}
1920
enableTelemetry: {{ .Values.enableTelemetry }}
2021
enablePodLevel: {{ .Values.enablePodLevel }}
2122
remoteContext: {{ .Values.remoteContext }}
@@ -42,6 +43,7 @@ data:
4243
logLevel: {{ .Values.logLevel }}
4344
enabledPlugin: {{ .Values.enabledPlugin_win }}
4445
metricsInterval: {{ .Values.metricsInterval }}
46+
metricsIntervalDuration: {{ .Values.metricsIntervalDuration }}
4547
enableTelemetry: {{ .Values.enableTelemetry }}
4648
enablePodLevel: {{ .Values.enablePodLevel }}
4749
remoteContext: {{ .Values.remoteContext }}

deploy/legacy/manifests/controller/helm/retina/values.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ enabledPlugin_win: '["hnsstats"]'
6666

6767
enableTelemetry: false
6868

69-
# Interval, in seconds, to scrape/publish metrics.
70-
metricsInterval: 10
69+
# Interval, in duration, to scrape/publish metrics.
70+
metricsIntervalDuration: "10s"
7171

7272
azure:
7373
appinsights:
@@ -191,3 +191,4 @@ metrics:
191191
## @param metrics.podMonitor.relabelings [array] Prometheus relabeling rules
192192
##
193193
relabelings: []
194+

docs/02-Installation/03-Config.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Defaults are specified for each component in *deploy/legacy/manifests/controller
1212
* `enableAnnotations`: When this toggle is set to true, retina will gather metrics for the annotated resources. Namespaces or Pods can be annotated with `retina.sh/v1alpha=observe`. The operator and enableRetinaEndpoint for the operator should be enabled.
1313
* `enabledPlugin_linux`: Array of enabled plugins for linux.
1414
* `enabledPlugin_win`: Array of enabled plugins for windows.
15-
* `metricsInterval`: the interval for which metrics will be gathered.
15+
* `metricsInterval`: the interval for which metrics will be gathered (in seconds). (@deprecated, use metricsIntervalDuration instead)
16+
* `metricsIntervalDuration`: the interval for which metrics will be gathered (in duration)
1617
* `dataAggregationLevel`: This config defines the level of data aggregation for Retina. See [Data Aggregation](../05-Concepts/data-aggregation.md) for more details.
1718

1819
## Operator Config

docs/06-Troubleshooting/basic-metrics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ data:
5656
port: 10093
5757
logLevel: info
5858
enabledPlugin: ["dropreason","packetforward","linuxutil"]
59-
metricsInterval: 10
59+
metricsIntervalDuration: "10s"
6060
enableTelemetry: false
6161
kind: ConfigMap
6262
metadata:

pkg/config/config.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package config
44

55
import (
66
"fmt"
7+
"log"
78
"reflect"
89
"strings"
910
"time"
@@ -51,10 +52,12 @@ type Server struct {
5152
}
5253

5354
type Config struct {
54-
APIServer Server `yaml:"apiServer"`
55-
LogLevel string `yaml:"logLevel"`
56-
EnabledPlugin []string `yaml:"enabledPlugin"`
57-
MetricsInterval time.Duration `yaml:"metricsInterval"`
55+
APIServer Server `yaml:"apiServer"`
56+
LogLevel string `yaml:"logLevel"`
57+
EnabledPlugin []string `yaml:"enabledPlugin"`
58+
MetricsInterval time.Duration `yaml:"metricsInterval"`
59+
// Deprecated: Use only MetricsInterval instead in the go code.
60+
MetricsIntervalDuration time.Duration `yaml:"metricsIntervalDuration"`
5861
EnableTelemetry bool `yaml:"enableTelemetry"`
5962
EnableRetinaEndpoint bool `yaml:"enableRetinaEndpoint"`
6063
EnablePodLevel bool `yaml:"enablePodLevel"`
@@ -95,8 +98,13 @@ func GetConfig(cfgFilename string) (*Config, error) {
9598
if err != nil {
9699
return nil, fmt.Errorf("fatal error config file: %s", err)
97100
}
98-
// Convert to second.
99-
config.MetricsInterval = config.MetricsInterval * time.Second
101+
102+
if config.MetricsIntervalDuration != 0 {
103+
config.MetricsInterval = config.MetricsIntervalDuration
104+
} else if config.MetricsInterval != 0 {
105+
config.MetricsInterval *= time.Second
106+
log.Print("metricsInterval is deprecated, please use metricsIntervalDuration instead")
107+
}
100108

101109
return &config, nil
102110
}

pkg/config/testwith/config-mock.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ apiServer:
55
logLevel: info
66
enabledPlugin: ["mockplugin"]
77
# Interval, in seconds, to scrape/publish metrics.
8-
metricsInterval: 10
8+
metricsIntervalDuration: "10s"
99
# used to export telemetry to AppInsights
1010
telemetryEnabled: true

pkg/config/testwith/config-win.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ apiServer:
55
logLevel: info
66
enabledPlugin: ["hnsstats"]
77
# Interval, in seconds, to scrape/publish metrics.
8-
metricsInterval: 10
8+
metricsIntervalDuration: "10s"
99
# used to export telemetry to AppInsights
1010
telemetryEnabled: true

pkg/config/testwith/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiServer:
55
logLevel: info
66
enabledPlugin: ["dropreason", "packetforward", "linuxutil"]
77
# Interval, in seconds, to scrape/publish metrics.
8-
metricsInterval: 10
8+
metricsIntervalDuration: "10s"
99
# used to export telemetry to AppInsights
1010
telemetryEnabled: true
1111
dataAggregationLevel: "low"

windows/manifests/windows.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ data:
6767
port: 10093
6868
logLevel: info
6969
enabledPlugin: ["hnsstats"]
70-
metricsInterval: 10
70+
metricsIntervalDuration: "10s"

0 commit comments

Comments
 (0)