@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 94 lines 3.03 KB
Raw
1 import type * as Credentials from "@distilled.cloud/aws/Credentials";
2 import type * as SigV4 from "@distilled.cloud/aws/SigV4";
3 import * as Binding from "alchemy/Binding";
4 import type { SourceError } from "effect/ConfigProvider";
5 import type * as Duration from "effect/Duration";
6 import type * as Effect from "effect/Effect";
7 import type {
8 PrometheusApiError,
9 PrometheusInstantResult,
10 PrometheusRangeResult,
11 PrometheusTime,
12 } from "./PrometheusTypes.ts";
13 import type { Workspace } from "./Workspace.ts";
14
15 export interface QueryMetricsRequest {
16 /** PromQL expression to evaluate, e.g. `up` or `rate(http_requests_total[5m])`. */
17 query: string;
18 /**
19 * Evaluation instant. A `Date`, Unix seconds, or an RFC 3339 string.
20 * @default the server's current time
21 */
22 time?: PrometheusTime;
23 /**
24 * Evaluation timeout. Capped by the server-side query timeout.
25 */
26 timeout?: Duration.Input;
27 }
28
29 export interface QueryRangeRequest {
30 /** PromQL expression to evaluate over the range. */
31 query: string;
32 /** Start of the range (inclusive). A `Date`, Unix seconds, or RFC 3339 string. */
33 start: PrometheusTime;
34 /** End of the range (inclusive). A `Date`, Unix seconds, or RFC 3339 string. */
35 end: PrometheusTime;
36 /** Resolution step between evaluated points, e.g. `"30 seconds"`. */
37 step: Duration.Input;
38 /** Evaluation timeout. Capped by the server-side query timeout. */
39 timeout?: Duration.Input;
40 }
41
42 export interface QueryMetricsClient {
43 /** Evaluate a PromQL expression at a single instant (`api/v1/query`). */
44 query(
45 request: QueryMetricsRequest,
46 ): Effect.Effect<
47 PrometheusInstantResult,
48 PrometheusApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError
49 >;
50 /** Evaluate a PromQL expression over a time range (`api/v1/query_range`). */
51 queryRange(
52 request: QueryRangeRequest,
53 ): Effect.Effect<
54 PrometheusRangeResult,
55 PrometheusApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError
56 >;
57 }
58
59 /**
60 * Runtime binding for `aps:QueryMetrics` — evaluate PromQL against an AMP
61 * {@link Workspace}'s Prometheus-compatible query API (`api/v1/query` and
62 * `api/v1/query_range`), SigV4-signed with the host Function's credentials.
63 *
64 * ### Querying Metrics
65 * **Example:** Instant Query
66 * ```typescript
67 * const metrics = yield* AMP.QueryMetrics(workspace);
68 *
69 * const result = yield* metrics.query({ query: "up" });
70 * if (result.resultType === "vector") {
71 * for (const sample of result.result) {
72 * console.log(sample.metric.__name__, sample.value[1]);
73 * }
74 * }
75 * ```
76 *
77 * **Example:** Range Query
78 * ```typescript
79 * const result = yield* metrics.queryRange({
80 * query: "rate(http_requests_total[5m])",
81 * start: new Date(Date.now() - 3_600_000),
82 * end: new Date(),
83 * step: "30 seconds",
84 * });
85 * ```
86 *
87 * @binding
88 */
89 export interface QueryMetrics extends Binding.Service<
90 QueryMetrics,
91 "AWS.AMP.QueryMetrics",
92 (workspace: Workspace) => Effect.Effect<QueryMetricsClient>
93 > {}
94 export const QueryMetrics = Binding.Service<QueryMetrics>("AWS.AMP.QueryMetrics");