From c5f28ed58687a0ceb3e38a20b370b34dd455da14 Mon Sep 17 00:00:00 2001 From: raymond zhao Date: Mon, 13 Nov 2023 13:04:50 -0500 Subject: [PATCH] add read from config file --- .../misbehaving-seed-config.yaml | 1 + .../org/datadog/misbehavingjmxserver/App.java | 42 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tools/misbehaving-jmx-server/misbehaving-seed-config.yaml diff --git a/tools/misbehaving-jmx-server/misbehaving-seed-config.yaml b/tools/misbehaving-jmx-server/misbehaving-seed-config.yaml new file mode 100644 index 000000000..46e944889 --- /dev/null +++ b/tools/misbehaving-jmx-server/misbehaving-seed-config.yaml @@ -0,0 +1 @@ +seed: 12345 \ No newline at end of file diff --git a/tools/misbehaving-jmx-server/src/main/java/org/datadog/misbehavingjmxserver/App.java b/tools/misbehaving-jmx-server/src/main/java/org/datadog/misbehavingjmxserver/App.java index 52072d21e..96cb8e430 100644 --- a/tools/misbehaving-jmx-server/src/main/java/org/datadog/misbehavingjmxserver/App.java +++ b/tools/misbehaving-jmx-server/src/main/java/org/datadog/misbehavingjmxserver/App.java @@ -46,7 +46,7 @@ class AppConfig { public String rmiHost = Defaults.JMXSERVER_RMI_INTERFACE; @Parameter(names = {"--rng-seed", "-rs"}) - public long rngSeed = 1042849; + public Long rngSeed = 54321L; // Can only be set via env var public int controlPort = Defaults.JMXSERVER_CONTROL_PORT; @@ -54,7 +54,11 @@ class AppConfig { @Parameter(names = {"--config-path", "-cfp"}) public String config_path = "./misbehaving-jmx-domains-config.yaml"; + @Parameter(names = {"--seed-config-path", "-scfp"}) + public String seed_config_path = "./misbehaving-seed-config.yaml"; + public JmxDomainConfigurations jmxDomainConfigurations; + public RNGSeedConfiguration rngSeedConfiguration; public void overrideFromEnv() { String val; @@ -80,7 +84,7 @@ public void overrideFromEnv() { } } - public void readConfigFileOnDisk () { + public void readDomainsConfigFileOnDisk () { File f = new File(config_path); String yamlPath = f.getPath(); try{ @@ -93,6 +97,33 @@ public void readConfigFileOnDisk () { jmxDomainConfigurations = null; } } + + public void readSeedConfigFileOnDisk () { + File f = new File(seed_config_path); + String yamlPath = f.getPath(); + try{ + FileInputStream yamlInputStream = new FileInputStream(yamlPath); + Yaml yaml = new Yaml(new Constructor(RNGSeedConfiguration.class)); + rngSeedConfiguration = yaml.load(yamlInputStream); + log.info("RNGSeed configuration read from " + seed_config_path + " is:\n" + rngSeedConfiguration); + } catch (FileNotFoundException e) { + log.warn("Could not find your config file at " + yamlPath); + rngSeedConfiguration = null; + } + } +} + +class RNGSeedConfiguration { + public Long seed; + + @Override + public String toString() { + if (seed != null) { + return "RNG Seed: " + seed; + } + return "No seed specified in seed configuration file"; + } + } class JmxDomainConfigurations { @@ -158,7 +189,8 @@ public static void main( String[] args ) throws IOException, MalformedObjectName jCommander.usage(); System.exit(1); } - config.readConfigFileOnDisk(); + config.readDomainsConfigFileOnDisk(); + config.readSeedConfigFileOnDisk(); InterruptibleRMISocketFactory customRMISocketFactory = new InterruptibleRMISocketFactory(); // I don't think this call is actually important for jmx, the below 'env' param to JMXConnectorServerFactory is the important one @@ -175,6 +207,10 @@ public static void main( String[] args ) throws IOException, MalformedObjectName MetricDAO mDao = new MetricDAO(); mDao.runTickLoop(); + // rng seed config file overrides flag + if (config.rngSeedConfiguration != null) { + config.rngSeed = config.rngSeedConfiguration.seed; + } BeanManager bm = new BeanManager(mbs, mDao, config.rngSeed); // Set up test domain