gnocchixyz / gnocchi

Timeseries database
Apache License 2.0
299 stars 85 forks source link

Unexpected fractions in result of `aggregate` difference between two metrics #1355

Open dbalagansky opened 11 months ago

dbalagansky commented 11 months ago

Which version of Gnocchi are you using

master

How to reproduce your problem

fixtures:
    - ConfigFixture

defaults:
  request_headers:
    content-type: application/json
    # User foobar
    authorization: "basic Zm9vYmFyOg=="

tests:
    - name: create archive policy
      desc: for later use
      POST: /v1/archive_policy
      request_headers:
        # User admin
        authorization: "basic YWRtaW46"
      data:
          name: low
          definition:
              - granularity: 1 second
              - granularity: 300 seconds
      status: 201

# Aggregation by metric ids

    - name: create metric 1
      POST: /v1/metric
      request_headers:
          content-type: application/json
      data:
        archive_policy_name: low
      status: 201

    - name: create metric 2
      POST: /v1/metric
      request_headers:
          content-type: application/json
      data:
        archive_policy_name: low
      status: 201

    - name: get metric list
      GET: /v1/metric

    - name: push measurements to metric 1
      POST: /v1/metric/$RESPONSE['$[0].id']/measures
      request_headers:
           content-type: application/json
      data:
          - timestamp: "2015-03-06T14:33:57"
            value: 43.7
          - timestamp: "2015-03-06T14:34:12"
            value: 12
      status: 202

    - name: push measurements to metric 2
      POST: /v1/metric/$HISTORY['get metric list'].$RESPONSE['$[1].id']/measures
      request_headers:
           content-type: application/json
      data:
          - timestamp: "2015-03-06T14:33:57"
            value: 3.1
          - timestamp: "2015-03-06T14:34:12"
            value: 2
          - timestamp: "2015-03-06T14:35:12"
            value: 5
      status: 202

    - name: GET measure aggregates by granularity with refresh
      GET: /v1/aggregation/metric?metric=$HISTORY['get metric list'].$RESPONSE['$[0].id']&metric=$HISTORY['get metric list'].$RESPONSE['$[1].id']&granularity=1&refresh=true
      response_json_paths:
        $:
          - ['2015-03-06T14:33:57+00:00', 1.0, 23.4]
          - ['2015-03-06T14:34:12+00:00', 1.0, 7.0]

    - name: get measure aggregates difference with default fill
      POST: /v1/aggregates?granularity=1
      data:
        operations: "(aggregate mean (- (metric $HISTORY['get metric list'].$RESPONSE['$[0].id'] mean) (metric $HISTORY['get metric list'].$RESPONSE['$[1].id'] mean)))"
      response_json_paths:
        $.measures.aggregated:
          - ['2015-03-06T14:33:57+00:00', 1.0, 40.6]
          - ['2015-03-06T14:34:12+00:00', 1.0, 10.0]

What is the result that you get

Test get measure aggregates difference with default fill fails:

    AssertionError: Lists differ: [['20[29 chars], 23.4], ['2015-03-06T14:34:12+00:00', 1.0, 7.0]] != [['20[29 chars], 23.400000000000002], ['2015-03-06T14:34:12+00:00', 1.0, 7.0]]

First differing element 0:
['2015-03-06T14:33:57+00:00', 1.0, 23.4]
['2015-03-06T14:33:57+00:00', 1.0, 23.400000000000002]

- [['2015-03-06T14:33:57+00:00', 1.0, 23.4],
+ [['2015-03-06T14:33:57+00:00', 1.0, 23.400000000000002],
?                                         ++++++++++++++

   ['2015-03-06T14:34:12+00:00', 1.0, 7.0]] : Unable to match $ as [['2015-03-06T14:33:57+00:00', 1.0, 23.4], ['2015-03-06T14:34:12+00:00', 1.0, 7.0]], got [['2015-03-06T14:33:57+00:00', 1.0, 23.400000000000002], ['2015-03-06T14:34:12+00:00', 1.0, 7.0]]

Using the value less than 43.7 in the first mesurement of the first metric (and consequently changing all other values in tests) would allow this test to pass.

What is result that you expected

Test passes :)