2323import io .javaoperatorsdk .operator .processing .event .source .ResourceAction ;
2424
2525public class MDCUtils {
26+ public static final String NO_NAMESPACE = "no namespace" ;
2627
2728 private static final String NAME = "resource.name" ;
2829 private static final String NAMESPACE = "resource.namespace" ;
@@ -31,20 +32,18 @@ public class MDCUtils {
3132 private static final String RESOURCE_VERSION = "resource.resourceVersion" ;
3233 private static final String GENERATION = "resource.generation" ;
3334 private static final String UID = "resource.uid" ;
34- private static final String NO_NAMESPACE = "no namespace" ;
3535 private static final boolean enabled =
3636 Utils .getBooleanFromSystemPropsOrDefault (Utils .USE_MDC_ENV_KEY , true );
3737
3838 private static final String EVENT_SOURCE_PREFIX = "eventsource.event." ;
3939 private static final String EVENT_ACTION = EVENT_SOURCE_PREFIX + "action" ;
4040 private static final String EVENT_SOURCE_NAME = "eventsource.name" ;
41- private static final String UNKNOWN_ACTION = "unknown action" ;
4241
4342 public static void addInformerEventInfo (
4443 HasMetadata resource , ResourceAction action , String eventSourceName ) {
4544 if (enabled ) {
4645 addResourceInfo (resource , true );
47- MDC .put (EVENT_ACTION , action == null ? UNKNOWN_ACTION : action .name ());
46+ MDC .put (EVENT_ACTION , action .name ());
4847 MDC .put (EVENT_SOURCE_NAME , eventSourceName );
4948 }
5049 }
@@ -92,9 +91,10 @@ public static void addResourceInfo(HasMetadata resource, boolean forEventSource)
9291 final var metadata = resource .getMetadata ();
9392 if (metadata != null ) {
9493 MDC .put (key (NAME , forEventSource ), metadata .getName ());
95- if (metadata .getNamespace () != null ) {
96- MDC .put (key (NAMESPACE , forEventSource ), metadata .getNamespace ());
97- }
94+
95+ final var namespace = metadata .getNamespace ();
96+ MDC .put (key (NAMESPACE , forEventSource ), namespace != null ? namespace : NO_NAMESPACE );
97+
9898 MDC .put (key (RESOURCE_VERSION , forEventSource ), metadata .getResourceVersion ());
9999 if (metadata .getGeneration () != null ) {
100100 MDC .put (key (GENERATION , forEventSource ), metadata .getGeneration ().toString ());
0 commit comments