Exemplo n.º 1
0
  /**
   * Attempts to load a configuration given a file or default files and overrides with command line
   * arguments
   *
   * @return A config object with user settings or defaults
   * @throws IOException If there was an error opening any of the config files
   * @throws FileNotFoundException If the user provided config file was not found
   * @since 2.0
   */
  static final Config getConfig(final ArgP argp) throws IOException {
    // load configuration
    final Config config;
    final String config_file = argp.get("--config", "");
    if (!config_file.isEmpty()) config = new Config(config_file);
    else config = new Config(true);

    // load CLI overloads
    overloadConfig(argp, config);
    // the auto metric is recorded to a class boolean flag since it's used so
    // often. We have to set it manually after overriding.
    config.setAutoMetric(config.getBoolean("tsd.core.auto_create_metrics"));
    return config;
  }
Exemplo n.º 2
0
 @Test(expected = RuntimeException.class)
 public void initializePluginsPathBad() throws Exception {
   Field properties = config.getClass().getDeclaredField("properties");
   properties.setAccessible(true);
   @SuppressWarnings("unchecked")
   HashMap<String, String> props = (HashMap<String, String>) properties.get(config);
   props.put("tsd.core.plugin_path", "./doesnotexist");
   properties.setAccessible(false);
   tsdb.initializePlugins(true);
 }
Exemplo n.º 3
0
 @Test(expected = RuntimeException.class)
 public void initializePluginsSearchNotFound() throws Exception {
   Field properties = config.getClass().getDeclaredField("properties");
   properties.setAccessible(true);
   @SuppressWarnings("unchecked")
   HashMap<String, String> props = (HashMap<String, String>) properties.get(config);
   props.put("tsd.search.enable", "true");
   props.put("tsd.search.plugin", "net.opentsdb.search.DoesNotExist");
   properties.setAccessible(false);
   tsdb.initializePlugins(true);
 }
Exemplo n.º 4
0
 @Test
 public void initializePluginsSearch() throws Exception {
   Field properties = config.getClass().getDeclaredField("properties");
   properties.setAccessible(true);
   @SuppressWarnings("unchecked")
   HashMap<String, String> props = (HashMap<String, String>) properties.get(config);
   props.put("tsd.core.plugin_path", "./");
   props.put("tsd.search.enable", "true");
   props.put("tsd.search.plugin", "net.opentsdb.search.DummySearchPlugin");
   props.put("tsd.search.DummySearchPlugin.hosts", "localhost");
   props.put("tsd.search.DummySearchPlugin.port", "42");
   properties.setAccessible(false);
   tsdb.initializePlugins(true);
 }
Exemplo n.º 5
0
  @Before
  public void before() throws Exception {
    config = mock(Config.class);
    when(config.getString("tsd.storage.hbase.data_table")).thenReturn("tsdb");
    when(config.getString("tsd.storage.hbase.uid_table")).thenReturn("tsdb-uid");
    when(config.getString("tsd.storage.hbase.meta_table")).thenReturn("tsdb-meta");
    when(config.getString("tsd.storage.hbase.tree_table")).thenReturn("tsdb-tree");
    when(config.enable_tsuid_incrementing()).thenReturn(true);
    when(config.enable_realtime_ts()).thenReturn(true);

    PowerMockito.whenNew(HBaseClient.class)
        .withArguments(anyString(), anyString())
        .thenReturn(client);
    tsdb = new TSDB(config);
    storage = new MockBase(tsdb, client, true, true, true, true, true);

    storage.addColumn(
        new byte[] {0, 0, 1},
        NAME_FAMILY,
        "metrics".getBytes(MockBase.ASCII()),
        "sys.cpu.0".getBytes(MockBase.ASCII()));
    storage.addColumn(
        new byte[] {0, 0, 1},
        NAME_FAMILY,
        "metric_meta".getBytes(MockBase.ASCII()),
        ("{\"uid\":\"000001\",\"type\":\"METRIC\",\"name\":\"sys.cpu.0\","
                + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":"
                + "1328140801,\"displayName\":\"System CPU\"}")
            .getBytes(MockBase.ASCII()));

    storage.addColumn(
        new byte[] {0, 0, 1},
        NAME_FAMILY,
        "tagk".getBytes(MockBase.ASCII()),
        "host".getBytes(MockBase.ASCII()));
    storage.addColumn(
        new byte[] {0, 0, 1},
        NAME_FAMILY,
        "tagk_meta".getBytes(MockBase.ASCII()),
        ("{\"uid\":\"000001\",\"type\":\"TAGK\",\"name\":\"host\","
                + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":"
                + "1328140801,\"displayName\":\"Host server name\"}")
            .getBytes(MockBase.ASCII()));

    storage.addColumn(
        new byte[] {0, 0, 1},
        NAME_FAMILY,
        "tagv".getBytes(MockBase.ASCII()),
        "web01".getBytes(MockBase.ASCII()));
    storage.addColumn(
        new byte[] {0, 0, 1},
        NAME_FAMILY,
        "tagv_meta".getBytes(MockBase.ASCII()),
        ("{\"uid\":\"000001\",\"type\":\"TAGV\",\"name\":\"web01\","
                + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":"
                + "1328140801,\"displayName\":\"Web server 1\"}")
            .getBytes(MockBase.ASCII()));

    storage.addColumn(
        new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1},
        NAME_FAMILY,
        "ts_meta".getBytes(MockBase.ASCII()),
        ("{\"tsuid\":\"000001000001000001\",\""
                + "description\":\"Description\",\"notes\":\"Notes\",\"created\":1328140800,"
                + "\"custom\":null,\"units\":\"\",\"retention\":42,\"max\":1.0,\"min\":"
                + "\"NaN\",\"displayName\":\"Display\",\"dataType\":\"Data\"}")
            .getBytes(MockBase.ASCII()));
    storage.addColumn(
        new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1},
        NAME_FAMILY,
        "ts_ctr".getBytes(MockBase.ASCII()),
        Bytes.fromLong(1L));
  }
Exemplo n.º 6
0
  /**
   * Copies the parsed command line options to the {@link Config} class
   *
   * @param config Configuration instance to override
   * @since 2.0
   */
  static void overloadConfig(final ArgP argp, final Config config) {

    // loop and switch so we can map cli options to tsdb options
    for (Map.Entry<String, String> entry : argp.getParsed().entrySet()) {
      // map the overrides
      if (entry.getKey().toLowerCase().equals("--auto-metric")) {
        config.overrideConfig("tsd.core.auto_create_metrics", "true");
      } else if (entry.getKey().toLowerCase().equals("--table")) {
        config.overrideConfig("tsd.storage.hbase.data_table", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--uidtable")) {
        config.overrideConfig("tsd.storage.hbase.uid_table", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--zkquorum")) {
        config.overrideConfig("tsd.storage.hbase.zk_quorum", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--zkbasedir")) {
        config.overrideConfig("tsd.storage.hbase.zk_basedir", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--port")) {
        config.overrideConfig("tsd.network.port", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--staticroot")) {
        config.overrideConfig("tsd.http.staticroot", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--cachedir")) {
        config.overrideConfig("tsd.http.cachedir", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--flush-interval")) {
        config.overrideConfig("tsd.core.flushinterval", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--backlog")) {
        config.overrideConfig("tsd.network.backlog", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--bind")) {
        config.overrideConfig("tsd.network.bind", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--async-io")) {
        config.overrideConfig("tsd.network.async_io", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--worker-threads")) {
        config.overrideConfig("tsd.network.worker_threads", entry.getValue());
      } else if (entry.getKey().toLowerCase().equals("--fix")) {
        System.setProperty("tsd.core.auto_heal_metrics", "true");
      }
    }
  }