Skip to content

Commit

Permalink
feat(felixible aggregation): Expose expression in API (#293)
Browse files Browse the repository at this point in the history
* feat(felixible aggregation): Expose expression in API

* feat(felixible aggregation): Add documentation for expression evaluation endpoint
  • Loading branch information
vincent-pochet authored Nov 14, 2024
1 parent b26bccd commit 16d89f4
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 97 deletions.
172 changes: 134 additions & 38 deletions openapi.yaml

Large diffs are not rendered by default.

120 changes: 61 additions & 59 deletions src/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/resources/billable_metric_evaluate_expression.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
post:
tags:
- billable_metrics
summary: Evaluate an expression for a billable metric
description: Evaluate an expression for a billable metric creation by providing the expression and test data
operationId: evaluateBillableMetricExpression
requestBody:
description: Billable metric expression evaluation payload
content:
application/json:
schema:
$ref: "../schemas/BillableMetricEvaluateExpressionInput.yaml"
required: true
responses:
"200":
description: Billable metric expression evaluation result
content:
application/json:
schema:
$ref: "../schemas/BillableMetricEvaluateExpressionResult.yaml"
"400":
$ref: "../responses/BadRequest.yaml"
"401":
$ref: "../responses/Unauthorized.yaml"
"422":
$ref: "../responses/UnprocessableEntity.yaml"
8 changes: 8 additions & 0 deletions src/schemas/BillableMetricBaseInput.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ properties:
- If set to `true`: the accumulated number of units calculated from the previous billing period is persisted to the next billing period.
- If set to `false`: the accumulated number of units is reset to 0 at the end of the billing period.
- If not defined in the request, default value is `false`.
expression:
type: string
example: "round((ended_at - started_at) * units)"
description: |
Expression used to calculate the event units. The expression is evalutated for each event and the result is then used to calculate the total aggregated units.
Accepted function are `ceil`, `concat` and `round` as well as `+`, `-`, `\` and `*` operations.
Round is accepting an optional second parameter to specify the number of decimal.
nullable: true
field_name:
type: string
example: "gb"
Expand Down
40 changes: 40 additions & 0 deletions src/schemas/BillableMetricEvaluateExpressionInput.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
type: object
required:
- expression
- event
properties:
expression:
type: string
example: "round((ended_at - started_at) * units)"
description: |
Expression used to calculate the event units. The expression is evalutated for each event and the result is then used to calculate the total aggregated units.
Accepted function are `ceil`, `concat` and `round` as well as `+`, `-`, `\` and `*` operations.
Round is accepting an optional second parameter to specify the number of decimal.
event:
type: object
required:
- code
- properties
properties:
code:
type: string
example: "storage"
description: The code that identifies a targeted billable metric.
timestamp:
anyOf:
- type: integer
- type: string
example: "1651240791"
description: |
This field captures the Unix timestamp in seconds indicating the occurrence of the event in Coordinated Universal Time (UTC).
If this timestamp is not provided, the API will automatically set it to the time of event reception.
properties:
type: object
description: This field represents additional properties associated with the event. They can be used when evaluating the expression.
additionalProperties:
oneOf:
- type: string
- type: integer
- type: number
example:
gb: 10
15 changes: 15 additions & 0 deletions src/schemas/BillableMetricEvaluateExpressionResult.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type: object
required:
- expression_result
properties:
expression_result:
type: object
required:
- value
properties:
value:
anyOf:
- type: string
- type: number
example: 1.0
description: "Result of evaluating the expression"
4 changes: 4 additions & 0 deletions src/schemas/BillableMetricObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ properties:
format: "date-time"
example: "2022-09-14T16:35:31Z"
description: "Creation date of the billable metric."
expression:
type: string
example: "round((ended_at - started_at) * units)"
description: "Expression used to calculate the event units. The expression is evalutated for each event and the result is then used to calculate the total aggregated units."
field_name:
type: string
example: "gb"
Expand Down
4 changes: 4 additions & 0 deletions src/schemas/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ BillableMetricBaseInput:
$ref: "./BillableMetricBaseInput.yaml"
BillableMetricCreateInput:
$ref: "./BillableMetricCreateInput.yaml"
BillableMetricEvaluateExpressionInput:
$ref: "./BillableMetricEvaluateExpressionInput.yaml"
BillableMetricEvaluateExpressionResult:
$ref: "./BillableMetricEvaluateExpressionResult.yaml"
BillableMetricFilterInput:
$ref: "./BillableMetricFilterInput.yaml"
BillableMetricFilterObject:
Expand Down

0 comments on commit 16d89f4

Please sign in to comment.