Files
cloudkitty/doc/source/api-reference/v2/summary/summary.inc
Rafael Weingärtner 6ba9d45ea6 Introduce "response_format" for the V2 summary API
The V2 summary endpoint uses a quite unconventional data format in
the response. Currently, the format is the following:

```
{"total": <number of elements in the response>,
 "results": [array of arrays of data],
 "columns": [array of columns]}
```

To process this, we need to find the index of a column in the column
list, and with this index, we retrieve the data in the array of data
that is found in the array of results. The proposal is to use the
following format in the response.

```
{"total": <number of elements in the response>,
 "results": [array of objects/dictionary]}
```

With this new format, one does not need to consult the index of a
column to retrieve data in one of the entries. We would only need to
retrieve the data in the entry using its column name. Therefore, the
coding feels more natural. To maintain compatibility, this new format
would be only applied when an option is sent to CloudKitty via
`response_format` option.

Depends-on: https://review.opendev.org/c/openstack/cloudkitty/+/793973

Change-Id: I5869d527e6e4655c653b6852d6fb7bebc9d71520
2021-12-02 12:56:37 +00:00

119 lines
2.8 KiB
PHP

================
Summary endpoint
================
Get a rating summary
====================
Get a rating summary for one or several tenants.
.. rest_method:: GET /v2/summary
.. rest_parameters:: summary/summary_parameters.yml
- limit: limit
- offset: offset
- begin: begin
- end: end
- groupby: groupby
- filters: filters
- custom_fields: custom_fields
- response_format: response_format
Status codes
------------
.. rest_status_code:: success http_status.yml
- 200
.. rest_status_code:: error http_status.yml
- 400
- 403
- 405
Response
--------
The response has the following default format (response_format='table'):
.. code-block:: javascript
{
"columns": [
"begin",
"end",
"qty",
"rate",
"group1",
"group2",
],
"results": [
[
"2019-06-01T00:00:00Z",
"2019-07-01T00:00:00Z",
2590.421676635742,
1295.210838317871,
"group1",
"group2",
]
],
"total": 4
}
``total`` is the total amount of found elements. ``columns`` contains the name of
the columns for each element of ``results``. The columns are the four mandatory ones
(``begin``, ``end``, ``qty``, ``rate``) along with each attribute the result is
grouped by.
``format`` is the response format. It can be "table" or "object". The default
response structure is "table", which is presented above. The object structure
uses the following pattern.
.. code-block:: javascript
{
"results": [
{"begin": "2019-06-01T00:00:00Z",
"end": "2019-07-01T00:00:00Z",
"qty": 2590.421676635742,
"rate": 1295.210838317871,
"group1": "group1",
"group2": "group2",
},
],
"total": 4
}
.. note:: It is also possible to group data by time, in order to obtain timeseries.
In order to do this, group by ``time``. No extra column will be added,
but you'll get one entry per collect period in the queried timeframe.
See examples below.
.. rest_parameters:: summary/summary_parameters.yml
- begin: begin_resp
- end: end_resp
- qty: qty_resp
- rate: rate_resp
Response Example
----------------
Grouping by time and project_id:
.. code-block:: shell
curl "http://cloudkitty-api:8889/v2/summary?groupby=time&groupby=project_id&limit=3"
.. literalinclude:: ./api_samples/summary/summary_get_groupby_time.json
:language: javascript
.. code-block:: shell
curl "http://cloudkitty-api:8889/v2/summary?filters=project_id%3Afe9c35372db6420089883805b37a34af&groupby=type&groupby=project_id"
.. literalinclude:: ./api_samples/summary/summary_get.json
:language: javascript