Skip to content

Commit eae49c6

Browse files
STORIF-330: refactored handling of Quotas. Introduced new interface that allows to quickly introduce new services. Added service selector.
1 parent 128efd1 commit eae49c6

35 files changed

+1418
-1004
lines changed
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,48 @@
11
import { BETA_API_ROOT } from '../constants';
22
import Request, { setMethod, setParams, setURL, setXFilter } from '../request';
33

4-
import type { Quota, QuotaType, QuotaUsage } from './types';
4+
import type { Quota, QuotaServiceType, QuotaUsage } from './types';
55
import type { Filter, ResourcePage as Page, Params } from 'src/types';
66

77
/**
88
* getQuota
99
*
1010
* Returns the details for a single quota within a particular service specified by `type`.
1111
*
12-
* @param type { QuotaType } retrieve a quota within this service type.
12+
* @param quotaService { QuotaServiceType } retrieve a quota within this service type.
1313
* @param id { number } the quota ID to look up.
14-
* @param collection { string } quota collection name (quotas/global-quotas).
14+
* @param apiCollection { string } quota collection name (quotas/global-quotas).
1515
*/
16-
export const getQuota = (type: QuotaType, collection: string, id: number) =>
16+
export const getQuota = (
17+
quotaService: QuotaServiceType,
18+
apiCollection: string,
19+
id: number,
20+
) =>
1721
Request<Quota>(
18-
setURL(`${BETA_API_ROOT}/${type}/${collection}/${id}`),
22+
setURL(`${BETA_API_ROOT}/${quotaService}/${apiCollection}/${id}`),
1923
setMethod('GET'),
2024
);
2125

2226
/**
2327
* getQuotas
2428
*
25-
* Returns a paginated list of quotas for a particular service specified by `type`.
29+
* Returns a paginated list of quotas for a particular service specified by `quotaService`.
2630
*
2731
* This request can be filtered on `quota_name`, `service_name` and `scope`.
2832
*
29-
* @param type { QuotaType } retrieve quotas within this service type.
30-
* @param collection { string } quota collection name (quotas/global-quotas).
33+
* @param quotaService { QuotaServiceType } retrieve quotas within this service quotaService.
34+
* @param apiCollection { string } quota API collection name (e.g. quotas, global-quotas, etc.).
35+
* @param params { Params } query params to include in the request.
36+
* @param filter { Filter } filters to include in the request.
3137
*/
3238
export const getQuotas = (
33-
type: QuotaType,
34-
collection: string,
39+
quotaService: QuotaServiceType,
40+
apiCollection: string,
3541
params: Params = {},
3642
filter: Filter = {},
3743
) =>
3844
Request<Page<Quota>>(
39-
setURL(`${BETA_API_ROOT}/${type}/${collection}`),
45+
setURL(`${BETA_API_ROOT}/${quotaService}/${apiCollection}`),
4046
setMethod('GET'),
4147
setXFilter(filter),
4248
setParams(params),
@@ -47,16 +53,16 @@ export const getQuotas = (
4753
*
4854
* Returns the usage for a single quota within a particular service specified by `type`.
4955
*
50-
* @param type { QuotaType } retrieve a quota within this service type.
51-
* @param collection { string } quota collection name (quotas/global-quotas).
56+
* @param quotaService { QuotaServiceType } retrieve a quota within this service type.
57+
* @param apiCollection { string } quota collection name (quotas/global-quotas).
5258
* @param id { string } the quota ID to look up.
5359
*/
5460
export const getQuotaUsage = (
55-
type: QuotaType,
56-
collection: string,
61+
quotaService: QuotaServiceType,
62+
apiCollection: string,
5763
id: string,
5864
) =>
5965
Request<QuotaUsage>(
60-
setURL(`${BETA_API_ROOT}/${type}/${collection}/${id}/usage`),
66+
setURL(`${BETA_API_ROOT}/${quotaService}/${apiCollection}/${id}/usage`),
6167
setMethod('GET'),
6268
);
Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
11
import type { ObjectStorageEndpointTypes } from 'src/object-storage';
22
import type { Region } from 'src/regions';
33

4-
export enum QuotaResourceMetrics {
5-
BUCKET = 'bucket',
6-
BYTE = 'byte',
7-
BYTE_PER_SECOND = 'byte_per_second',
8-
CLUSTER = 'cluster',
9-
CPU = 'CPU',
10-
GPU = 'GPU',
11-
OBJECT = 'object',
12-
REQUEST = 'request',
13-
VPU = 'VPU',
14-
}
4+
export type LinodeQuotaResourceMetric = 'CPU' | 'GPU' | 'VPU';
5+
export type LkeQuotaResourceMetric = 'cluster';
6+
export type ObjectStorageEndpointQuotaResourceMetric =
7+
| 'bucket'
8+
| 'byte'
9+
| 'byte_per_second'
10+
| 'object'
11+
| 'request';
12+
export type ObjectStorageGlobalQuotaResourceMetric = 'key';
1513

16-
/**
17-
* A Quota is a service used limit that is rated based on service metrics such
18-
* as vCPUs used, instances or storage size.
19-
*/
20-
export interface Quota {
14+
interface QuotaCommon<T> {
2115
/**
2216
* Longer explanatory description for the quota.
2317
*/
2418
description: string;
2519

26-
/**
27-
* The OBJ endpoint type to which this limit applies.
28-
*
29-
* For OBJ limits only.
30-
*/
31-
endpoint_type?: ObjectStorageEndpointTypes;
32-
33-
/**
34-
* Sets usage column to be n/a when value is false.
35-
*/
36-
has_usage?: boolean;
37-
3820
/**
3921
* A unique identifier for the quota.
4022
*/
@@ -52,31 +34,80 @@ export interface Quota {
5234
quota_name: string;
5335

5436
/**
55-
* Customer facing id describing the quota.
37+
* The unit of measurement for this service limit.
5638
*/
57-
quota_type: string;
39+
resource_metric: T;
40+
}
5841

42+
interface QuotaCommonWithRegionApplied<T> extends QuotaCommon<T> {
5943
/**
6044
* The region slug to which this limit applies.
6145
*
6246
* OBJ limits are applied by endpoint, not region.
6347
* This below really just is a `string` type but being verbose helps with reading comprehension.
6448
*/
65-
region_applied?: 'global' | Region['id'];
49+
region_applied: 'global' | Region['id'];
50+
}
6651

52+
interface QuotaCommonWithUsage<T> extends QuotaCommon<T> {
6753
/**
68-
* The unit of measurement for this service limit.
54+
* Determines whether usage information is provided for this quota.
55+
*/
56+
has_usage: boolean;
57+
}
58+
59+
export type LinodeQuota =
60+
QuotaCommonWithRegionApplied<LinodeQuotaResourceMetric>;
61+
62+
export type LkeQuota = QuotaCommonWithRegionApplied<LkeQuotaResourceMetric>;
63+
64+
export interface ObjectStorageGlobalQuota
65+
extends QuotaCommon<ObjectStorageGlobalQuotaResourceMetric> {
66+
/**
67+
* Represents the quota type.
68+
*/
69+
quota_type: 'keys';
70+
}
71+
72+
export interface ObjectStorageEndpointQuota
73+
extends QuotaCommonWithUsage<ObjectStorageEndpointQuotaResourceMetric> {
74+
/**
75+
* The OBJ endpoint type to which this limit applies.
76+
*
77+
*/
78+
endpoint_type: ObjectStorageEndpointTypes;
79+
80+
/**
81+
* Represents the quota type.
6982
*/
70-
resource_metric: QuotaResourceMetrics;
83+
quota_type:
84+
| 'obj-buckets'
85+
| 'obj-bytes'
86+
| 'obj-objects'
87+
| 'obj-per-ip-concurrent-requests'
88+
| 'obj-per-ip-egress-throughput'
89+
| 'obj-per-ip-ingress-throughput'
90+
| 'obj-total-concurrent-requests'
91+
| 'obj-total-egress-throughput'
92+
| 'obj-total-ingress-throughput';
7193

7294
/**
7395
* The S3 endpoint URL to which this limit applies.
7496
*
75-
* For OBJ limits only.
7697
*/
77-
s3_endpoint?: string;
98+
s3_endpoint: string;
7899
}
79100

101+
/**
102+
* A Quota is a service used limit that is rated based on service metrics such
103+
* as vCPUs used, instances or storage size.
104+
*/
105+
export type Quota =
106+
| LinodeQuota
107+
| LkeQuota
108+
| ObjectStorageEndpointQuota
109+
| ObjectStorageGlobalQuota;
110+
80111
/**
81112
* A usage limit for a given Quota based on service metrics such
82113
* as vCPUs, instances or storage size.
@@ -97,10 +128,8 @@ export interface QuotaUsage {
97128
usage: null | number;
98129
}
99130

100-
export const quotaTypes = {
101-
linode: 'Linodes',
102-
lke: 'Kubernetes',
103-
'object-storage': 'Object Storage',
104-
} as const;
105-
106-
export type QuotaType = keyof typeof quotaTypes;
131+
/**
132+
* Represents the type of service for a given quota, e.g. Linodes, Object Storage, etc.
133+
* The type must match the service part of the quota endpoint paths.
134+
*/
135+
export type QuotaServiceType = 'linode' | 'lke' | 'object-storage';

0 commit comments

Comments
 (0)