Search code examples
azure-timeseries-insights

Azure TSI aggregateSeries query returns data with inconsistent plotting


I'm using TSI rest API to get aggregation data, when I request data for multiple months with interval of one month ("P1M"), it returns data with inconsistent plotting. Below is my request and response,

Request

{
    "aggregateSeries": {
        "interval": "P1M",
        "searchSpan": {
            "from": "2020-11-01T00:00:00Z",
            "to": "2020-12-31T23:59:59.999Z"
        },
        "timeSeriesId": [
            "MyTSIId"
        ],
        "projectedVariables": [
            "ResultSet"
        ],
        "inlineVariables": {
            "ResultSet": {
                "kind": "numeric",
                "value": {
                    "tsx": "$event.MyData.Double"
                },
                "filter": null,
                "interpolation": null,
                "aggregation": {
                    "tsx": "avg($value)"
                },
                "categories": null,
                "defaultCategory": null
            }
        }
    }
}

Response

{
    "timestamps": [
        "2020-10-03T00:00:00Z",
        "2020-11-02T00:00:00Z",
        "2020-12-02T00:00:00Z"
    ],
    "properties": [
        {
            "values": [
                null,
                2.8,
                null
            ],
            "name": "ResultSet",
            "type": "Double"
        }
    ],
    "progress": 100.0
}

If you look at TSI response it returns 3 records where as I requested data for only 2 months, also plotting of months starts from random date, it's not plotting either starts of month and also not based on from date in searchSpan.

+-----------------------------------------------------+
| TSI Response Plotting  | Expected Response Plotting |
+-----------------------------------------------------+
| "2020-10-03T00:00:00Z" |   "2020-11-01T00:00:00Z"   |
| "2020-11-02T00:00:00Z" |   "2020-12-01T00:00:00Z"   |
| "2020-12-02T00:00:00Z" |                            |
+-----------------------------------------------------+

Is it possible to get expected response from TSI, or is there any workaround, any help is appreciated.


Solution

  • This is by design in TSI. The behavior is explained here.

    "For a specified search span and interval, this API returns an aggregated response per interval per variable for a Time Series ID. The number of intervals in the response dataset is calculated by counting epoch ticks (the number of milliseconds that have elapsed since Unix epoch - Jan 1st, 1970) and dividing the ticks by the interval span size specified in the query. The timestamps returned in the response set are of the left interval boundaries, not of the sampled events from the interval."

    This is a known issue and something that TSI has in it's backlog to fix! You can vote on the Feedback item here.