Skip to content

Commit

Permalink
Change Prometheus /metrics response from JSON to text
Browse files Browse the repository at this point in the history
  • Loading branch information
0237h committed Aug 26, 2024
1 parent c886aa5 commit fa0a751
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function AntelopeTokenAPI() {

app.get(
"/metrics",
async (ctx: Context) => ctx.json<EndpointReturnTypes<"/metrics">, 200>(await prometheus.registry.getMetricsAsJSON())
async (ctx: Context) => new Response(await prometheus.registry.metrics())
);

// --------------------------
Expand Down Expand Up @@ -133,7 +133,7 @@ async function AntelopeTokenAPI() {
return response.success ? "OK" : `[500] bad_database_response: ${response.error.message}`;
},
openapi: () => openapi,
metrics: async () => await prometheus.registry.getMetricsAsJSON(),
metrics: async () => await prometheus.registry.metrics(),
version: () => APP_VERSION
}
);
Expand Down
9 changes: 7 additions & 2 deletions src/types/zod.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ export type MonitoringHealthQueryResponseSchema = z.infer<typeof monitoringHealt
/**
* @description Metrics as text.
*/
export const monitoringMetrics200Schema = z.object({});
export const monitoringMetrics200Schema = z.coerce.string();
export type MonitoringMetrics200Schema = z.infer<typeof monitoringMetrics200Schema>;
/**
* @description An unexpected error response.
*/
export const monitoringMetricsErrorSchema = z.lazy(() => apiErrorSchema);
export type MonitoringMetricsErrorSchema = z.infer<typeof monitoringMetricsErrorSchema>;
/**
* @description Metrics as text.
*/
export const monitoringMetricsQueryResponseSchema = z.object({});
export const monitoringMetricsQueryResponseSchema = z.coerce.string();
export type MonitoringMetricsQueryResponseSchema = z.infer<typeof monitoringMetricsQueryResponseSchema>;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/typespec/openapi3.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,5 @@ interface Monitoring {
@summary("Prometheus metrics")
@route("/metrics")
@get
metrics(): Record<unknown>;
metrics(): APIResponse<string>;
}
2 changes: 1 addition & 1 deletion static/@openapi-to-graphql/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Query {
Equivalent to GET /metrics
"""
metrics: JSON
metrics: String

"""
Reflection endpoint to return OpenAPI JSON spec. Also used by Swagger to generate the frontpage.
Expand Down
13 changes: 11 additions & 2 deletions static/@typespec/openapi3/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,17 @@
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": {}
"type": "string"
}
}
}
},
"default": {
"description": "An unexpected error response.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIError"
}
}
}
Expand Down

0 comments on commit fa0a751

Please sign in to comment.