Skip to content

Commit 24e27b4

Browse files
authored
feat(cockpit): add retention setup in datasource (#1557)
1 parent 490f9d6 commit 24e27b4

File tree

5 files changed

+115
-8
lines changed

5 files changed

+115
-8
lines changed

packages/clients/src/api/cockpit/v1/api.gen.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
unmarshalAlertManager,
2626
unmarshalContactPoint,
2727
unmarshalDataSource,
28+
unmarshalGetConfigResponse,
2829
unmarshalGrafana,
2930
unmarshalGrafanaProductDashboard,
3031
unmarshalGrafanaUser,
@@ -43,6 +44,7 @@ import type {
4344
AlertManager,
4445
ContactPoint,
4546
DataSource,
47+
GetConfigResponse,
4648
GlobalApiCreateGrafanaUserRequest,
4749
GlobalApiDeleteGrafanaUserRequest,
4850
GlobalApiGetCurrentPlanRequest,
@@ -76,6 +78,7 @@ import type {
7678
RegionalApiEnableAlertManagerRequest,
7779
RegionalApiEnableManagedAlertsRequest,
7880
RegionalApiGetAlertManagerRequest,
81+
RegionalApiGetConfigRequest,
7982
RegionalApiGetDataSourceRequest,
8083
RegionalApiGetTokenRequest,
8184
RegionalApiGetUsageOverviewRequest,
@@ -334,7 +337,9 @@ export class GlobalAPI extends ParentAPI {
334337

335338
/**
336339
* List plan types. Retrieve a list of available pricing plan types.
340+
* Deprecated, retention is now managed at the data source level.
337341
*
342+
* @deprecated
338343
* @param request - The request {@link GlobalApiListPlansRequest}
339344
* @returns A Promise of ListPlansResponse
340345
*/
@@ -344,8 +349,10 @@ export class GlobalAPI extends ParentAPI {
344349
/**
345350
* Apply a pricing plan. Apply a pricing plan on a given Project. You must
346351
* specify the ID of the pricing plan type. Note that you will be billed for
347-
* the plan you apply.
352+
* the plan you apply. Deprecated, retention is now managed at the data source
353+
* level.
348354
*
355+
* @deprecated
349356
* @param request - The request {@link GlobalApiSelectPlanRequest}
350357
* @returns A Promise of Plan
351358
*/
@@ -364,8 +371,10 @@ export class GlobalAPI extends ParentAPI {
364371

365372
/**
366373
* Get current plan. Retrieve a pricing plan for the given Project, specified
367-
* by the ID of the Project.
374+
* by the ID of the Project. Deprecated, retention is now managed at the data
375+
* source level.
368376
*
377+
* @deprecated
369378
* @param request - The request {@link GlobalApiGetCurrentPlanRequest}
370379
* @returns A Promise of Plan
371380
*/
@@ -395,6 +404,21 @@ export class RegionalAPI extends ParentAPI {
395404
/** Lists the available regions of the API. */
396405
public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw']
397406

407+
/**
408+
* Get the Cockpit configuration.
409+
*
410+
* @param request - The request {@link RegionalApiGetConfigRequest}
411+
* @returns A Promise of GetConfigResponse
412+
*/
413+
getConfig = (request: Readonly<RegionalApiGetConfigRequest> = {}) =>
414+
this.client.fetch<GetConfigResponse>(
415+
{
416+
method: 'GET',
417+
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/config`,
418+
},
419+
unmarshalGetConfigResponse,
420+
)
421+
398422
/**
399423
* Create a data source. You must specify the data source type upon creation.
400424
* Available data source types include:

packages/clients/src/api/cockpit/v1/index.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type {
99
DataSource,
1010
DataSourceOrigin,
1111
DataSourceType,
12+
GetConfigResponse,
13+
GetConfigResponseRetention,
1214
GlobalApiCreateGrafanaUserRequest,
1315
GlobalApiDeleteGrafanaUserRequest,
1416
GlobalApiGetCurrentPlanRequest,
@@ -49,6 +51,7 @@ export type {
4951
RegionalApiEnableAlertManagerRequest,
5052
RegionalApiEnableManagedAlertsRequest,
5153
RegionalApiGetAlertManagerRequest,
54+
RegionalApiGetConfigRequest,
5255
RegionalApiGetDataSourceRequest,
5356
RegionalApiGetTokenRequest,
5457
RegionalApiGetUsageOverviewRequest,

packages/clients/src/api/cockpit/v1/marshalling.gen.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type {
1313
ContactPoint,
1414
ContactPointEmail,
1515
DataSource,
16+
GetConfigResponse,
17+
GetConfigResponseRetention,
1618
GlobalApiCreateGrafanaUserRequest,
1719
GlobalApiResetGrafanaUserPasswordRequest,
1820
GlobalApiSelectPlanRequest,
@@ -82,6 +84,7 @@ export const unmarshalDataSource = (data: unknown): DataSource => {
8284
origin: data.origin,
8385
projectId: data.project_id,
8486
region: data.region,
87+
retentionDays: data.retention_days,
8588
synchronizedWithGrafana: data.synchronized_with_grafana,
8689
type: data.type,
8790
updatedAt: unmarshalDate(data.updated_at),
@@ -175,6 +178,44 @@ export const unmarshalAlertManager = (data: unknown): AlertManager => {
175178
} as AlertManager
176179
}
177180

181+
const unmarshalGetConfigResponseRetention = (
182+
data: unknown,
183+
): GetConfigResponseRetention => {
184+
if (!isJSONObject(data)) {
185+
throw new TypeError(
186+
`Unmarshalling the type 'GetConfigResponseRetention' failed as data isn't a dictionary.`,
187+
)
188+
}
189+
190+
return {
191+
defaultDays: data.default_days,
192+
maxDays: data.max_days,
193+
minDays: data.min_days,
194+
} as GetConfigResponseRetention
195+
}
196+
197+
export const unmarshalGetConfigResponse = (
198+
data: unknown,
199+
): GetConfigResponse => {
200+
if (!isJSONObject(data)) {
201+
throw new TypeError(
202+
`Unmarshalling the type 'GetConfigResponse' failed as data isn't a dictionary.`,
203+
)
204+
}
205+
206+
return {
207+
logsRetention: data.logs_retention
208+
? unmarshalGetConfigResponseRetention(data.logs_retention)
209+
: undefined,
210+
metricsRetention: data.metrics_retention
211+
? unmarshalGetConfigResponseRetention(data.metrics_retention)
212+
: undefined,
213+
tracesRetention: data.traces_retention
214+
? unmarshalGetConfigResponseRetention(data.traces_retention)
215+
: undefined,
216+
} as GetConfigResponse
217+
}
218+
178219
export const unmarshalGrafana = (data: unknown): Grafana => {
179220
if (!isJSONObject(data)) {
180221
throw new TypeError(
@@ -424,6 +465,7 @@ export const marshalRegionalApiCreateDataSourceRequest = (
424465
): Record<string, unknown> => ({
425466
name: request.name,
426467
project_id: request.projectId ?? defaults.defaultProjectId,
468+
retention_days: request.retentionDays,
427469
type: request.type,
428470
})
429471

@@ -493,4 +535,5 @@ export const marshalRegionalApiUpdateDataSourceRequest = (
493535
defaults: DefaultValues,
494536
): Record<string, unknown> => ({
495537
name: request.name,
538+
retention_days: request.retentionDays,
496539
})

packages/clients/src/api/cockpit/v1/types.gen.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import type { Region } from '../../../bridge'
44

55
export type DataSourceOrigin = 'unknown_origin' | 'scaleway' | 'external'
66

7-
export type DataSourceType =
8-
| 'unknown_type'
9-
| 'metrics'
10-
| 'logs'
11-
| 'traces'
12-
| 'alerts'
7+
export type DataSourceType = 'unknown_type' | 'metrics' | 'logs' | 'traces'
138

149
export type GrafanaUserRole = 'unknown_role' | 'editor' | 'viewer'
1510

@@ -59,6 +54,12 @@ export interface ContactPointEmail {
5954
to: string
6055
}
6156

57+
export interface GetConfigResponseRetention {
58+
minDays: number
59+
maxDays: number
60+
defaultDays: number
61+
}
62+
6263
/** Contact point. */
6364
export interface ContactPoint {
6465
/**
@@ -94,6 +95,8 @@ export interface DataSource {
9495
updatedAt?: Date
9596
/** Indicates whether the data source is synchronized with Grafana. */
9697
synchronizedWithGrafana: boolean
98+
/** BETA - Duration for which the data will be retained in the data source. */
99+
retentionDays: number
97100
/** Region of the data source. */
98101
region: Region
99102
}
@@ -204,6 +207,16 @@ export interface AlertManager {
204207
region: Region
205208
}
206209

210+
/** Cockpit configuration. */
211+
export interface GetConfigResponse {
212+
/** Metrics retention configuration. */
213+
metricsRetention?: GetConfigResponseRetention
214+
/** Logs retention configuration. */
215+
logsRetention?: GetConfigResponseRetention
216+
/** Traces retention configuration. */
217+
tracesRetention?: GetConfigResponseRetention
218+
}
219+
207220
/** Create a Grafana user. */
208221
export type GlobalApiCreateGrafanaUserRequest = {
209222
/** ID of the Project in which to create the Grafana user. */
@@ -405,6 +418,8 @@ export type RegionalApiCreateDataSourceRequest = {
405418
name: string
406419
/** Data source type. */
407420
type?: DataSourceType
421+
/** Default values are 30 days for metrics, 7 days for logs and traces. */
422+
retentionDays?: number
408423
}
409424

410425
/** Create a token. */
@@ -516,6 +531,15 @@ export type RegionalApiGetAlertManagerRequest = {
516531
projectId?: string
517532
}
518533

534+
/** Get Cockpit configuration. */
535+
export type RegionalApiGetConfigRequest = {
536+
/**
537+
* Region to target. If none is passed will use default region from the
538+
* config.
539+
*/
540+
region?: Region
541+
}
542+
519543
/** Retrieve a data source. */
520544
export type RegionalApiGetDataSourceRequest = {
521545
/**
@@ -654,6 +678,8 @@ export type RegionalApiUpdateDataSourceRequest = {
654678
dataSourceId: string
655679
/** Updated name of the data source. */
656680
name?: string
681+
/** BETA - Duration for which the data will be retained in the data source. */
682+
retentionDays?: number
657683
}
658684

659685
export interface UsageOverview {

packages/clients/src/api/cockpit/v1/validation-rules.gen.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export const RegionalApiCreateDataSourceRequest = {
77
minLength: 3,
88
pattern: /^[A-Za-z0-9-_. ]+$/,
99
},
10+
retentionDays: {
11+
greaterThanOrEqual: 1,
12+
ignoreEmpty: true,
13+
lessThanOrEqual: 365,
14+
},
1015
}
1116

1217
export const RegionalApiCreateTokenRequest = {
@@ -59,8 +64,14 @@ export const RegionalApiListTokensRequest = {
5964

6065
export const RegionalApiUpdateDataSourceRequest = {
6166
name: {
67+
ignoreEmpty: true,
6268
maxLength: 50,
6369
minLength: 3,
6470
pattern: /^[A-Za-z0-9-_. ]+$/,
6571
},
72+
retentionDays: {
73+
greaterThanOrEqual: 1,
74+
ignoreEmpty: true,
75+
lessThanOrEqual: 365,
76+
},
6677
}

0 commit comments

Comments
 (0)