Code

t/integration: Add a simple time-series fetcher test.
authorSebastian Harl <sh@tokkee.org>
Fri, 16 Jan 2015 20:22:06 +0000 (21:22 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 16 Jan 2015 20:22:06 +0000 (21:22 +0100)
t/integration/config.sh
t/integration/filter.sh
t/integration/matching.sh
t/integration/mock_plugin.c
t/integration/query.sh
t/integration/test_lib.sh

index 3bdb10490915912190c4e7b46070a6342e6de6b4..b25e9502988bf310664b4f39365e22c39e1146df 100755 (executable)
@@ -91,3 +91,4 @@ wait_for_sysdbd
 
 stop_sysdbd
 
+# vim: set tw=78 sw=4 ts=4 noexpandtab :
index da75b9aa5312bbe7ae50dfe2085efcd1c8b78cbe..ddcf78532bbee17d85852c367b95f0155a15ab14 100755 (executable)
@@ -77,3 +77,4 @@ echo $output | grep -E '^\[\]$'
 
 stop_sysdbd
 
+# vim: set tw=78 sw=4 ts=4 noexpandtab :
index 8b25ed3cc062627115f32bdb45e62abde3a54b66..34e7c549b9005a067bb9f643981e749089614f03 100755 (executable)
@@ -117,3 +117,4 @@ echo $output | grep -E '^\[\]$'
 
 stop_sysdbd
 
+# vim: set tw=78 sw=4 ts=4 noexpandtab :
index 1fb59fc1f39dbca0b248cbf3ab28ef236c92c3c5..8041c0dfab9a4e1af2b5132d886528642ec5c27d 100644 (file)
@@ -57,21 +57,21 @@ static struct {
        sdb_metric_store_t store;
 } metrics[] = {
        { "some.host.name", "foo/bar/qux",
-               { "dummy", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } },
        { "some.host.name", "foo/bar/baz",
-               { "dummy", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } },
        { "some.host.name", "foo2/bar/qux",
-               { "dummy", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } },
        { "some.host.name", "foo2/bar/baz",
-               { "dummy", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } },
        { "other.host.name", "foo/bar/qux",
-               { "dummy", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } },
        { "other.host.name", "foo/bar/baz",
-               { "dummy", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } },
        { "other.host.name", "foo2/bar/qux",
-               { "dummy", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } },
        { "other.host.name", "foo2/bar/baz",
-               { "dummy", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } },
+               { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } },
 };
 
 static struct {
@@ -192,6 +192,42 @@ mock_collect(sdb_object_t *user_data)
        return 0;
 } /* mock_collect */
 
+static sdb_timeseries_t *
+mock_fetch_ts(const char *id, sdb_timeseries_opts_t *opts,
+               sdb_object_t *user_data)
+{
+       sdb_timeseries_t *ts;
+       const char *names[] = { "nameA", "nameB" };
+       size_t i, j;
+
+       if (*id != '/') {
+               sdb_log(SDB_LOG_ERR, "mock::plugin: Invalid time-series %s", id);
+               exit(1);
+       }
+
+       if (SDB_OBJ_WRAPPER(user_data)->data != MAGIC_DATA) {
+               sdb_log(SDB_LOG_ERR, "mock::plugin: Invalid user data %p "
+                               "passed to collect", SDB_OBJ_WRAPPER(user_data)->data);
+               exit(1);
+       }
+
+       ts = sdb_timeseries_create(SDB_STATIC_ARRAY_LEN(names), names, 10);
+       if (! ts)
+               return NULL;
+
+       ts->start = opts->start;
+       ts->end = opts->end;
+
+       for (i = 0; i < 10; ++i) {
+               for (j = 0; j < SDB_STATIC_ARRAY_LEN(names); ++j) {
+                       ts->data[j][i].timestamp = ts->start
+                               + i * (ts->end - ts->start) / 10;
+                       ts->data[j][i].value = (double)(i + j);
+               }
+       }
+       return ts;
+} /* mock_fetch_ts */
+
 static int
 mock_config(oconfig_item_t *ci)
 {
@@ -220,6 +256,8 @@ mock_config(oconfig_item_t *ci)
        sdb_plugin_register_collector("main", mock_collect,
                        /* interval = */ NULL, user_data);
 
+       sdb_plugin_register_ts_fetcher("mock", mock_fetch_ts, user_data);
+
        sdb_object_deref(user_data);
        return 0;
 } /* mock_config */
index eb4ccd8814771f058f6a9a357f1b669f5803b5e5..b2e6ed82a644074cb3745b58b3d45e388a471313 100755 (executable)
@@ -115,8 +115,20 @@ run_sysdb -H "$SOCKET_FILE" \
                -c "TIMESERIES 'invalid.host'.'invalid-metric'" && exit 1
 
 # Does not work yet since there is no fetcher plugin.
-run_sysdb -H "$SOCKET_FILE" \
-               -c "TIMESERIES 'some.host.name'.'foo/bar/qux'" && exit 1
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "TIMESERIES 'some.host.name'.'foo/bar/qux'" )"
+echo "$output" \
+       | grep -F '"value": "1.000000"' \
+       | grep -F '"value": "2.000000"' \
+       | grep -F '"value": "3.000000"' \
+       | grep -F '"value": "4.000000"' \
+       | grep -F '"value": "5.000000"' \
+       | grep -F '"value": "6.000000"' \
+       | grep -F '"value": "7.000000"' \
+       | grep -F '"value": "8.000000"' \
+       | grep -F '"value": "9.000000"' \
+       | grep -F '"value": "10.000000"'
 
 stop_sysdbd
 
+# vim: set tw=78 sw=4 ts=4 noexpandtab :
index f6898e4678a9359e7e3b78949e095f8d2f36e9fc..8206ddfd5d21bad444dbf3a40b395556ebd59a02 100644 (file)
@@ -94,3 +94,4 @@ function wait_for_sysdbd() {
        fi
 }
 
+# vim: set tw=78 sw=4 ts=4 noexpandtab :