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

add flag to disable stackdriver #77

Merged
merged 1 commit into from
Aug 27, 2021
Merged
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
34 changes: 19 additions & 15 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (

var (
metricsAddr string
enableStackdriver bool
maxReconciles int
enableLeaderElection bool
leaderElectionId string
Expand Down Expand Up @@ -82,6 +83,7 @@ func init() {
func main() {
setupLog.Info("Parsing flags")
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.BoolVar(&enableStackdriver, "enable-stackdriver", true, "If true, export metrics to stackdriver")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&leaderElectionId, "leader-election-id", "controller-leader-election-helper",
Expand Down Expand Up @@ -110,22 +112,24 @@ func main() {
// Exporters use Application Default Credentials to authenticate.
// See https://developers.google.com/identity/protocols/application-default-credentials
// for more details.
setupLog.Info("Creating OpenCensus->Stackdriver exporter")
sd, err := stackdriver.NewExporter(stackdriver.Options{
// Stackdriver’s minimum stats reporting period must be >= 60 seconds.
// https://opencensus.io/exporters/supported-exporters/go/stackdriver/
ReportingInterval: stats.ReportingInterval,
})
if err == nil {
// Flush must be called before main() exits to ensure metrics are recorded.
defer sd.Flush()
err = sd.StartMetricsExporter()
if enableStackdriver {
setupLog.Info("Creating OpenCensus->Stackdriver exporter")
sd, err := stackdriver.NewExporter(stackdriver.Options{
// Stackdriver’s minimum stats reporting period must be >= 60 seconds.
// https://opencensus.io/exporters/supported-exporters/go/stackdriver/
ReportingInterval: stats.ReportingInterval,
})
if err == nil {
defer sd.StopMetricsExporter()
// Flush must be called before main() exits to ensure metrics are recorded.
defer sd.Flush()
err = sd.StartMetricsExporter()
if err == nil {
defer sd.StopMetricsExporter()
}
}
if err != nil {
setupLog.Error(err, "Could not create Stackdriver exporter")
}
}
if err != nil {
setupLog.Error(err, "Could not create Stackdriver exporter")
}

// Hook up OpenCensus to Prometheus.
Expand All @@ -134,7 +138,7 @@ func main() {
// the returned value since it doesn't do anything anyway. See:
// (https://github.com/census-ecosystem/opencensus-go-exporter-prometheus/blob/2b9ada237b532c09fcb0a1242469827bdb89df41/prometheus.go#L103)
setupLog.Info("Creating Prometheus exporter")
_, err = prometheus.NewExporter(prometheus.Options{
_, err := prometheus.NewExporter(prometheus.Options{
adrianludwin marked this conversation as resolved.
Show resolved Hide resolved
Registerer: metrics.Registry, // use the controller-runtime registry to merge with all other metrics
})
if err != nil {
Expand Down