Skip to content

Commit 7f5c5b5

Browse files
committed
Return endpoint usage
1 parent ead1a9d commit 7f5c5b5

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/tools/oauthClientUsage/oauthClientUsage.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe("OAuth Client Usage", () => {
1818
postOauthClientUsageQuery: vi.fn(),
1919
getOauthClientUsageQueryResult: vi.fn(),
2020
},
21+
cache: undefined,
2122
};
2223
const toolDefinition = oauthClientUsage(toolDeps);
2324
toolName = toolDefinition.schema.name;
@@ -141,8 +142,6 @@ describe("OAuth Client Usage", () => {
141142
test("OAuth Client usage returned for date range", async () => {
142143
const oauthClientId = randomUUID();
143144
const executionId = randomUUID();
144-
const organisationOneId = randomUUID();
145-
const organisationTwoId = randomUUID();
146145

147146
toolDeps.oauthApi.postOauthClientUsageQuery.mockResolvedValue({
148147
executionId,
@@ -152,11 +151,13 @@ describe("OAuth Client Usage", () => {
152151
toolDeps.oauthApi.getOauthClientUsageQueryResult.mockResolvedValue({
153152
results: [
154153
{
155-
organizationId: organisationOneId,
154+
templateUri: "api/v2/authorization/divisions",
155+
httpMethod: "GET",
156156
requests: 5,
157157
},
158158
{
159-
organizationId: organisationTwoId,
159+
templateUri: "api/v2/authorization/roles",
160+
httpMethod: "GET",
160161
requests: 10,
161162
},
162163
],
@@ -181,14 +182,14 @@ describe("OAuth Client Usage", () => {
181182
text: JSON.stringify({
182183
startDate,
183184
endDate,
184-
totalRequest: 15,
185-
requestsPerOrganisation: [
185+
totalRequests: 15,
186+
requestsPerEndpoint: [
186187
{
187-
organisationId: organisationOneId,
188+
endpoint: "GET api/v2/authorization/divisions",
188189
requests: 5,
189190
},
190191
{
191-
organisationId: organisationTwoId,
192+
endpoint: "GET api/v2/authorization/roles",
192193
requests: 10,
193194
},
194195
],

src/tools/oauthClientUsage/oauthClientUsage.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const TOOL_CACHE_KEY = "oauthClientUsage";
1212
export interface OAuthClientUsageResponse {
1313
startDate: string;
1414
endDate: string;
15-
totalRequest: number;
16-
requestsPerOrganisation: {
17-
organisationId?: string;
15+
totalRequests: number;
16+
requestsPerEndpoint: {
17+
endpoint?: string;
1818
requests?: number;
1919
}[];
2020
}
@@ -91,7 +91,7 @@ export const oauthClientUsage: ToolFactory<
9191
result = await oauthApi.postOauthClientUsageQuery(oauthClientId, {
9292
interval: `${from.toISOString()}/${to.toISOString()}`,
9393
metrics: ["Requests"],
94-
groupBy: ["OrganizationId"],
94+
groupBy: ["TemplateUri", "HttpMethod"],
9595
});
9696
} catch (error: unknown) {
9797
const errorMessage = isUnauthorisedError(error)
@@ -147,13 +147,14 @@ export const oauthClientUsage: ToolFactory<
147147
const toolResult: OAuthClientUsageResponse = {
148148
startDate,
149149
endDate,
150-
totalRequest: (apiUsageQueryResult?.results ?? []).reduce(
150+
totalRequests: (apiUsageQueryResult?.results ?? []).reduce(
151151
(acc, curr) => acc + (curr.requests ?? 0),
152152
0,
153153
),
154-
requestsPerOrganisation: (apiUsageQueryResult?.results ?? []).map(
154+
requestsPerEndpoint: (apiUsageQueryResult?.results ?? []).map(
155155
(result) => ({
156-
organisationId: result.organizationId,
156+
endpoint:
157+
[result.httpMethod, result.templateUri].join(" ") || undefined,
157158
requests: result.requests,
158159
}),
159160
),

0 commit comments

Comments
 (0)