-
Notifications
You must be signed in to change notification settings - Fork 236
feat: emit MDCUtils.NO_NAMESPACE value when namespace is null #3186
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,13 @@ For `InformerEventSource` and `ControllerEventSource` the following information | |||||||||||||||||||
| | `eventsource.event.action` | action name (e.g. `ADDED`, `UPDATED`, `DELETED`) | | ||||||||||||||||||||
| | `eventsource.name` | name of the event source | | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ### Note on null values | ||||||||||||||||||||
|
|
||||||||||||||||||||
| If a resource doesn't provide values for one of the specified key, the key will be omitted and not added to the MDC | ||||||||||||||||||||
| context. There is, however, one notable exception: the resources' namespace, where, instead of omitting the key, we emit | ||||||||||||||||||||
| the `MDCUtils.NO_NAMESPACE` value instead. This allows searching for resources without namespace (notably, clustered | ||||||||||||||||||||
| resources) in the logs more easily. | ||||||||||||||||||||
|
||||||||||||||||||||
| If a resource doesn't provide values for one of the specified key, the key will be omitted and not added to the MDC | |
| context. There is, however, one notable exception: the resources' namespace, where, instead of omitting the key, we emit | |
| the `MDCUtils.NO_NAMESPACE` value instead. This allows searching for resources without namespace (notably, clustered | |
| resources) in the logs more easily. | |
| If a resource doesn't provide values for one of the specified keys, the SDK may still attempt to add the corresponding | |
| MDC entry with a `null` value. The exact behavior (omitting the key, storing a `null` value, or even raising an error) | |
| depends on the underlying MDC implementation and any logging adapters in use. There is, however, one notable exception: | |
| the resource's namespace, where, instead of using `null`, we emit the `MDCUtils.NO_NAMESPACE` value. This allows | |
| searching for resources without namespace (notably, cluster-scoped resources) in the logs more easily. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |||||
| import io.javaoperatorsdk.operator.processing.event.source.ResourceAction; | ||||||
|
|
||||||
| public class MDCUtils { | ||||||
| public static final String NO_NAMESPACE = "no namespace"; | ||||||
|
|
||||||
| private static final String NAME = "resource.name"; | ||||||
| private static final String NAMESPACE = "resource.namespace"; | ||||||
|
|
@@ -31,20 +32,18 @@ public class MDCUtils { | |||||
| private static final String RESOURCE_VERSION = "resource.resourceVersion"; | ||||||
| private static final String GENERATION = "resource.generation"; | ||||||
| private static final String UID = "resource.uid"; | ||||||
| private static final String NO_NAMESPACE = "no namespace"; | ||||||
| private static final boolean enabled = | ||||||
| Utils.getBooleanFromSystemPropsOrDefault(Utils.USE_MDC_ENV_KEY, true); | ||||||
|
|
||||||
| private static final String EVENT_SOURCE_PREFIX = "eventsource.event."; | ||||||
| private static final String EVENT_ACTION = EVENT_SOURCE_PREFIX + "action"; | ||||||
| private static final String EVENT_SOURCE_NAME = "eventsource.name"; | ||||||
| private static final String UNKNOWN_ACTION = "unknown action"; | ||||||
|
|
||||||
| public static void addInformerEventInfo( | ||||||
| HasMetadata resource, ResourceAction action, String eventSourceName) { | ||||||
| if (enabled) { | ||||||
| addResourceInfo(resource, true); | ||||||
| MDC.put(EVENT_ACTION, action == null ? UNKNOWN_ACTION : action.name()); | ||||||
| MDC.put(EVENT_ACTION, action.name()); | ||||||
|
||||||
| MDC.put(EVENT_ACTION, action.name()); | |
| MDC.put(EVENT_ACTION, action != null ? action.name() : "unknown"); |
Uh oh!
There was an error while loading. Please reload this page.