Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
authorSebastian Harl <sh@tokkee.org>
Fri, 15 May 2015 20:53:44 +0000 (22:53 +0200)
committerSebastian Harl <sh@tokkee.org>
Fri, 15 May 2015 20:53:44 +0000 (22:53 +0200)
1  2 
src/core/store.c
t/unit/frontend/query_test.c

Simple merge
index 3e43c0a64290e6c5d789dd0fbeb1736e8befc10c,73f3042ee9516a8605346393ab4ca456cdb2dd5c..7e15502096a04ed83358c1fb41f5aab8e14c098a
@@@ -96,30 -99,22 +99,38 @@@ populate(void
                                                "\"update_interval\": \"0s\", \"backends\": []}]}," \
                        "{\"name\": \"m2\", \"timeseries\": false, " \
                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
-                               "\"update_interval\": \"0s\", \"backends\": []}]}"
+                               "\"update_interval\": \"0s\", \"backends\": [], " \
+                               "\"attributes\": [" \
+                                       "{\"name\": \"hostname\", \"value\": \"h1\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 +#define HOST_H1_ARRAY "["HOST_H1"]"
 +#define HOST_H1_LISTING \
 +      "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                      "\"update_interval\": \"0s\", \"backends\": []}"
 +#define HOST_H2_LISTING \
 +      "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                      "\"update_interval\": \"0s\", \"backends\": []}"
  
  #define SERVICE_H2_S1 \
        "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"services\": [" \
                        "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
-                               "\"update_interval\": \"0s\", \"backends\": []}]}"
+                               "\"update_interval\": \"0s\", \"backends\": [], " \
+                               "\"attributes\": [" \
+                                       "{\"name\": \"hostname\", \"value\": \"h2\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 +#define SERVICE_H2_S1_ARRAY "["SERVICE_H2_S1"]"
 +#define SERVICE_H2_S12_LISTING \
 +      "[{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                      "\"update_interval\": \"0s\", \"backends\": [], " \
 +              "\"services\": [" \
 +                      "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                              "\"update_interval\": \"0s\", \"backends\": []}," \
 +                      "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                              "\"update_interval\": \"0s\", \"backends\": []}]}]"
  
  #define METRIC_H1_M1 \
        "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
                                        "{\"name\": \"k3\", \"value\": 42, " \
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
-                               "\"update_interval\": \"0s\", \"backends\": []}]}]"
 +#define METRIC_H12_M1_ARRAY \
 +      "["METRIC_H1_M1"," \
 +      "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                      "\"update_interval\": \"0s\", \"backends\": [], " \
 +              "\"metrics\": [" \
 +                      "{\"name\": \"m1\", \"timeseries\": false, " \
 +                              "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
++                              "\"update_interval\": \"0s\", \"backends\": [], " \
++                              "\"attributes\": [" \
++                                      "{\"name\": \"hostname\", \"value\": \"h2\", " \
++                                              "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
++                                              "\"update_interval\": \"0s\", \"backends\": []}]}]}]"
 +#define METRIC_H12_M12_LISTING \
 +      "[{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                      "\"update_interval\": \"0s\", \"backends\": [], " \
 +              "\"metrics\": [" \
 +                      "{\"name\": \"m1\", \"timeseries\": false, " \
 +                              "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                              "\"update_interval\": \"0s\", \"backends\": []}," \
 +                      "{\"name\": \"m2\", \"timeseries\": false, " \
 +                              "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                              "\"update_interval\": \"0s\", \"backends\": []}]}," \
 +      "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                      "\"update_interval\": \"0s\", \"backends\": [], " \
 +              "\"metrics\": [" \
 +                      "{\"name\": \"m1\", \"timeseries\": false, " \
 +                              "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
 +                              "\"update_interval\": \"0s\", \"backends\": []}]}]"
  
  typedef struct {
        sdb_conn_t conn;
@@@ -270,243 -248,86 +288,243 @@@ static struct 
        int expected;
        uint32_t code;
        size_t len;
 +      uint32_t type;
        const char *data;
 -} exec_fetch_data[] = {
 +} query_data[] = {
        /* hosts */
        {
 -              SDB_HOST, "h1", NULL, NULL,
 -              0, SDB_CONNECTION_DATA, 1110, HOST_H1,
 +              "LIST hosts",
 +              0, SDB_CONNECTION_DATA, 205, SDB_CONNECTION_LIST,
 +              "["HOST_H1_LISTING","HOST_H2_LISTING"]",
        },
        {
 -              SDB_HOST, "h1", NULL, "age >= 0s", /* always matches */
 -              0, SDB_CONNECTION_DATA, 1110, HOST_H1,
 +              "LIST hosts; LIST hosts", /* ignore second (and later) commands */
 +              0, SDB_CONNECTION_DATA, 205, SDB_CONNECTION_LIST,
 +              "["HOST_H1_LISTING","HOST_H2_LISTING"]",
        },
        {
 -              SDB_HOST, "h1", NULL, "age < 0s", /* never matches */
 -              -1, UINT32_MAX, 0, NULL, /* FETCH fails if the object doesn't exist */
 +              "LIST hosts FILTER name = 'h1'",
 +              0, SDB_CONNECTION_DATA, 105, SDB_CONNECTION_LIST, "["HOST_H1_LISTING"]",
        },
        {
 -              SDB_HOST, "x1", NULL, NULL, /* does not exist */
 -              -1, UINT32_MAX, 0, NULL,
 +              "LIST hosts FILTER name = 's1'",
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LIST, "[]",
        },
        {
 -              SDB_HOST, "h1", "s1", NULL, /* invalid args */
 -              -1, UINT32_MAX, 0, NULL,
 +              "FETCH host 'h1'",
-               0, SDB_CONNECTION_DATA, 851, SDB_CONNECTION_FETCH, HOST_H1,
++              0, SDB_CONNECTION_DATA, 1110, SDB_CONNECTION_FETCH, HOST_H1,
 +      },
 +      {
 +              "LOOKUP hosts MATCHING name = 'h1'",
-               0, SDB_CONNECTION_DATA, 853, SDB_CONNECTION_LOOKUP, HOST_H1_ARRAY,
++              0, SDB_CONNECTION_DATA, 1112, SDB_CONNECTION_LOOKUP, HOST_H1_ARRAY,
 +      },
 +      {
 +              "FETCH host 'h1' FILTER age >= 0s", /* always matches */
-               0, SDB_CONNECTION_DATA, 851, SDB_CONNECTION_FETCH, HOST_H1,
++              0, SDB_CONNECTION_DATA, 1110, SDB_CONNECTION_FETCH, HOST_H1,
 +      },
 +      {
 +              "LOOKUP hosts MATCHING name = 'h1' FILTER age >= 0s", /* always matches */
-               0, SDB_CONNECTION_DATA, 853, SDB_CONNECTION_LOOKUP, HOST_H1_ARRAY,
++              0, SDB_CONNECTION_DATA, 1112, SDB_CONNECTION_LOOKUP, HOST_H1_ARRAY,
 +      },
 +      {
 +              "FETCH host 'h1' FILTER age < 0s", /* never matches */
 +              -1, UINT32_MAX, 0, 0, NULL, /* FETCH fails if the object doesn't exist */
 +      },
 +      {
 +              "LOOKUP hosts MATCHING name = 'h1' FILTER age < 0s", /* never matches */
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]",
 +      },
 +      {
 +              "FETCH host 'x1'", /* does not exist */
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "LOOKUP hosts MATCHING name = 'x1'", /* does not exist */
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]",
 +      },
 +      {
 +              "FETCH host 'h1'.'s1'", /* invalid args */
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "LOOKUP hosts BY name = 'x1'", /* does not exist */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        /* services */
        {
 -              SDB_SERVICE, "h2", "s1", NULL,
 -              0, SDB_CONNECTION_DATA, 356, SERVICE_H2_S1,
 +              "LIST services",
 +              0, SDB_CONNECTION_DATA, 320, SDB_CONNECTION_LIST, SERVICE_H2_S12_LISTING,
 +      },
 +      {
 +              "LIST services FILTER host.name = 'h2'",
 +              0, SDB_CONNECTION_DATA, 320, SDB_CONNECTION_LIST, SERVICE_H2_S12_LISTING,
 +      },
 +      {
 +              "LIST services FILTER host.name = 'h1'",
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LIST, "[]",
 +      },
 +      {
 +              "FETCH service 'h2'.'s1'",
-               0, SDB_CONNECTION_DATA, 218, SDB_CONNECTION_FETCH, SERVICE_H2_S1,
++              0, SDB_CONNECTION_DATA, 356, SDB_CONNECTION_FETCH, SERVICE_H2_S1,
 +      },
 +      {
 +              "LOOKUP services MATCHING name = 's1'",
-               0, SDB_CONNECTION_DATA, 220, SDB_CONNECTION_LOOKUP, SERVICE_H2_S1_ARRAY,
++              0, SDB_CONNECTION_DATA, 358, SDB_CONNECTION_LOOKUP, SERVICE_H2_S1_ARRAY,
 +      },
 +      {
 +              "FETCH service 'h2'.'s1' FILTER age >= 0s", /* always matches */
-               0, SDB_CONNECTION_DATA, 218, SDB_CONNECTION_FETCH, SERVICE_H2_S1,
++              0, SDB_CONNECTION_DATA, 356, SDB_CONNECTION_FETCH, SERVICE_H2_S1,
 +      },
 +      {
 +              "LOOKUP services MATCHING name = 's1' FILTER age >= 0s", /* always matches */
-               0, SDB_CONNECTION_DATA, 220, SDB_CONNECTION_LOOKUP, SERVICE_H2_S1_ARRAY,
++              0, SDB_CONNECTION_DATA, 358, SDB_CONNECTION_LOOKUP, SERVICE_H2_S1_ARRAY,
        },
        {
 -              SDB_SERVICE, "h2", "s1", "age >= 0s", /* always matches */
 -              0, SDB_CONNECTION_DATA, 356, SERVICE_H2_S1,
 +              "FETCH service 'h2'.'s1' FILTER age < 0s", /* never matches */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        {
 -              SDB_SERVICE, "h2", "s1", "age < 0s", /* never matches */
 -              -1, UINT32_MAX, 0, NULL,
 +              "LOOKUP services MATCHING name = 's1' FILTER age < 0s", /* never matches */
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]",
        },
        {
 -              SDB_SERVICE, "h2", "s1", "name = 'h2'", /* only matches host */
 -              -1, UINT32_MAX, 0, NULL,
 +              "FETCH service 'h2'.'s1' FILTER name = 'h2'", /* only matches host */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        {
 -              SDB_SERVICE, "h2", "x1", NULL, /* does not exist */
 -              -1, UINT32_MAX, 0, NULL,
 +              "LOOKUP services MATCHING name = 's1' FILTER name = 'h2'", /* only matches host */
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]",
        },
        {
 -              SDB_SERVICE, "x2", "s1", NULL, /* does not exist */
 -              -1, UINT32_MAX, 0, NULL,
 +              "FETCH service 'h2'.'x1'", /* does not exist */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        {
 -              SDB_SERVICE, "h2", NULL, NULL, /* invalid args */
 -              -1, UINT32_MAX, 0, NULL,
 +              "FETCH service 'x2'.'s1'", /* does not exist */
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "FETCH service 'h2'", /* invalid args */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        /* metrics */
        {
 -              SDB_METRIC, "h1", "m1", NULL,
 -              0, SDB_CONNECTION_DATA, 489, METRIC_H1_M1,
 +              "LIST metrics",
 +              0, SDB_CONNECTION_DATA, 596, SDB_CONNECTION_LIST, METRIC_H12_M12_LISTING,
 +      },
 +      {
 +              "LIST metrics FILTER age > 0s",
 +              0, SDB_CONNECTION_DATA, 596, SDB_CONNECTION_LIST, METRIC_H12_M12_LISTING,
 +      },
 +      {
 +              "LIST metrics FILTER age < 0s",
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LIST, "[]",
 +      },
 +      {
 +              "FETCH metric 'h1'.'m1'",
-               0, SDB_CONNECTION_DATA, 368, SDB_CONNECTION_FETCH, METRIC_H1_M1,
++              0, SDB_CONNECTION_DATA, 489, SDB_CONNECTION_FETCH, METRIC_H1_M1,
 +      },
 +      {
 +              "LOOKUP metrics MATCHING name = 'm1'",
-               0, SDB_CONNECTION_DATA, 605, SDB_CONNECTION_LOOKUP, METRIC_H12_M1_ARRAY,
++              0, SDB_CONNECTION_DATA, 864, SDB_CONNECTION_LOOKUP, METRIC_H12_M1_ARRAY,
 +      },
 +      {
 +              "FETCH metric 'h1'.'m1' FILTER age >= 0s", /* always matches */
-               0, SDB_CONNECTION_DATA, 368, SDB_CONNECTION_FETCH, METRIC_H1_M1,
++              0, SDB_CONNECTION_DATA, 489, SDB_CONNECTION_FETCH, METRIC_H1_M1,
 +      },
 +      {
 +              "LOOKUP metrics MATCHING name = 'm1' FILTER age >= 0s", /* always matches */
-               0, SDB_CONNECTION_DATA, 605, SDB_CONNECTION_LOOKUP, METRIC_H12_M1_ARRAY,
++              0, SDB_CONNECTION_DATA, 864, SDB_CONNECTION_LOOKUP, METRIC_H12_M1_ARRAY,
 +      },
 +      {
 +              "FETCH metric 'h1'.'m1' FILTER age < 0s", /* never matches */
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "LOOKUP metrics MATCHING name = 'm1' FILTER age < 0s", /* never matches */
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]",
        },
        {
 -              SDB_METRIC, "h1", "m1", "age >= 0s", /* always matches */
 -              0, SDB_CONNECTION_DATA, 489, METRIC_H1_M1,
 +              "FETCH metric 'h1'.'m1' FILTER name = 'h1'", /* only matches host */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        {
 -              SDB_METRIC, "h1", "m1", "age < 0s", /* never matches */
 -              -1, UINT32_MAX, 0, NULL,
 +              "LOOKUP metrics MATCHING name = 'm1' FILTER name = 'h1'", /* only matches host */
 +              0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]",
        },
        {
 -              SDB_METRIC, "h1", "m1", "name = 'h1'", /* only matches host */
 -              -1, UINT32_MAX, 0, NULL,
 +              "FETCH metric 'h1'.'x1'", /* does not exist */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        {
 -              SDB_METRIC, "h1", "x1", NULL, /* does not exist */
 -              -1, UINT32_MAX, 0, NULL,
 +              "FETCH metric 'x1'.'m1'", /* does not exist */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
        {
 -              SDB_METRIC, "x1", "m1", NULL, /* does not exist */
 -              -1, UINT32_MAX, 0, NULL,
 +              "FETCH metric 'x1'", /* invalid args */
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
 +      /* timeseries */
        {
 -              SDB_METRIC, "x1", NULL, NULL, /* invalid args */
 -              -1, UINT32_MAX, 0, NULL,
 +              "TIMESERIES 'h1'.'m1'",
 +              -1, UINT32_MAX, 0, 0, NULL, /* no data-store available */
 +      },
 +      {
 +              "TIMESERIES 'h1'.'x1'",
 +              -1, UINT32_MAX, 0, 0, NULL, /* does not exist */
 +      },
 +      {
 +              "TIMESERIES 'x1'.'m1'",
 +              -1, UINT32_MAX, 0, 0, NULL, /* does not exist */
 +      },
 +      /* store commands */
 +      {
 +              "STORE host 'hA' LAST UPDATE 01:00",
 +              0, SDB_CONNECTION_OK, 27, 0, "Successfully stored host hA",
 +      },
 +      {
 +              "STORE host 'hA'",
 +              0, SDB_CONNECTION_OK, 27, 0, "Successfully stored host hA",
 +      },
 +      {
 +              "STORE host attribute 'h1'.'aA' 'vA'",
 +              0, SDB_CONNECTION_OK, 40, 0, "Successfully stored host attribute h1.aA",
 +      },
 +      {
 +              "STORE host attribute 'x1'.'aA' 'vA'",
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "STORE service 'h1'.'sA'",
 +              0, SDB_CONNECTION_OK, 33, 0, "Successfully stored service h1.sA",
 +      },
 +      {
 +              "STORE service 'x1'.'sA'",
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "STORE service attribute 'h2'.'s1'.'aA' 'vA'",
 +              0, SDB_CONNECTION_OK, 43, 0, "Successfully stored service attribute s1.aA",
 +      },
 +      {
 +              "STORE service attribute 'h2'.'x1'.'aA' 'vA'",
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "STORE metric 'h1'.'mA'",
 +              0, SDB_CONNECTION_OK, 32, 0, "Successfully stored metric h1.mA",
 +      },
 +      {
 +              "STORE metric 'x1'.'mA'",
 +              -1, UINT32_MAX, 0, 0, NULL,
 +      },
 +      {
 +              "STORE metric attribute 'h1'.'m1'.'aA' 'vA'",
 +              0, SDB_CONNECTION_OK, 42, 0, "Successfully stored metric attribute m1.aA",
 +      },
 +      {
 +              "STORE metric attribute 'h1'.'x1'.'aA' 'vA'",
 +              -1, UINT32_MAX, 0, 0, NULL,
        },
  };