29
29
import java .util .Map ;
30
30
import java .util .concurrent .TimeUnit ;
31
31
import java .util .function .Supplier ;
32
- import javax .annotation .Nullable ;
33
32
34
33
public final class InstrumentationProperties {
35
34
private static final SafeLogger log = SafeLoggerFactory .get (InstrumentationProperties .class );
@@ -53,26 +52,25 @@ public static boolean isSpecificEnabled(String name) {
53
52
54
53
@ SuppressWarnings ("WeakerAccess" ) // public API
55
54
public static boolean isSpecificEnabled (String name , boolean defaultValue ) {
56
- String qualifiedValue = getSpecific (name );
55
+ Map <String , String > props = instrumentationProperties .get ();
56
+ // avoid string concatenation allocation in common case where no `instrument` properties are defined
57
+ if (props .isEmpty ()) {
58
+ return defaultValue ;
59
+ }
60
+ String qualifiedValue = props .get (INSTRUMENT_PREFIX + "." + name );
57
61
if (qualifiedValue == null ) {
58
62
return defaultValue ;
59
63
}
60
64
return "true" .equalsIgnoreCase (qualifiedValue );
61
65
}
62
66
63
- /** Applies the {@link #INSTRUMENT_PREFIX} and returns the current value. */
64
- @ Nullable
65
- private static String getSpecific (String name ) {
66
- return instrumentationProperties ().get (INSTRUMENT_PREFIX + "." + name );
67
- }
68
-
69
67
@ SuppressWarnings ("WeakerAccess" ) // public API
70
68
public static boolean isGloballyEnabled () {
71
69
return !isGloballyDisabled ();
72
70
}
73
71
74
72
private static boolean isGloballyDisabled () {
75
- return "false" .equalsIgnoreCase (instrumentationProperties ().get (INSTRUMENT_PREFIX ));
73
+ return "false" .equalsIgnoreCase (instrumentationProperties . get ().get (INSTRUMENT_PREFIX ));
76
74
}
77
75
78
76
/**
@@ -90,10 +88,6 @@ private static Supplier<Map<String, String>> createSupplier() {
90
88
InstrumentationProperties ::createInstrumentationSystemProperties , 1L , TimeUnit .MINUTES );
91
89
}
92
90
93
- private static Map <String , String > instrumentationProperties () {
94
- return instrumentationProperties .get ();
95
- }
96
-
97
91
private static ImmutableMap <String , String > createInstrumentationSystemProperties () {
98
92
/*
99
93
* Since system properties are backed by a java.util.Hashtable, they can be
@@ -112,7 +106,9 @@ private static ImmutableMap<String, String> createInstrumentationSystemPropertie
112
106
&& String .valueOf (entry .getKey ()).startsWith (INSTRUMENT_PREFIX ))
113
107
.collect (ImmutableMap .toImmutableMap (
114
108
entry -> String .valueOf (entry .getKey ()), entry -> String .valueOf (entry .getValue ())));
115
- log .debug ("Reloaded instrumentation properties {}" , UnsafeArg .of ("instrumentationProperties" , map ));
109
+ if (log .isDebugEnabled ()) {
110
+ log .debug ("Reloaded instrumentation properties" , UnsafeArg .of ("instrumentationProperties" , map ));
111
+ }
116
112
return map ;
117
113
}
118
114
}
0 commit comments