Skip to content

Commit ff0c644

Browse files
committed
doc/../metrics/*: Wrap main func in docs
1 parent aa022bb commit ff0c644

File tree

2 files changed

+46
-32
lines changed

2 files changed

+46
-32
lines changed

doc/user/metrics/README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,35 @@ By default, the metrics are served on `0.0.0.0:8383/metrics`. To modify the port
1212

1313
```go
1414
import(
15-
"github.com/operator-framework/operator-sdk/pkg/metrics"
16-
"sigs.k8s.io/controller-runtime/pkg/manager"
15+
"github.com/operator-framework/operator-sdk/pkg/metrics"
16+
"sigs.k8s.io/controller-runtime/pkg/manager"
1717
)
1818

19-
// Change the below variables to serve metrics on different host or port.
20-
var metricsHost = "0.0.0.0"
21-
var metricsPort int32 = 8383
22-
23-
// Pass metrics address to controller-runtime manager
24-
mgr, err := manager.New(cfg, manager.Options{
25-
Namespace: namespace,
26-
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
27-
})
28-
29-
...
30-
31-
// Create Service object to expose the metrics port.
32-
_, err = metrics.ExposeMetricsPort(ctx, metricsPort)
33-
if err != nil {
34-
// handle error
35-
log.Info(err.Error())
36-
}
19+
func main() {
20+
21+
...
22+
23+
// Change the below variables to serve metrics on different host or port.
24+
var metricsHost = "0.0.0.0"
25+
var metricsPort int32 = 8383
26+
27+
// Pass metrics address to controller-runtime manager
28+
mgr, err := manager.New(cfg, manager.Options{
29+
Namespace: namespace,
30+
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
31+
})
32+
33+
...
34+
35+
// Create Service object to expose the metrics port.
36+
_, err = metrics.ExposeMetricsPort(ctx, metricsPort)
37+
if err != nil {
38+
// handle error
39+
log.Info(err.Error())
40+
}
41+
42+
...
43+
}
3744
```
3845

3946
Note: The above example is already present in `cmd/manager/main.go` in all the operators generated with operator-sdk.

doc/user/metrics/service-monitor.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@ The `GenerateServiceMonitor` takes a `Service` object and generates a `ServiceMo
1717
v1 "k8s.io/api/core/v1"
1818
"github.com/operator-framework/operator-sdk/pkg/metrics"
1919
)
20-
21-
// Populate bellow with Service(s) for which you want to create `ServiceMonitor` for.
22-
services := []*v1.Service{}
23-
24-
// Create one `ServiceMonitor` per application per namespace.
25-
// Change below value to name of the Namespace you want the `ServiceMonitor` to be created in.
26-
ns := "default"
27-
28-
// Pass the Service(s) to the helper function, which in turn returns the `ServiceMonitor` object.
29-
serviceMonitors, err := metrics.CreateServiceMonitors(restConfig, ns, services)
30-
if err != nil {
31-
// handle error here
20+
21+
func main() {
22+
23+
...
24+
25+
// Populate bellow with Service(s) for which you want to create `ServiceMonitor` for.
26+
services := []*v1.Service{}
27+
28+
// Create one `ServiceMonitor` per application per namespace.
29+
// Change below value to name of the Namespace you want the `ServiceMonitor` to be created in.
30+
ns := "default"
31+
32+
// Pass the Service(s) to the helper function, which in turn returns the `ServiceMonitor` object.
33+
serviceMonitors, err := metrics.CreateServiceMonitors(restConfig, ns, services)
34+
if err != nil {
35+
// handle error here
36+
}
37+
38+
...
3239
}
3340
```
3441

0 commit comments

Comments
 (0)