Skip to content

Commit

Permalink
apply quentin's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
hervenicol committed Dec 18, 2024
1 parent 33d32ed commit f96e8ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 1 addition & 2 deletions internal/controller/grafanaorganization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type GrafanaOrganizationReconciler struct {
func SetupGrafanaOrganizationReconciler(mgr manager.Manager, conf config.Config) error {
// Generate Grafana client

grafanaURL := conf.GrafanaURL
// Get grafana admin-password and admin-user
grafanaAdminCredentials := grafanaclient.AdminCredentials{
Username: conf.Environment.GrafanaAdminUsername,
Expand All @@ -74,7 +73,7 @@ func SetupGrafanaOrganizationReconciler(mgr manager.Manager, conf config.Config)
Cert: conf.Environment.GrafanaTLSCertFile,
Key: conf.Environment.GrafanaTLSKeyFile,
}
grafanaAPI, err := grafanaclient.GenerateGrafanaClient(grafanaURL, grafanaAdminCredentials, grafanaTLSConfig)
grafanaAPI, err := grafanaclient.GenerateGrafanaClient(conf.GrafanaURL, grafanaAdminCredentials, grafanaTLSConfig)
if err != nil {
return fmt.Errorf("unable to create grafana client: %w", err)
}
Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"flag"
"fmt"
"net/url"
"os"
"time"

Expand Down Expand Up @@ -63,6 +64,9 @@ func init() {
}

func main() {
var grafanaURLString string
var err error

flag.StringVar(&conf.MetricsAddr, "metrics-bind-address", ":8080",
"The address the metric endpoint binds to.")
flag.StringVar(&conf.ProbeAddr, "health-probe-bind-address", ":8081",
Expand All @@ -76,7 +80,7 @@ func main() {
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.StringVar(&conf.OperatorNamespace, "operator-namespace", "",
"The namespace where the observability-operator is running.")
flag.StringVar(&conf.GrafanaURL, "grafana-url", "http://grafana.monitoring.svc.cluster.local",
flag.StringVar(&grafanaURLString, "grafana-url", "http://grafana.monitoring.svc.cluster.local",
"grafana URL")

// Management cluster configuration flags.
Expand Down Expand Up @@ -112,7 +116,7 @@ func main() {
"The version of Prometheus Agents to deploy.")
flag.DurationVar(&conf.Monitoring.WALTruncateFrequency, "monitoring-wal-truncate-frequency", 2*time.Hour,
"Configures how frequently the Write-Ahead Log (WAL) truncates segments.")
flag.StringVar(&conf.Monitoring.MetricsQueryURL, "metrics-query-url", "http://mimir-gateway.mimir.svc/prometheus",
flag.StringVar(&conf.Monitoring.MetricsQueryURL, "monitoring-metrics-query-url", "http://mimir-gateway.mimir.svc/prometheus",
"URL to query for cluster metrics")
opts := zap.Options{
Development: false,
Expand All @@ -121,10 +125,16 @@ func main() {
opts.BindFlags(flag.CommandLine)
flag.Parse()

// parse grafana URL
conf.GrafanaURL, err = url.Parse(grafanaURLString)
if err != nil {
panic(fmt.Sprintf("failed to parse grafana url: %v", err))
}

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// Load environment variables.
_, err := env.UnmarshalFromEnviron(&conf.Environment)
_, err = env.UnmarshalFromEnviron(&conf.Environment)
if err != nil {
setupLog.Error(err, "failed to unmarshal environment variables")
os.Exit(1)
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"net/url"

"github.com/giantswarm/observability-operator/pkg/common"
"github.com/giantswarm/observability-operator/pkg/monitoring"
)
Expand All @@ -12,7 +14,7 @@ type Config struct {
SecureMetrics bool
EnableHTTP2 bool
OperatorNamespace string
GrafanaURL string
GrafanaURL *url.URL

ManagementCluster common.ManagementCluster

Expand Down
9 changes: 1 addition & 8 deletions pkg/grafana/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ import (
grafana "github.com/grafana/grafana-openapi-client-go/client"
)

var grafanaURL *url.URL

const (
clientConfigNumRetries = 3
)

func GenerateGrafanaClient(grafanaURLstring string, adminUserCredentials AdminCredentials, tlsConfig TLSConfig) (*grafana.GrafanaHTTPAPI, error) {
func GenerateGrafanaClient(grafanaURL *url.URL, adminUserCredentials AdminCredentials, tlsConfig TLSConfig) (*grafana.GrafanaHTTPAPI, error) {
var err error

grafanaURL, err = url.Parse(grafanaURLstring)
if err != nil {
panic(fmt.Sprintf("failed to parse grafana url: %v", err))
}

grafanaTLSConfig, err := tlsConfig.toTLSConfig()
if err != nil {
return nil, fmt.Errorf("failed to build tls config: %w", err)
Expand Down

0 comments on commit f96e8ba

Please sign in to comment.