-
Notifications
You must be signed in to change notification settings - Fork 312
Implement Config Inversion with Default Strictness of Warning
#9181
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
Open
mhlidd
wants to merge
46
commits into
master
Choose a base branch
from
mhlidd/config_inversion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
fd62009
saving work
mhlidd a756eb2
init: adding System.getenv forbiddenAPI, ConfigHelper, ParseSupported…
mhlidd 96e2546
Fixing java6 incompatibility with EnvironmentVariables component
mhlidd 6a87970
parsing JSON at buildtime
mhlidd b062c96
fixing invocationtargetexception
mhlidd 6769bda
spotless
mhlidd 06ed2fd
updating linter to include OTEL_
mhlidd 8dd50e0
adding EnvironmentVariables linter
mhlidd 9660b1a
adding flag for strictness
mhlidd f8d2a8c
updating supported-configurations
mhlidd b68f0b2
updated all discoverable configs
mhlidd dc5d83b
updating jmxfetch configs
mhlidd fe2eeb9
fixing config helper
mhlidd 229c38d
adding unit tests for ConfigHelper
mhlidd 77ddecd
fixing tests pt 1
mhlidd eb6908a
adding configs and updating specific tests to TEST strictness
mhlidd 972eef4
cleanup and removing system.getenv call
mhlidd 81c12f4
adding more supported-configurations
mhlidd 98c57b5
adding more configs
mhlidd 990c0ce
adding configs and updating tests
mhlidd 5bdd8cf
adding branch coverage
mhlidd 52c05b4
updating code coverage again
mhlidd 5192a8a
test
mhlidd f128de8
rebasing
mhlidd 734f9c7
adding more configs post-rebase
mhlidd e9ce233
initialize GeneratedSupportedConfiguratons at buildtime
mhlidd 90f536d
fixing buildtests
mhlidd 7a1517e
adding ConfigInversionStrictStyle
mhlidd 5ca61c0
refactor ConfigHelper to datadog.trace.api
mhlidd abc0b64
adding configs and updating gradle files to reflect ConfigHelper refa…
mhlidd 97db41f
adding telemetry
mhlidd 04bde01
reverting agent-bootstrap to directly invoke EnvironmentVariables com…
mhlidd 9a764c9
Merge branch 'master' into mhlidd/config_inversion
mhlidd e10e0a9
updating ConfigHelper to use getAll()
mhlidd 340eeef
adding classes to native build time and adding suppressforbidden
mhlidd ea83e25
Adding SupportedConfigurationsSource to buildtime
mhlidd 4b602c1
testing
mhlidd 4bdb960
attempt to fix native image
mhlidd 962490d
attempt to fix native build
mhlidd c7aa94d
cleanup pt 1
mhlidd 8068724
cleanup pt 2
mhlidd 47a8f6a
moving buildtime parser out of environment component
mhlidd 94f392c
updating tests bootstrap constants and spock runner
mhlidd 6c2a551
undo migration to configHelper
mhlidd fe697ff
pushing changes for new module
mhlidd 1aefa7e
updating gradle tasks to kotlin plugins
mhlidd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...ents/environment/src/generator/java/datadog/environment/ParseSupportedConfigurations.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package datadog.environment; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.PrintWriter; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class ParseSupportedConfigurations { | ||
|
||
public static void main(String[] args) { | ||
String supportedConfigurationsFilename = | ||
args[0]; // e.g., "resources/supported-configurations.json" | ||
String generatedMappingPath = args[1]; // e.g., | ||
// "build/generated-sources/datadog/environment/GeneratedSupportedConfigurations.java" | ||
|
||
String jsonString; | ||
try { | ||
|
||
InputStream in = | ||
ParseSupportedConfigurations.class | ||
.getClassLoader() | ||
.getResourceAsStream(supportedConfigurationsFilename); | ||
if (in == null) { | ||
throw new IllegalArgumentException( | ||
"Resource not found: " + supportedConfigurationsFilename); | ||
} | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
Map<String, Object> fileData = mapper.readValue(in, Map.class); | ||
|
||
Map<String, List<String>> supported = | ||
(Map<String, List<String>>) fileData.get("supportedConfigurations"); | ||
Map<String, List<String>> aliases = (Map<String, List<String>>) fileData.get("aliases"); | ||
Map<String, String> deprecated = (Map<String, String>) fileData.get("deprecations"); | ||
|
||
Map<String, String> aliasMapping = new HashMap<>(); | ||
for (Map.Entry<String, List<String>> entry : aliases.entrySet()) { | ||
for (String alias : entry.getValue()) { | ||
aliasMapping.put(alias, entry.getKey()); | ||
} | ||
} | ||
generateJavaFile(generatedMappingPath, supported.keySet(), aliases, aliasMapping, deprecated); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to read " + supportedConfigurationsFilename, e); | ||
} | ||
} | ||
|
||
private static void generateJavaFile( | ||
String outputPath, | ||
Set<String> supported, | ||
Map<String, List<String>> aliases, | ||
Map<String, String> aliasMapping, | ||
Map<String, String> deprecated) | ||
throws IOException { | ||
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(Paths.get(outputPath)))) { | ||
out.println("package datadog.environment;"); | ||
out.println(); | ||
out.println("import java.util.*;"); | ||
out.println(); | ||
out.println("public final class GeneratedSupportedConfigurations {"); | ||
|
||
// Supported set using Arrays.asList and HashSet | ||
out.println(" public static final Set<String> SUPPORTED;"); | ||
out.println(); | ||
|
||
// ALIASES map | ||
out.println(" public static final Map<String, List<String>> ALIASES;"); | ||
out.println(); | ||
|
||
// ALIAS_MAPPING map | ||
out.println(" public static final Map<String, String> ALIAS_MAPPING;"); | ||
out.println(); | ||
|
||
// DEPRECATED map | ||
out.println(" public static final Map<String, String> DEPRECATED;"); | ||
out.println(); | ||
|
||
// Static initializer block | ||
out.println(" static {"); | ||
|
||
// Initialize SUPPORTED | ||
out.print(" Set<String> supportedSet = new HashSet<>(Arrays.asList("); | ||
Iterator<String> supportedIter = supported.iterator(); | ||
while (supportedIter.hasNext()) { | ||
String key = supportedIter.next(); | ||
out.print("\"" + key + "\""); | ||
if (supportedIter.hasNext()) { | ||
out.print(", "); | ||
} | ||
} | ||
out.println("));"); | ||
out.println(" SUPPORTED = Collections.unmodifiableSet(supportedSet);"); | ||
out.println(); | ||
|
||
// Initialize ALIASES | ||
out.println(" Map<String, List<String>> aliasesMap = new HashMap<>();"); | ||
for (Map.Entry<String, List<String>> entry : aliases.entrySet()) { | ||
out.printf( | ||
" aliasesMap.put(\"%s\", Collections.unmodifiableList(Arrays.asList(%s)));\n", | ||
entry.getKey(), quoteList(entry.getValue())); | ||
} | ||
out.println(" ALIASES = Collections.unmodifiableMap(aliasesMap);"); | ||
out.println(); | ||
|
||
// Initialize ALIAS_MAPPING | ||
out.println(" Map<String, String> aliasMappingMap = new HashMap<>();"); | ||
for (Map.Entry<String, String> entry : aliasMapping.entrySet()) { | ||
out.printf(" aliasMappingMap.put(\"%s\", \"%s\");\n", entry.getKey(), entry.getValue()); | ||
} | ||
out.println(" ALIAS_MAPPING = Collections.unmodifiableMap(aliasMappingMap);"); | ||
out.println(); | ||
|
||
// Initialize DEPRECATED | ||
out.println(" Map<String, String> deprecatedMap = new HashMap<>();"); | ||
for (Map.Entry<String, String> entry : deprecated.entrySet()) { | ||
out.printf(" deprecatedMap.put(\"%s\", \"%s\");\n", entry.getKey(), entry.getValue()); | ||
} | ||
out.println(" DEPRECATED = Collections.unmodifiableMap(deprecatedMap);"); | ||
|
||
out.println(" }"); // end static block | ||
out.println("}"); // end class | ||
} | ||
} | ||
|
||
private static String quoteList(List<String> list) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < list.size(); i++) { | ||
sb.append("\"").append(list.get(i)).append("\""); | ||
if (i < list.size() - 1) { | ||
sb.append(", "); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.