11---
2- title : Observability
3- weight : 55
2+ title : Metrics
3+ weight : 87
44---
55
66## Runtime Info
@@ -15,53 +15,6 @@ setting, where this flag usually needs to be set to false, in order to control t
1515See also an example implementation in the
1616[ WebPage sample] ( https://github.com/java-operator-sdk/java-operator-sdk/blob/3e2e7c4c834ef1c409d636156b988125744ca911/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java#L38-L43 )
1717
18- ## Contextual Info for Logging with MDC
19-
20- Logging is enhanced with additional contextual information using
21- [ MDC] ( http://www.slf4j.org/manual.html#mdc ) . The following attributes are available in most
22- parts of reconciliation logic and during the execution of the controller:
23-
24- | MDC Key | Value added from primary resource |
25- | :---------------------------| :----------------------------------|
26- | ` resource.apiVersion ` | ` .apiVersion ` |
27- | ` resource.kind ` | ` .kind ` |
28- | ` resource.name ` | ` .metadata.name ` |
29- | ` resource.namespace ` | ` .metadata.namespace ` |
30- | ` resource.resourceVersion ` | ` .metadata.resourceVersion ` |
31- | ` resource.generation ` | ` .metadata.generation ` |
32- | ` resource.uid ` | ` .metadata.uid ` |
33-
34- For more information about MDC see this [ link] ( https://www.baeldung.com/mdc-in-log4j-2-logback ) .
35-
36- ### MDC entries during event handling
37-
38- Although, usually users might not require it in their day-to-day workflow, it is worth mentioning that
39- there are additional MDC entries managed for event handling. Typically, you might be interested in it
40- in your ` SecondaryToPrimaryMapper ` related logs.
41- For ` InformerEventSource ` and ` ControllerEventSource ` the following information is present:
42-
43- | MDC Key | Value from Resource from the Event |
44- | :-----------------------------------------------| :-------------------------------------------------|
45- | ` eventsource.event.resource.name ` | ` .metadata.name ` |
46- | ` eventsource.event.resource.uid ` | ` .metadata.uid ` |
47- | ` eventsource.event.resource.namespace ` | ` .metadata.namespace ` |
48- | ` eventsource.event.resource.kind ` | resource kind |
49- | ` eventsource.event.resource.resourceVersion ` | ` .metadata.resourceVersion ` |
50- | ` eventsource.event.action ` | action name (e.g. ` ADDED ` , ` UPDATED ` , ` DELETED ` ) |
51- | ` eventsource.name ` | name of the event source |
52-
53- ### Note on null values
54-
55- If a resource doesn't provide values for one of the specified keys, the key will be omitted and not added to the MDC
56- context. There is, however, one notable exception: the resource's namespace, where, instead of omitting the key, we emit
57- the ` MDCUtils.NO_NAMESPACE ` value instead. This allows searching for resources without namespace (notably, clustered
58- resources) in the logs more easily.
59-
60- ### Disabling MDC support
61-
62- MDC support is enabled by default. If you want to disable it, you can set the ` JAVA_OPERATOR_SDK_USE_MDC ` environment
63- variable to ` false ` when you start your operator.
64-
6518## Metrics
6619
6720JOSDK provides built-in support for metrics reporting on what is happening with your reconcilers in the form of
@@ -77,9 +30,9 @@ Metrics metrics; // initialize your metrics implementation
7730Operator operator = new Operator (client, o - > o. withMetrics(metrics));
7831```
7932
80- ### MicrometerMetricsV2
33+ ### MicrometerMetricsV2
8134
82- [ ` MicrometerMetricsV2 ` ] ( https://github.com/java-operator-sdk/java-operator-sdk/blob/main/micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetricsV2.java )
35+ [ ` MicrometerMetricsV2 ` ] ( https://github.com/java-operator-sdk/java-operator-sdk/blob/main/micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetricsV2.java )
8336is the recommended micrometer-based implementation. It is designed with low cardinality in mind:
8437all meters are scoped to the controller, not to individual resources. This avoids unbounded cardinality growth as
8538resources come and go.
@@ -230,8 +183,8 @@ Metrics loggingMetrics = new LoggingMetrics();
230183
231184// combine them into a single aggregated instance
232185Metrics aggregatedMetrics = new AggregatedMetrics (List . of(
233- micrometerMetrics,
234- customMetrics,
186+ micrometerMetrics,
187+ customMetrics,
235188 loggingMetrics
236189));
237190
0 commit comments