Skip to content

Commit 9799052

Browse files
committed
init
1 parent ffcf597 commit 9799052

File tree

17 files changed

+900
-147
lines changed

17 files changed

+900
-147
lines changed

bifrost/lib/clients/jawnTypes/public.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ export interface paths {
423423
"/v1/public/status/provider/{provider}": {
424424
get: operations["GetProviderStatus"];
425425
};
426+
"/v1/providers": {
427+
get: operations["GetProviders"];
428+
};
426429
"/v1/property/query": {
427430
post: operations["GetProperties"];
428431
};
@@ -2566,6 +2569,17 @@ Json: JsonObject;
25662569
"Result_ProviderMetrics.string_": components["schemas"]["ResultSuccess_ProviderMetrics_"] | components["schemas"]["ResultError_string_"];
25672570
/** @enum {string} */
25682571
TimeFrame: "24h" | "7d" | "30d";
2572+
ProviderMetric: {
2573+
provider: string;
2574+
/** Format: double */
2575+
total_requests: number;
2576+
};
2577+
"ResultSuccess_ProviderMetric-Array_": {
2578+
data: components["schemas"]["ProviderMetric"][];
2579+
/** @enum {number|null} */
2580+
error: null;
2581+
};
2582+
"Result_ProviderMetric-Array.string_": components["schemas"]["ResultSuccess_ProviderMetric-Array_"] | components["schemas"]["ResultError_string_"];
25692583
Property: {
25702584
property: string;
25712585
};
@@ -6442,6 +6456,16 @@ export interface operations {
64426456
};
64436457
};
64446458
};
6459+
GetProviders: {
6460+
responses: {
6461+
/** @description Ok */
6462+
200: {
6463+
content: {
6464+
"application/json": components["schemas"]["Result_ProviderMetric-Array.string_"];
6465+
};
6466+
};
6467+
};
6468+
};
64456469
GetProperties: {
64466470
requestBody: {
64476471
content: {

docs/swagger.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7241,6 +7241,56 @@
72417241
"30d"
72427242
]
72437243
},
7244+
"ProviderMetric": {
7245+
"properties": {
7246+
"provider": {
7247+
"type": "string"
7248+
},
7249+
"total_requests": {
7250+
"type": "number",
7251+
"format": "double"
7252+
}
7253+
},
7254+
"required": [
7255+
"provider",
7256+
"total_requests"
7257+
],
7258+
"type": "object",
7259+
"additionalProperties": false
7260+
},
7261+
"ResultSuccess_ProviderMetric-Array_": {
7262+
"properties": {
7263+
"data": {
7264+
"items": {
7265+
"$ref": "#/components/schemas/ProviderMetric"
7266+
},
7267+
"type": "array"
7268+
},
7269+
"error": {
7270+
"type": "number",
7271+
"enum": [
7272+
null
7273+
],
7274+
"nullable": true
7275+
}
7276+
},
7277+
"required": [
7278+
"data",
7279+
"error"
7280+
],
7281+
"type": "object",
7282+
"additionalProperties": false
7283+
},
7284+
"Result_ProviderMetric-Array.string_": {
7285+
"anyOf": [
7286+
{
7287+
"$ref": "#/components/schemas/ResultSuccess_ProviderMetric-Array_"
7288+
},
7289+
{
7290+
"$ref": "#/components/schemas/ResultError_string_"
7291+
}
7292+
]
7293+
},
72447294
"Property": {
72457295
"properties": {
72467296
"property": {
@@ -18521,6 +18571,32 @@
1852118571
]
1852218572
}
1852318573
},
18574+
"/v1/providers": {
18575+
"get": {
18576+
"operationId": "GetProviders",
18577+
"responses": {
18578+
"200": {
18579+
"description": "Ok",
18580+
"content": {
18581+
"application/json": {
18582+
"schema": {
18583+
"$ref": "#/components/schemas/Result_ProviderMetric-Array.string_"
18584+
}
18585+
}
18586+
}
18587+
}
18588+
},
18589+
"tags": [
18590+
"Providers"
18591+
],
18592+
"security": [
18593+
{
18594+
"api_key": []
18595+
}
18596+
],
18597+
"parameters": []
18598+
}
18599+
},
1852418600
"/v1/property/query": {
1852518601
"post": {
1852618602
"operationId": "GetProperties",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Controller, Get, Request, Route, Security, Tags } from "tsoa";
2+
import { KVCache } from "../../lib/cache/kvCache";
3+
import { err, ok, Result } from "../../packages/common/result";
4+
import { type JawnAuthenticatedRequest } from "../../types/request";
5+
import { cacheResultCustom } from "../../utils/cacheResult";
6+
import { dbQueryClickhouse } from "../../lib/shared/db/dbExecute";
7+
8+
const kvCache = new KVCache(12 * 60 * 60 * 1000); // 12 hours
9+
10+
export interface ProviderMetric {
11+
provider: string;
12+
total_requests: number;
13+
}
14+
15+
@Route("/v1/providers")
16+
@Tags("Providers")
17+
@Security("api_key")
18+
export class ProviderController extends Controller {
19+
@Get("/")
20+
public async getProviders(
21+
@Request() request: JawnAuthenticatedRequest
22+
): Promise<Result<ProviderMetric[], string>> {
23+
const result = await cacheResultCustom(
24+
"v1/public/providers" + JSON.stringify(request.authParams),
25+
async () => {
26+
const result = await dbQueryClickhouse<ProviderMetric>(
27+
`
28+
SELECT
29+
provider,
30+
count(DISTINCT request_id) as total_requests
31+
FROM request_response_rmt
32+
WHERE organization_id = {val_0: UUID}
33+
GROUP BY provider
34+
ORDER BY total_requests DESC
35+
LIMIT 1000
36+
`,
37+
[request.authParams.organizationId]
38+
);
39+
return ok(result);
40+
},
41+
kvCache
42+
);
43+
44+
if (result.error || !result.data) {
45+
this.setStatus(500);
46+
return err(
47+
JSON.stringify(result.error) || "Failed to fetch providers"
48+
);
49+
} else {
50+
this.setStatus(200);
51+
return ok(result.data.data ?? []);
52+
}
53+
}
54+
}

valhalla/jawn/src/tsoa-build/public/routes.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import { SessionController } from './../../controllers/public/sessionController'
3434
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
3535
import { StatusController } from './../../controllers/public/providerStatusController';
3636
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
37+
import { ProviderController } from './../../controllers/public/providerController';
38+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
3739
import { PropertyController } from './../../controllers/public/propertyController';
3840
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
3941
import { PlaygroundController } from './../../controllers/public/playgroundController';
@@ -2337,6 +2339,29 @@ const models: TsoaRoute.Models = {
23372339
"type": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["24h"]},{"dataType":"enum","enums":["7d"]},{"dataType":"enum","enums":["30d"]}],"validators":{}},
23382340
},
23392341
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
2342+
"ProviderMetric": {
2343+
"dataType": "refObject",
2344+
"properties": {
2345+
"provider": {"dataType":"string","required":true},
2346+
"total_requests": {"dataType":"double","required":true},
2347+
},
2348+
"additionalProperties": false,
2349+
},
2350+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
2351+
"ResultSuccess_ProviderMetric-Array_": {
2352+
"dataType": "refObject",
2353+
"properties": {
2354+
"data": {"dataType":"array","array":{"dataType":"refObject","ref":"ProviderMetric"},"required":true},
2355+
"error": {"dataType":"enum","enums":[null],"required":true},
2356+
},
2357+
"additionalProperties": false,
2358+
},
2359+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
2360+
"Result_ProviderMetric-Array.string_": {
2361+
"dataType": "refAlias",
2362+
"type": {"dataType":"union","subSchemas":[{"ref":"ResultSuccess_ProviderMetric-Array_"},{"ref":"ResultError_string_"}],"validators":{}},
2363+
},
2364+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
23402365
"Property": {
23412366
"dataType": "refObject",
23422367
"properties": {
@@ -8778,6 +8803,37 @@ export function RegisterRoutes(app: Router) {
87788803
}
87798804
});
87808805
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
8806+
const argsProviderController_getProviders: Record<string, TsoaRoute.ParameterSchema> = {
8807+
request: {"in":"request","name":"request","required":true,"dataType":"object"},
8808+
};
8809+
app.get('/v1/providers',
8810+
authenticateMiddleware([{"api_key":[]}]),
8811+
...(fetchMiddlewares<RequestHandler>(ProviderController)),
8812+
...(fetchMiddlewares<RequestHandler>(ProviderController.prototype.getProviders)),
8813+
8814+
async function ProviderController_getProviders(request: ExRequest, response: ExResponse, next: any) {
8815+
8816+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
8817+
8818+
let validatedArgs: any[] = [];
8819+
try {
8820+
validatedArgs = templateService.getValidatedArgs({ args: argsProviderController_getProviders, request, response });
8821+
8822+
const controller = new ProviderController();
8823+
8824+
await templateService.apiHandler({
8825+
methodName: 'getProviders',
8826+
controller,
8827+
response,
8828+
next,
8829+
validatedArgs,
8830+
successStatus: undefined,
8831+
});
8832+
} catch (err) {
8833+
return next(err);
8834+
}
8835+
});
8836+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
87818837
const argsPropertyController_getProperties: Record<string, TsoaRoute.ParameterSchema> = {
87828838
requestBody: {"in":"body","name":"requestBody","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{}},
87838839
request: {"in":"request","name":"request","required":true,"dataType":"object"},

valhalla/jawn/src/tsoa-build/public/swagger.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7241,6 +7241,56 @@
72417241
"30d"
72427242
]
72437243
},
7244+
"ProviderMetric": {
7245+
"properties": {
7246+
"provider": {
7247+
"type": "string"
7248+
},
7249+
"total_requests": {
7250+
"type": "number",
7251+
"format": "double"
7252+
}
7253+
},
7254+
"required": [
7255+
"provider",
7256+
"total_requests"
7257+
],
7258+
"type": "object",
7259+
"additionalProperties": false
7260+
},
7261+
"ResultSuccess_ProviderMetric-Array_": {
7262+
"properties": {
7263+
"data": {
7264+
"items": {
7265+
"$ref": "#/components/schemas/ProviderMetric"
7266+
},
7267+
"type": "array"
7268+
},
7269+
"error": {
7270+
"type": "number",
7271+
"enum": [
7272+
null
7273+
],
7274+
"nullable": true
7275+
}
7276+
},
7277+
"required": [
7278+
"data",
7279+
"error"
7280+
],
7281+
"type": "object",
7282+
"additionalProperties": false
7283+
},
7284+
"Result_ProviderMetric-Array.string_": {
7285+
"anyOf": [
7286+
{
7287+
"$ref": "#/components/schemas/ResultSuccess_ProviderMetric-Array_"
7288+
},
7289+
{
7290+
"$ref": "#/components/schemas/ResultError_string_"
7291+
}
7292+
]
7293+
},
72447294
"Property": {
72457295
"properties": {
72467296
"property": {
@@ -18521,6 +18571,32 @@
1852118571
]
1852218572
}
1852318573
},
18574+
"/v1/providers": {
18575+
"get": {
18576+
"operationId": "GetProviders",
18577+
"responses": {
18578+
"200": {
18579+
"description": "Ok",
18580+
"content": {
18581+
"application/json": {
18582+
"schema": {
18583+
"$ref": "#/components/schemas/Result_ProviderMetric-Array.string_"
18584+
}
18585+
}
18586+
}
18587+
}
18588+
},
18589+
"tags": [
18590+
"Providers"
18591+
],
18592+
"security": [
18593+
{
18594+
"api_key": []
18595+
}
18596+
],
18597+
"parameters": []
18598+
}
18599+
},
1852418600
"/v1/property/query": {
1852518601
"post": {
1852618602
"operationId": "GetProperties",

0 commit comments

Comments
 (0)