Skip to content

Commit

Permalink
SCUBA-186: Add GetMetricsBatch API
Browse files Browse the repository at this point in the history
  • Loading branch information
dvasilas committed Nov 26, 2024
1 parent 71a7252 commit 615a9be
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
89 changes: 89 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export enum AdminActions {
*/
export interface MetricsClass {}

export type GetMetricsBatchBody = {
resourceNames: string[];
dates?: string[];
};

/**
* ScubaApi - axios parameter creator
* @export
Expand Down Expand Up @@ -154,6 +159,57 @@ export const ScubaApiAxiosParamCreator = function (configuration?: Configuration
options: localVarRequestOptions,
};
},
/**
*
* @param {MetricsClass} metricsClass
* @param {any} resourceName
* @param {any} metricsDate
* @param {any} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getMetricsBatch: async (
metricsClass: MetricsClass,
body: GetMetricsBatchBody,
options: AxiosRequestConfig = {},
): Promise<RequestArgs> => {
// verify required parameter 'metricsClass' is not null or undefined
assertParamExists('getMetricsBatch', 'metricsClass', metricsClass);
// // verify required parameter 'resourceName' is not null or undefined
// assertParamExists('getMetrics', 'resourceName', resourceName);
// // verify required parameter 'metricsDate' is not null or undefined
// assertParamExists('getMetrics', 'metricsDate', metricsDate);
const localVarPath = `/metrics/{metricsClass}`.replace(
`{${'metricsClass'}}`,
encodeURIComponent(String(metricsClass)),
);
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {
...localVarHeaderParameter,
...headersFromBaseOptions,
...options.headers,
};
localVarRequestOptions.data = serializeDataIfNeeded(body, localVarRequestOptions, configuration);

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {*} [options] Override http request option.
Expand Down Expand Up @@ -290,6 +346,23 @@ export const ScubaApiFp = function (configuration?: Configuration) {
);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {MetricsClass} metricsClass
* @param {any} resourceName
* @param {any} metricsDate
* @param {any} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getMetricsBatch(
metricsClass: MetricsClass,
body: GetMetricsBatchBody,
options?: AxiosRequestConfig,
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getMetrics(metricsClass, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand Down Expand Up @@ -418,6 +491,22 @@ export class ScubaApi extends BaseAPI {
.then(request => request(this.axios, this.basePath));
}

/**
*
* @param {MetricsClass} metricsClass
* @param {any} resourceName
* @param {any} metricsDate
* @param {any} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ScubaApi
*/
public getMetricsBatch(metricsClass: MetricsClass, body: GetMetricsBatchBody, options?: AxiosRequestConfig) {
return ScubaApiFp(this.configuration)
.getMetrics(metricsClass, body, options)
.then(request => request(this.axios, this.basePath));
}

/**
* Health check endpoint
* @param {*} [options] Override http request option.
Expand Down
18 changes: 17 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import globalAxios, { AxiosRequestConfig, AxiosInstance, AxiosHeaders } from 'ax
import { Sha256 } from '@aws-crypto/sha256-js';
import { URL } from 'url';
import { parse as parseQuerystring } from 'querystring';
import { ScubaApi, AdminActions } from './api';
import { ScubaApi, AdminActions, GetMetricsBatchBody } from './api';
import { Configuration, ConfigurationParameters } from './configuration';

export type MetricsClass = 'account' | 'bucket' | 'service';
Expand Down Expand Up @@ -170,6 +170,22 @@ export default class ScubaClient {
return resp.data;
}

async getMetricsBatch(
metricsClass: MetricsClass,
body: GetMetricsBatchBody,
options?: AxiosRequestConfig,
): Promise<ScubaMetrics> {
// const year = lpad(date.getUTCFullYear(), 4);
// const month = lpad(date.getUTCMonth() + 1, 2);
// const day = lpad(date.getUTCDate(), 2);
// const dateString = `${year}-${month}-${day}`;
const resp = (await this._api.getMetricsBatch(metricsClass, body, {
...this._defaultReqOptions,
...options,
})) as any;
return resp.data;
}

async healthCheck(options?: AxiosRequestConfig): Promise<HealthCheckResponse> {
const resp = (await this._api.healthCheck({ ...this._defaultReqOptions, ...options })) as any;
return resp.data;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './client';
export { default as ScubaClient } from './client';
export { AdminActions } from './api';
export { AdminActions, GetMetricsBatchBody } from './api';

0 comments on commit 615a9be

Please sign in to comment.