Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make Prometheus namespace optional #87

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Command struct {
disableMetrics bool
telemetryProject string
telemetryPrefix string
prometheus bool
prometheusNamespace string
healthCheck bool
httpPort string
Expand Down Expand Up @@ -184,8 +185,10 @@ the maximum time has passed. Defaults to 0s.`)
"Disable Cloud Monitoring integration (used with telemetry-project)")
cmd.PersistentFlags().StringVar(&c.telemetryPrefix, "telemetry-prefix", "",
"Prefix to use for Cloud Monitoring metrics.")
cmd.PersistentFlags().BoolVar(&c.prometheus, "prometheus", false,
"Enable Prometheus HTTP endpoint /metrics")
cmd.PersistentFlags().StringVar(&c.prometheusNamespace, "prometheus-namespace", "",
"Enable Prometheus for metric collection using the provided namespace")
"Use the provided Prometheus namespace for metrics")
cmd.PersistentFlags().StringVar(&c.httpPort, "http-port", "9090",
"Port for the Prometheus server to use")
cmd.PersistentFlags().BoolVar(&c.healthCheck, "health-check", false,
Expand Down Expand Up @@ -247,8 +250,8 @@ func parseConfig(cmd *Command, conf *proxy.Config, args []string) error {
cmd.logger.Infof("Using API Endpoint %v", conf.APIEndpointURL)
}

if userHasSet("http-port") && !userHasSet("prometheus-namespace") && !userHasSet("health-check") {
cmd.logger.Infof("Ignoring --http-port because --prometheus-namespace or --health-check was not set")
if userHasSet("http-port") && !userHasSet("prometheus") && !userHasSet("health-check") {
cmd.logger.Infof("Ignoring --http-port because --prometheus or --health-check was not set")
}

if !userHasSet("telemetry-project") && userHasSet("telemetry-prefix") {
Expand Down Expand Up @@ -367,7 +370,7 @@ func runSignalWrapper(cmd *Command) error {
needsHTTPServer bool
mux = http.NewServeMux()
)
if cmd.prometheusNamespace != "" {
if cmd.prometheus {
needsHTTPServer = true
e, err := prometheus.NewExporter(prometheus.Options{
Namespace: cmd.prometheusNamespace,
Expand Down
4 changes: 1 addition & 3 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,7 @@ func TestPrometheusMetricsEndpoint(t *testing.T) {
// Keep the test output quiet
c.SilenceUsage = true
c.SilenceErrors = true
c.SetArgs([]string{
"--prometheus-namespace", "prometheus",
"my-project:my-region:my-instance"})
c.SetArgs([]string{"--prometheus", "my-project:my-region:my-instance"})

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down