Skip to content

Commit a229d0f

Browse files
committed
fix: Address new comments
1 parent 09abfff commit a229d0f

File tree

5 files changed

+56
-30
lines changed

5 files changed

+56
-30
lines changed

cmd/csi-rclone-plugin/main.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@ import (
1717
)
1818

1919
var (
20-
endpoint string
21-
nodeID string
22-
cacheDir string
23-
cacheSize string
24-
metricsServerConfig metrics.ServerConfig
25-
meters []metrics.Observable
20+
endpoint string
21+
nodeID string
22+
cacheDir string
23+
cacheSize string
24+
meters []metrics.Observable
2625
)
2726

2827
func init() {
2928
flag.Set("logtostderr", "true")
3029
}
3130

3231
func main() {
32+
metricsServerConfig := metrics.ServerConfig{
33+
Host: "localhost",
34+
Port: 9090,
35+
PathPrefix: "/metrics",
36+
PollPeriod: 30 * time.Second,
37+
ShutdownTimeout: 5 * time.Second,
38+
Enabled: false,
39+
}
3340

3441
root := &cobra.Command{
3542
Use: "rclone",
@@ -81,12 +88,12 @@ func main() {
8188

8289
root.ParseFlags(os.Args[1:])
8390

84-
if metricsServerConfig.Enable {
91+
if metricsServerConfig.Enabled {
8592
// Gracefully exit the metrics background servers
8693
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
8794
defer stop()
8895

89-
metricsServer := metricsServerConfig.NewServer(ctx, 5*time.Second, 30*time.Second, &meters)
96+
metricsServer := metricsServerConfig.NewServer(ctx, &meters)
9097
go metricsServer.ListenAndServe()
9198
}
9299

deploy/csi-rclone/templates/csi-controller-rclone.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,21 @@ spec:
5959
- name: rclone
6060
args:
6161
- run
62-
{{- if .Values.csiControllerRclone.rclone.metrics.enable }}
63-
- --metrics-enable={{.Values.csiControllerRclone.rclone.metrics.enable}}
62+
{{- if .Values.csiControllerRclone.rclone.metrics.enabled }}
63+
- --metrics-enabled={{.Values.csiControllerRclone.rclone.metrics.enabled}}
6464
{{- end }}
6565
{{- if .Values.csiControllerRclone.rclone.metrics.host }}
6666
- --metrics-host={{.Values.csiControllerRclone.rclone.metrics.host}}
6767
{{- end }}
6868
{{- if .Values.csiControllerRclone.rclone.metrics.port }}
6969
- --metrics-port={{.Values.csiControllerRclone.rclone.metrics.port}}
7070
{{- end }}
71+
{{- if .Values.csiControllerRclone.rclone.metrics.pathPrefix }}
72+
- --metrics-path-prefix={{.Values.csiControllerRclone.rclone.metrics.pathPrefix}}
73+
{{- end }}
74+
{{- if .Values.csiControllerRclone.rclone.metrics.pollPeriod }}
75+
- --metrics-path-prefix={{.Values.csiControllerRclone.rclone.metrics.pollPeriod}}
76+
{{- end }}
7177
- controller
7278
- --nodeid=$(NODE_ID)
7379
- --endpoint=$(CSI_ENDPOINT)

deploy/csi-rclone/templates/csi-nodeplugin-rclone.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ spec:
6060
- name: rclone
6161
args:
6262
- run
63-
{{- if .Values.csiNodepluginRclone.rclone.metrics.enable }}
64-
- --metrics-enable={{.Values.csiNodepluginRclone.rclone.metrics.enable}}
63+
{{- if .Values.csiNodepluginRclone.rclone.metrics.enabled }}
64+
- --metrics-enabled={{.Values.csiNodepluginRclone.rclone.metrics.enabled}}
6565
{{- end }}
6666
{{- if .Values.csiNodepluginRclone.rclone.metrics.host }}
6767
- --metrics-host={{.Values.csiNodepluginRclone.rclone.metrics.host}}
6868
{{- end }}
6969
{{- if .Values.csiNodepluginRclone.rclone.metrics.port }}
7070
- --metrics-port={{.Values.csiNodepluginRclone.rclone.metrics.port}}
7171
{{- end }}
72+
{{- if .Values.csiNodepluginRclone.rclone.metrics.pathPrefix }}
73+
- --metrics-path-prefix={{.Values.csiNodepluginRclone.rclone.metrics.pathPrefix}}
74+
{{- end }}
75+
{{- if .Values.csiNodepluginRclone.rclone.metrics.pollPeriod }}
76+
- --metrics-path-prefix={{.Values.csiNodepluginRclone.rclone.metrics.pollPeriod}}
77+
{{- end }}
7278
- node
7379
- --nodeid=$(NODE_ID)
7480
- --endpoint=$(CSI_ENDPOINT)

deploy/csi-rclone/values.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ csiControllerRclone:
2828
goMemLimit: # 115Mi
2929
# Prometheus metrics
3030
metrics:
31-
enable: true
31+
enabled: true
3232
host: # localhost
33-
port: 80
33+
port: 9090
34+
pathPrefix: # /metrics
35+
pollPeriod: # 30s
3436
replicas: 1
3537
serviceAccount:
3638
annotations: {}
@@ -69,9 +71,11 @@ csiNodepluginRclone:
6971
goMemLimit: # 115Mi
7072
# Prometheus metrics
7173
metrics:
72-
enable: true
74+
enabled: true
7375
host: # localhost
74-
port: 80
76+
port: 9090
77+
pathPrefix: # /metrics
78+
pollPeriod: # 30s
7579
# Options to configure rclone's caching with VFS
7680
cache:
7781
# The location of the cache directory

pkg/metrics/server.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,41 @@ func poll(ctx context.Context, period time.Duration, observe Observable) {
6262
}
6363

6464
type ServerConfig struct {
65-
host string
66-
port int16
67-
pathPrefix string
68-
Enable bool
65+
Host string
66+
Port int16
67+
PathPrefix string
68+
PollPeriod time.Duration
69+
ShutdownTimeout time.Duration
70+
Enabled bool
6971
}
7072

7173
func (config *ServerConfig) CommandLineParameters(root *cobra.Command) {
72-
root.PersistentFlags().StringVar(&config.host, "metrics-host", "localhost", "Host name or ip address for Prometheus metrics")
73-
root.PersistentFlags().Int16Var(&config.port, "metrics-port", 80, "Port for Prometheus metrics")
74-
root.PersistentFlags().BoolVar(&config.Enable, "metrics-enable", false, "Enable Prometheus metrics")
75-
76-
config.pathPrefix = "/metrics"
74+
root.PersistentFlags().StringVar(&config.Host, "metrics-host", config.Host, "Host name or ip address for Prometheus metrics")
75+
root.PersistentFlags().Int16Var(&config.Port, "metrics-port", config.Port, "Port for Prometheus metrics")
76+
root.PersistentFlags().StringVar(&config.PathPrefix, "metrics-path-prefix", config.PathPrefix, "Path prefix for Prometheus metrics")
77+
root.PersistentFlags().DurationVar(&config.PollPeriod, "metrics-poll-period", config.PollPeriod, "Polling period for Prometheus metrics updates")
78+
root.PersistentFlags().DurationVar(&config.ShutdownTimeout, "metrics-shutdown-timeout", config.ShutdownTimeout, "Shutdown timeout of the Prometheus metrics server")
79+
root.PersistentFlags().BoolVar(&config.Enabled, "metrics-enabled", config.Enabled, "Prometheus metrics state")
7780
}
7881

79-
func (config *ServerConfig) NewServer(ctx context.Context, shutdownTimeout, pollPeriod time.Duration, meters *[]Observable) *Server {
82+
func (config *ServerConfig) NewServer(ctx context.Context, meters *[]Observable) *Server {
8083
mux := http.NewServeMux()
81-
mux.Handle(config.pathPrefix, promhttp.Handler())
84+
mux.Handle(config.PathPrefix, promhttp.Handler())
8285

8386
server := Server{
84-
http: http.Server{Addr: fmt.Sprintf("%s:%d", config.host, config.port), Handler: mux},
87+
http: http.Server{Addr: fmt.Sprintf("%s:%d", config.Host, config.Port), Handler: mux},
8588
shutdownFinished: make(chan struct{}),
8689
}
8790

88-
go poll(ctx, pollPeriod,
91+
go poll(ctx, config.PollPeriod,
8992
func() {
9093
for _, observer := range *meters {
9194
observer()
9295
}
9396
},
9497
)
9598

96-
go server.shutdown(ctx, shutdownTimeout)
99+
go server.shutdown(ctx, config.ShutdownTimeout)
97100

98101
return &server
99102
}

0 commit comments

Comments
 (0)