|
| 1 | +import "@typespec/openapi"; |
| 2 | +import "./responses.tsp"; |
| 3 | + |
| 4 | +namespace Api; |
| 5 | + |
| 6 | +using TypeSpec.Http; |
| 7 | +using OpenAPI; |
| 8 | + |
| 9 | +@route("/api/clusters/{clusterName}/graphs") |
| 10 | +@tag("Graphs") |
| 11 | +interface GraphsApi { |
| 12 | + @get |
| 13 | + @operationId("getGraphsList") |
| 14 | + @summary("getGraphsList") |
| 15 | + getGraphsList( |
| 16 | + @path clusterName: string |
| 17 | + ): GraphDescriptions; |
| 18 | + |
| 19 | + @post |
| 20 | + @operationId("getGraphData") |
| 21 | + @summary("getGraphData") |
| 22 | + getGraphData( |
| 23 | + @path clusterName: string, |
| 24 | + @body request: GraphDataRequest |
| 25 | + ) : PrometheusApiQueryResponse |
| 26 | +} |
| 27 | + |
| 28 | +model GraphDescriptions { |
| 29 | + graphs?: Array<GraphDescription>; |
| 30 | +} |
| 31 | + |
| 32 | +model GraphDescription { |
| 33 | + @doc("Id that should be used to query data on API level") |
| 34 | + id: string; |
| 35 | + type?: "range" | "instant"; |
| 36 | + @doc(""" |
| 37 | + ISO_8601 duration string (for "range" graphs only) |
| 38 | + """) |
| 39 | + defaultPeriod?: string; |
| 40 | + parameters?: Array<GraphParameter>; |
| 41 | +} |
| 42 | + |
| 43 | +model GraphParameter { |
| 44 | + name: string; |
| 45 | +} |
| 46 | + |
| 47 | +model GraphDataRequest { |
| 48 | + id?: string; |
| 49 | + parameters?: Record<string>; |
| 50 | + from?: offsetDateTime; |
| 51 | + to?: offsetDateTime; |
| 52 | +} |
| 53 | + |
| 54 | +model PrometheusApiBaseResponse { |
| 55 | + status: "success" | "error"; |
| 56 | + error?: string; |
| 57 | + errorType?: string; |
| 58 | + warnings?: Array<string>; |
| 59 | +} |
| 60 | + |
| 61 | +model PrometheusApiQueryResponse extends PrometheusApiBaseResponse { |
| 62 | + data?: PrometheusApiQueryResponseData; |
| 63 | +} |
| 64 | + |
| 65 | +model PrometheusApiQueryResponseData { |
| 66 | + resultType: "matrix" | "vector" | "scalar" | "string"; |
| 67 | + @doc(""" |
| 68 | + Depending on resultType format can vary: |
| 69 | + "vector": |
| 70 | + [ |
| 71 | + { |
| 72 | + "metric": { "<label_name>": "<label_value>", ... }, |
| 73 | + "value": [ <unix_time>, "<sample_value>" ], |
| 74 | + "histogram": [ <unix_time>, <histogram> ] |
| 75 | + }, ... |
| 76 | + ] |
| 77 | + "matrix": |
| 78 | + [ |
| 79 | + { |
| 80 | + "metric": { "<label_name>": "<label_value>", ... }, |
| 81 | + "values": [ [ <unix_time>, "<sample_value>" ], ... ], |
| 82 | + "histograms": [ [ <unix_time>, <histogram> ], ... ] |
| 83 | + }, ... |
| 84 | + ] |
| 85 | + "scalar": |
| 86 | + [ <unix_time>, "<scalar_value>" ] |
| 87 | + "string": |
| 88 | + [ <unix_time>, "<string_value>" ] |
| 89 | + """) |
| 90 | + result?: Array<unknown>; |
| 91 | +} |
0 commit comments