Skip to content

Commit

Permalink
rest api: 2 new endpoints (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkremser authored Nov 27, 2024
2 parents 8edc7b1 + 39f290b commit c4e5744
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ generate: codegen-tags codegen ## Generate code DeepCopy, DeepCopyInto, and Deep
.PHONY: codegen-tags
codegen-tags: gomodifytags ## Generate json tags for certain structs.
$(GO_MODIFY_TAGS) -file rest/api.go -struct MetricDataPayload -add-tags json -transform camelcase -quiet -w
$(GO_MODIFY_TAGS) -file rest/api.go -struct OperationResult -add-tags json -transform camelcase -quiet -w
$(GO_MODIFY_TAGS) -file rest/api.go -struct QueryRequest -add-tags json -transform camelcase -quiet -w
$(GO_MODIFY_TAGS) -file types/metrics.go -all -add-tags json -transform camelcase -quiet -w

.PHONY: codegen
Expand Down
90 changes: 90 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,66 @@ const docTemplate = `{
}
}
}
},
"/memstore/query": {
"post": {
"description": "evaluates provided query on top of internal metric storage",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"metrics"
],
"summary": "queries the metric storage",
"parameters": [
{
"description": "QueryRequest",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/rest.QueryRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/rest.OperationResult"
}
},
"500": {
"description": "Internal Server Error"
}
}
}
},
"/memstore/reset": {
"post": {
"description": "deletes all the data in the internal metric store",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ops"
],
"summary": "resets mem storage",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/rest.OperationResult"
}
}
}
}
}
},
"definitions": {
Expand All @@ -115,6 +175,36 @@ const docTemplate = `{
}
}
},
"rest.OperationResult": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"ok": {
"type": "boolean"
},
"operation": {
"type": "string"
},
"value": {
"type": "number"
}
}
},
"rest.QueryRequest": {
"type": "object",
"properties": {
"operationOverTime": {
"type": "string",
"example": "rate"
},
"query": {
"type": "string",
"example": "avg(runtime_service_invocation_req_recv_total{app_id=nodeapp,src_app_id=pythonapp})"
}
}
},
"types.Labels": {
"type": "object",
"additionalProperties": {}
Expand Down
90 changes: 90 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,66 @@
}
}
}
},
"/memstore/query": {
"post": {
"description": "evaluates provided query on top of internal metric storage",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"metrics"
],
"summary": "queries the metric storage",
"parameters": [
{
"description": "QueryRequest",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/rest.QueryRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/rest.OperationResult"
}
},
"500": {
"description": "Internal Server Error"
}
}
}
},
"/memstore/reset": {
"post": {
"description": "deletes all the data in the internal metric store",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ops"
],
"summary": "resets mem storage",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/rest.OperationResult"
}
}
}
}
}
},
"definitions": {
Expand All @@ -104,6 +164,36 @@
}
}
},
"rest.OperationResult": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"ok": {
"type": "boolean"
},
"operation": {
"type": "string"
},
"value": {
"type": "number"
}
}
},
"rest.QueryRequest": {
"type": "object",
"properties": {
"operationOverTime": {
"type": "string",
"example": "rate"
},
"query": {
"type": "string",
"example": "avg(runtime_service_invocation_req_recv_total{app_id=nodeapp,src_app_id=pythonapp})"
}
}
},
"types.Labels": {
"type": "object",
"additionalProperties": {}
Expand Down
59 changes: 59 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ definitions:
lastUpdate:
type: integer
type: object
rest.OperationResult:
properties:
error:
type: string
ok:
type: boolean
operation:
type: string
value:
type: number
type: object
rest.QueryRequest:
properties:
operationOverTime:
example: rate
type: string
query:
example: avg(runtime_service_invocation_req_recv_total{app_id=nodeapp,src_app_id=pythonapp})
type: string
type: object
types.Labels:
additionalProperties: {}
type: object
Expand Down Expand Up @@ -80,4 +100,43 @@ paths:
summary: get metric names in the store
tags:
- metrics
/memstore/query:
post:
consumes:
- application/json
description: evaluates provided query on top of internal metric storage
parameters:
- description: QueryRequest
in: body
name: request
required: true
schema:
$ref: '#/definitions/rest.QueryRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/rest.OperationResult'
"500":
description: Internal Server Error
summary: queries the metric storage
tags:
- metrics
/memstore/reset:
post:
consumes:
- application/json
description: deletes all the data in the internal metric store
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/rest.OperationResult'
summary: resets mem storage
tags:
- ops
swagger: "2.0"
8 changes: 8 additions & 0 deletions metric/mem_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (m ms) get(name types.MetricName, searchLabels types.Labels, timeOp types.O
return -1., false, fmt.Errorf("unknown OperationOverTime: %s", timeOp)
}
return ret, true, nil
} else {
defer func() {
storedMetrics.Delete(hashOfMap(searchLabels))
}()
}
v, _ := md.AggregatesOverTime.Load(timeOp)
return v, true, nil
Expand All @@ -84,6 +88,10 @@ func (m ms) get(name types.MetricName, searchLabels types.Labels, timeOp types.O
}
counter += 1
accumulator = m.calculateAggregate(val, counter, accumulator, defaultAggregation)
} else {
defer func() {
storedMetrics.Delete(hashOfMap(searchLabels))
}()
}
}
return true
Expand Down
Loading

0 comments on commit c4e5744

Please sign in to comment.