Skip to content

Commit b2b1551

Browse files
authored
Merge pull request #578 from GoogleCloudPlatform/revert-575-automated-cherry-pick-of-#574-upstream-release-1.14
Revert "Automated cherry pick of #574: Enable metrics collection by default on gcsfusecsi sidecar."
2 parents 1d2ff17 + d5f02f1 commit b2b1551

2 files changed

Lines changed: 25 additions & 39 deletions

File tree

pkg/sidecar_mounter/sidecar_mounter_config.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,13 @@ func NewMountConfig(sp string) *MountConfig {
154154

155155
func (mc *MountConfig) prepareMountArgs() {
156156
flagMap := map[string]string{
157-
"app-name": GCSFuseAppName,
158-
"temp-dir": mc.BufferDir + TempDir,
159-
"config-file": mc.ConfigFile,
160-
"foreground": "",
161-
"uid": "0",
162-
"gid": "0",
163-
"prometheus-port": strconv.Itoa(prometheusPort),
157+
"app-name": GCSFuseAppName,
158+
"temp-dir": mc.BufferDir + TempDir,
159+
"config-file": mc.ConfigFile,
160+
"foreground": "",
161+
"uid": "0",
162+
"gid": "0",
164163
}
165-
// Use a new port each gcsfuse instance that we start.
166-
prometheusPort++
167164

168165
configFileFlagMap := map[string]string{
169166
"logging:file-path": "/dev/fd/1", // redirect the output to cmd stdout
@@ -179,8 +176,10 @@ func (mc *MountConfig) prepareMountArgs() {
179176
f, v := arg[:i], arg[i+1:]
180177

181178
if f == util.DisableMetricsForGKE {
182-
if v == util.TrueStr {
183-
flagMap["prometheus-port"] = "0"
179+
if v == util.FalseStr {
180+
flagMap["prometheus-port"] = strconv.Itoa(prometheusPort)
181+
// Use a new port each gcsfuse instance that we start.
182+
prometheusPort++
184183
}
185184

186185
continue

pkg/sidecar_mounter/sidecar_mounter_config_test.go

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package sidecarmounter
2020
import (
2121
"os"
2222
"reflect"
23-
"slices"
2423
"strconv"
2524
"testing"
2625

@@ -221,7 +220,7 @@ func TestPrepareMountArgs(t *testing.T) {
221220
BufferDir: "test-buffer-dir",
222221
CacheDir: "test-cache-dir",
223222
ConfigFile: "test-config-file",
224-
Options: []string{util.DisableMetricsForGKE + ":true"},
223+
Options: []string{util.DisableMetricsForGKE + ":false"},
225224
},
226225
expectedArgs: map[string]string{
227226
"app-name": GCSFuseAppName,
@@ -234,37 +233,25 @@ func TestPrepareMountArgs(t *testing.T) {
234233
},
235234
expectedConfigMapArgs: defaultConfigFileFlagMap,
236235
},
237-
{
238-
name: "should return valid args when metrics is enabled",
239-
mc: &MountConfig{
240-
BucketName: "test-bucket",
241-
BufferDir: "test-buffer-dir",
242-
CacheDir: "test-cache-dir",
243-
ConfigFile: "test-config-file",
244-
Options: []string{util.DisableMetricsForGKE + ":false"},
245-
},
246-
expectedArgs: map[string]string{
247-
"app-name": GCSFuseAppName,
248-
"temp-dir": "test-buffer-dir/temp-dir",
249-
"config-file": "test-config-file",
250-
"foreground": "",
251-
"uid": "0",
252-
"gid": "0",
253-
},
254-
expectedConfigMapArgs: defaultConfigFileFlagMap,
255-
},
256236
}
257237

258-
testPrometheusPort := prometheusPort
238+
prometheusPort := 62990
259239
for _, tc := range testCases {
260240
t.Run(tc.name, func(t *testing.T) {
261-
// Do not parallelize [e.g t.Parallel()] because all testcases share testPrometheusPort.
262-
found := slices.Contains(tc.mc.Options, util.DisableMetricsForGKE+":true")
263-
if !found {
264-
tc.expectedArgs["prometheus-port"] = strconv.Itoa(testPrometheusPort)
241+
t.Parallel()
242+
found := false
243+
for _, o := range tc.mc.Options {
244+
if o == util.DisableMetricsForGKE+":false" {
245+
found = true
246+
247+
break
248+
}
249+
}
250+
251+
if found {
252+
tc.expectedArgs["prometheus-port"] = strconv.Itoa(prometheusPort)
253+
prometheusPort++
265254
}
266-
// Increase port value to match behavior of prepareMountArgs()
267-
testPrometheusPort++
268255

269256
tc.mc.prepareMountArgs()
270257
if !reflect.DeepEqual(tc.mc.FlagMap, tc.expectedArgs) {

0 commit comments

Comments
 (0)