kairosdb / kairosdb-client

Java Client for KairosDB
65 stars 67 forks source link

Irregular groups alignment #58

Closed gdlx closed 6 years ago

gdlx commented 7 years ago

Hi,

When querying grouped series with non unitary sampling (eg: 2 minutes), some gapped groups returns some points that aren't aligned with ungapped groups timestamps.

Here's a query example:

{
  "metrics": [
    {
      "name": [
        "http.access.count"
      ],
      "aggregators": [
        {
          "name": "sum",
          "sampling": {
            "value": "2",
            "unit": "minutes"
          },
          "align_sampling": true
        }
      ],
      "group_by": [
        {
          "name": "tag",
          "tags": [
            "status_code"
          ]
        }
      ]
    }
  ],
  "cache_time": 0,
  "start_relative": {
    "value": "3",
    "unit": "hours"
  },
  "end_relative": {
    "value": "3",
    "unit": "minutes"
  }
}

This way, I'll get common HTTP codes like 200 that will be sampled every 2 minutes (generally on even ones), but some rare codes that aren't present on every minute will be sampled on the exact minute they appear, which is sometimes an odd minute, creating a timestamp that doesn't exist on full groups.

I thought using align_sampling should align different groups on the same timestamps but it seems not.

Using gaps aggregator doesn't help.

jsabin commented 6 years ago

I think you want startTimeAlignment.

QueryMetric queryMetric = builder.addMetric("foo"); queryMetric.addAggregator(AggregatorFactory.createSumAggregator(1, TimeUnit.MINUTES).withStartTimeAlignment());