Skip to content

Commit

Permalink
Merge pull request #181 from go-faster/feat/metrics
Browse files Browse the repository at this point in the history
feat(metricstorage): add schema for metrics
  • Loading branch information
ernado authored Nov 12, 2023
2 parents 388864d + d289d55 commit bc9b85a
Show file tree
Hide file tree
Showing 45 changed files with 6,209 additions and 357 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ issues:
source: "return x != x"
text: "dupSubExpr"

# False positive.
- path: internal/metricsharding/prometheus\.go
linters: [govet]
text: "method Seek"

# Not gonna use const, does not make any sense.
- path: internal/ytstorage
linters: [goconst]
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ test_fast:

tidy:
go mod tidy

yt-metric-bench:
KO_DOCKER_REPO=cloud-registry.odkl.ru/dash/resource-dashboard/moc
16 changes: 16 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ tasks:
cmds:
- go build -o ./oteldb ./cmd/oteldb

yt-metric-bench:local:
desc: Build and push the yt-metric-bench image
env:
KO_DOCKER_REPO: "ghcr.io/go-faster/oteldb"
KO_DEFAULTBASEIMAGE: "ubuntu:latest"
cmds:
- ko build -B --local ./cmd/yt-metric-bench

yt-metric-bench:push:
desc: Build and push the yt-metric-bench image
env:
KO_DOCKER_REPO: "ghcr.io/go-faster/oteldb"
KO_DEFAULTBASEIMAGE: "ubuntu:latest"
cmds:
- ko build -B ./cmd/yt-metric-bench

test:
desc: Run tests
env:
Expand Down
177 changes: 150 additions & 27 deletions _oas/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ paths:
schema:
type: string
- name: time
description: Evaluation timestamp
description: Evaluation timestamp.
in: query
schema:
$ref: "#/components/schemas/PrometheusTimestamp"
- name: lookback_delta
description: Lookback delta duration in duration format or float number of seconds.
in: query
schema:
type: string
- name: stats
description: Statistics to return.
in: query
schema:
type: string
responses:
200:
$ref: "#/components/responses/QueryResponse"
Expand All @@ -38,7 +48,7 @@ paths:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/QueryForm'
$ref: "#/components/schemas/QueryForm"
responses:
200:
$ref: "#/components/responses/QueryResponse"
Expand Down Expand Up @@ -74,13 +84,17 @@ paths:
required: true
schema:
type: string
description: Prometheus duration or float
- name: timeout
description: Evaluation timeout.
description: Prometheus duration or float.
- name: lookback_delta
description: Lookback delta duration in duration format or float number of seconds.
in: query
required: false
schema:
$ref: "#/components/schemas/PrometheusDuration"
type: string
- name: stats
description: Statistics to return.
in: query
schema:
type: string
responses:
200:
$ref: "#/components/responses/QueryResponse"
Expand All @@ -94,7 +108,7 @@ paths:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/QueryRangeForm'
$ref: "#/components/schemas/QueryRangeForm"
responses:
200:
$ref: "#/components/responses/QueryResponse"
Expand Down Expand Up @@ -146,13 +160,11 @@ paths:
- name: start
description: Start timestamp.
in: query
required: true
schema:
$ref: "#/components/schemas/PrometheusTimestamp"
- name: end
description: End timestamp.
in: query
required: true
schema:
$ref: "#/components/schemas/PrometheusTimestamp"
- name: match[]
Expand All @@ -172,6 +184,12 @@ paths:
post:
operationId: postSeries
description: Query Prometheus
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
$ref: "#/components/schemas/SeriesForm"
responses:
200:
$ref: "#/components/responses/SeriesResponse"
Expand Down Expand Up @@ -206,6 +224,12 @@ paths:
$ref: "#/components/responses/Error"
post:
operationId: postLabels
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
$ref: "#/components/schemas/LabelsForm"
responses:
200:
$ref: "#/components/responses/LabelsResponse"
Expand Down Expand Up @@ -486,36 +510,64 @@ components:
type: string
time:
$ref: "#/components/schemas/PrometheusTimestamp"
lookback_delta:
type: string
stats:
type: string
QueryRangeForm:
type: object
required: [query, start, end, step]
properties:
query:
type: string
description: Prometheus expression query string.
time:
$ref: "#/components/schemas/PrometheusTimestamp"
start:
$ref: "#/components/schemas/PrometheusTimestamp"
end:
$ref: "#/components/schemas/PrometheusTimestamp"
step:
type: string
description: Query resolution step width in duration format or float number of seconds.
timeout:
lookback_delta:
type: string
stats:
type: string
LabelsForm:
type: object
properties:
start:
$ref: "#/components/schemas/PrometheusTimestamp"
end:
$ref: "#/components/schemas/PrometheusTimestamp"
match[]:
type: array
items:
type: string
SeriesForm:
type: object
required: ["match[]"]
properties:
start:
$ref: "#/components/schemas/PrometheusTimestamp"
end:
$ref: "#/components/schemas/PrometheusTimestamp"
match[]:
type: array
items:
type: string

Scalar:
type: object
required: [result]
properties:
result:
$ref: "#/components/schemas/Value"
$ref: "#/components/schemas/FPoint"
String:
type: object
required: [result]
properties:
result:
type: string
$ref: "#/components/schemas/StringValue"
Vector:
type: object
required: [result]
Expand All @@ -531,7 +583,7 @@ components:
additionalProperties:
type: string
value:
$ref: "#/components/schemas/Value"
$ref: "#/components/schemas/Sample"
Matrix:
type: object
required: [result]
Expand All @@ -540,7 +592,7 @@ components:
type: array
items:
type: object
required: [metric, values]
required: [metric]
properties:
metric:
type: object
Expand All @@ -549,7 +601,11 @@ components:
values:
type: array
items:
$ref: "#/components/schemas/Value"
$ref: "#/components/schemas/FPoint"
histograms:
type: array
items:
$ref: "#/components/schemas/HPoint"
Data:
discriminator:
propertyName: resultType
Expand All @@ -563,16 +619,86 @@ components:
- $ref: "#/components/schemas/Vector"
- $ref: "#/components/schemas/Scalar"
- $ref: "#/components/schemas/String"
Value:
FPoint:
type: array
items:
- type: number
description: float64 timestamp
description: float64 milli timestamp
x-ogen-name: T
- type: string
description: value
format: float64
x-ogen-name: V
HPoint:
type: array
items:
- type: number
description: float64 milli timestamp
x-ogen-name: T
- $ref: "#/components/schemas/Histogram"
StringValue:
type: array
items:
- type: number
description: float64 milli timestamp
x-ogen-name: T
- type: string
description: value
x-ogen-name: V
Sample:
type: array
items:
- type: number
description: float64 milli timestamp
x-ogen-name: T
- oneOf:
- $ref: "#/components/schemas/Histogram"
- type: string
description: value
format: float64
x-ogen-name: HistogramOrValue
Histogram:
type: object
required: [count, sum]
properties:
count:
type: number
format: float64
sum:
type: number
format: float64
buckets:
type: array
items:
$ref: "#/components/schemas/Bucket"
Bucket:
# See https://github.com/prometheus/prometheus/blob/8e5f0387a2c9115849fcd99c9a0b295b779d938a/util/jsonutil/marshal.go#L66-L89
# as encoding reference.
type: array
items:
- type: integer
description: |
The 1st element in each bucket array determines if the boundaries are
inclusive (AKA closed) or exclusive (AKA open):
```
0: lower exclusive, upper inclusive
1: lower inclusive, upper exclusive
2: both exclusive
3: both inclusive
```
x-ogen-name: BoundaryType
- type: string
description: Lower boundary.
format: float64
x-ogen-name: Lower
- type: string
description: Upper boundary.
format: float64
x-ogen-name: Upper
- type: string
description: Bucket count.
format: float64
x-ogen-name: Count

Exemplars:
type: array
Expand Down Expand Up @@ -657,10 +783,10 @@ components:
Alert:
type: object
required:
- labels
- annotations
- state
- value
- labels
- annotations
- state
- value
properties:
labels:
$ref: "#/components/schemas/LabelSet"
Expand Down Expand Up @@ -805,9 +931,6 @@ components:
PrometheusTimestamp:
type: string
description: RFC3339 or Unix timestamp
PrometheusDuration:
type: string
description: Prometheus duration
LabelSet:
type: object
additionalProperties:
Expand Down
Loading

0 comments on commit bc9b85a

Please sign in to comment.