54
54
55
55
var (
56
56
metricsAddr string
57
+ enableStackdriver bool
57
58
maxReconciles int
58
59
enableLeaderElection bool
59
60
leaderElectionId string
@@ -82,6 +83,7 @@ func init() {
82
83
func main () {
83
84
setupLog .Info ("Parsing flags" )
84
85
flag .StringVar (& metricsAddr , "metrics-addr" , ":8080" , "The address the metric endpoint binds to." )
86
+ flag .BoolVar (& enableStackdriver , "enable-stackdriver" , true , "If true, export metrics to stackdriver" )
85
87
flag .BoolVar (& enableLeaderElection , "enable-leader-election" , false ,
86
88
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager." )
87
89
flag .StringVar (& leaderElectionId , "leader-election-id" , "controller-leader-election-helper" ,
@@ -110,22 +112,24 @@ func main() {
110
112
// Exporters use Application Default Credentials to authenticate.
111
113
// See https://developers.google.com/identity/protocols/application-default-credentials
112
114
// for more details.
113
- setupLog .Info ("Creating OpenCensus->Stackdriver exporter" )
114
- sd , err := stackdriver .NewExporter (stackdriver.Options {
115
- // Stackdriver’s minimum stats reporting period must be >= 60 seconds.
116
- // https://opencensus.io/exporters/supported-exporters/go/stackdriver/
117
- ReportingInterval : stats .ReportingInterval ,
118
- })
119
- if err == nil {
120
- // Flush must be called before main() exits to ensure metrics are recorded.
121
- defer sd .Flush ()
122
- err = sd .StartMetricsExporter ()
115
+ if enableStackdriver {
116
+ setupLog .Info ("Creating OpenCensus->Stackdriver exporter" )
117
+ sd , err := stackdriver .NewExporter (stackdriver.Options {
118
+ // Stackdriver’s minimum stats reporting period must be >= 60 seconds.
119
+ // https://opencensus.io/exporters/supported-exporters/go/stackdriver/
120
+ ReportingInterval : stats .ReportingInterval ,
121
+ })
123
122
if err == nil {
124
- defer sd .StopMetricsExporter ()
123
+ // Flush must be called before main() exits to ensure metrics are recorded.
124
+ defer sd .Flush ()
125
+ err = sd .StartMetricsExporter ()
126
+ if err == nil {
127
+ defer sd .StopMetricsExporter ()
128
+ }
129
+ }
130
+ if err != nil {
131
+ setupLog .Error (err , "Could not create Stackdriver exporter" )
125
132
}
126
- }
127
- if err != nil {
128
- setupLog .Error (err , "Could not create Stackdriver exporter" )
129
133
}
130
134
131
135
// Hook up OpenCensus to Prometheus.
@@ -134,7 +138,7 @@ func main() {
134
138
// the returned value since it doesn't do anything anyway. See:
135
139
// (https://github.com/census-ecosystem/opencensus-go-exporter-prometheus/blob/2b9ada237b532c09fcb0a1242469827bdb89df41/prometheus.go#L103)
136
140
setupLog .Info ("Creating Prometheus exporter" )
137
- _ , err = prometheus .NewExporter (prometheus.Options {
141
+ _ , err : = prometheus .NewExporter (prometheus.Options {
138
142
Registerer : metrics .Registry , // use the controller-runtime registry to merge with all other metrics
139
143
})
140
144
if err != nil {
0 commit comments