Skip to content

feat(cockpit): create datasource #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 53 additions & 39 deletions packages/clients/src/api/cockpit/v1beta1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { COCKPIT_TRANSIENT_STATUSES } from './content.gen'
import {
marshalActivateCockpitRequest,
marshalCreateContactPointRequest,
marshalCreateDatasourceRequest,
marshalCreateGrafanaUserRequest,
marshalCreateTokenRequest,
marshalDeactivateCockpitRequest,
Expand All @@ -26,6 +27,7 @@ import {
unmarshalCockpit,
unmarshalCockpitMetrics,
unmarshalContactPoint,
unmarshalDatasource,
unmarshalGrafanaUser,
unmarshalListContactPointsResponse,
unmarshalListGrafanaUsersResponse,
Expand All @@ -40,8 +42,10 @@ import type {
CockpitMetrics,
ContactPoint,
CreateContactPointRequest,
CreateDatasourceRequest,
CreateGrafanaUserRequest,
CreateTokenRequest,
Datasource,
DeactivateCockpitRequest,
DeleteContactPointRequest,
DeleteGrafanaUserRequest,
Expand Down Expand Up @@ -75,13 +79,13 @@ const jsonContentHeaders = {
/**
* Cockpit API.
*
* Cockpit API. Cockpit's API allows you to activate your Cockpit on your
* Projects. Scaleway's Cockpit stores metrics and logs and provides a dedicated
* Grafana for dashboarding to visualize them.
* Cockpit's API allows you to activate your Cockpit on your Projects.
* Scaleway's Cockpit stores metrics and logs and provides a dedicated Grafana
* for dashboarding to visualize them. Cockpit API.
*/
export class API extends ParentAPI {
/**
* Activate a Cockpit. Activate the Cockpit of the specified Project ID.
* Activate the Cockpit of the specified Project ID.
*
* @param request - The request {@link ActivateCockpitRequest}
* @returns A Promise of Cockpit
Expand All @@ -100,7 +104,7 @@ export class API extends ParentAPI {
)

/**
* Get a Cockpit. Retrieve the Cockpit of the specified Project ID.
* Retrieve the Cockpit of the specified Project ID.
*
* @param request - The request {@link GetCockpitRequest}
* @returns A Promise of Cockpit
Expand Down Expand Up @@ -139,8 +143,7 @@ export class API extends ParentAPI {
)

/**
* Get Cockpit metrics. Get metrics from your Cockpit with the specified
* Project ID.
* Get metrics from your Cockpit with the specified Project ID.
*
* @param request - The request {@link GetCockpitMetricsRequest}
* @returns A Promise of CockpitMetrics
Expand All @@ -164,7 +167,7 @@ export class API extends ParentAPI {
)

/**
* Deactivate a Cockpit. Deactivate the Cockpit of the specified Project ID.
* Deactivate the Cockpit of the specified Project ID.
*
* @param request - The request {@link DeactivateCockpitRequest}
* @returns A Promise of Cockpit
Expand All @@ -183,8 +186,7 @@ export class API extends ParentAPI {
)

/**
* Reset a Grafana. Reset your Cockpit's Grafana associated with the specified
* Project ID.
* Reset your Cockpit's Grafana associated with the specified Project ID.
*
* @param request - The request {@link ResetCockpitGrafanaRequest}
* @returns A Promise of Cockpit
Expand All @@ -203,7 +205,26 @@ export class API extends ParentAPI {
)

/**
* Create a token. Create a token associated with the specified Project ID.
* Create a datasource for the specified Project ID and the given type.
*
* @param request - The request {@link CreateDatasourceRequest}
* @returns A Promise of Datasource
*/
createDatasource = (request: Readonly<CreateDatasourceRequest>) =>
this.client.fetch<Datasource>(
{
body: JSON.stringify(
marshalCreateDatasourceRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/cockpit/v1beta1/datasources`,
},
unmarshalDatasource,
)

/**
* Create a token associated with the specified Project ID.
*
* @param request - The request {@link CreateTokenRequest}
* @returns A Promise of Token
Expand Down Expand Up @@ -243,7 +264,7 @@ export class API extends ParentAPI {
)

/**
* List tokens. Get a list of tokens associated with the specified Project ID.
* Get a list of tokens associated with the specified Project ID.
*
* @param request - The request {@link ListTokensRequest}
* @returns A Promise of ListTokensResponse
Expand All @@ -252,7 +273,7 @@ export class API extends ParentAPI {
enrichForPagination('tokens', this.pageOfListTokens, request)

/**
* Get a token. Retrieve the token associated with the specified token ID.
* Retrieve the token associated with the specified token ID.
*
* @param request - The request {@link GetTokenRequest}
* @returns A Promise of Token
Expand All @@ -270,7 +291,7 @@ export class API extends ParentAPI {
)

/**
* Delete a token. Delete the token associated with the specified token ID.
* Delete the token associated with the specified token ID.
*
* @param request - The request {@link DeleteTokenRequest}
*/
Expand All @@ -284,8 +305,7 @@ export class API extends ParentAPI {
})

/**
* Create a contact point. Create a contact point to receive alerts for the
* default receiver.
* Create a contact point to receive alerts for the default receiver.
*
* @param request - The request {@link CreateContactPointRequest}
* @returns A Promise of ContactPoint
Expand Down Expand Up @@ -326,8 +346,8 @@ export class API extends ParentAPI {
)

/**
* List contact points. Get a list of contact points for the Cockpit
* associated with the specified Project ID.
* Get a list of contact points for the Cockpit associated with the specified
* Project ID.
*
* @param request - The request {@link ListContactPointsRequest}
* @returns A Promise of ListContactPointsResponse
Expand All @@ -336,8 +356,7 @@ export class API extends ParentAPI {
enrichForPagination('contactPoints', this.pageOfListContactPoints, request)

/**
* Delete an alert contact point. Delete a contact point for the default
* receiver.
* Delete a contact point for the default receiver.
*
* @param request - The request {@link DeleteContactPointRequest}
*/
Expand All @@ -352,8 +371,7 @@ export class API extends ParentAPI {
})

/**
* Enable managed alerts. Enable the sending of managed alerts for the
* specified Project's Cockpit.
* Enable the sending of managed alerts for the specified Project's Cockpit.
*
* @param request - The request {@link EnableManagedAlertsRequest}
*/
Expand All @@ -368,8 +386,7 @@ export class API extends ParentAPI {
})

/**
* Disable managed alerts. Disable the sending of managed alerts for the
* specified Project's Cockpit.
* Disable the sending of managed alerts for the specified Project's Cockpit.
*
* @param request - The request {@link DisableManagedAlertsRequest}
*/
Expand All @@ -386,8 +403,7 @@ export class API extends ParentAPI {
})

/**
* Trigger a test alert. Trigger a test alert to all of the Cockpit's
* receivers.
* Trigger a test alert to all of the Cockpit's receivers.
*
* @param request - The request {@link TriggerTestAlertRequest}
*/
Expand All @@ -402,9 +418,8 @@ export class API extends ParentAPI {
})

/**
* Create a Grafana user. Create a Grafana user for your Cockpit's Grafana
* instance. Make sure you save the automatically-generated password and the
* Grafana user ID.
* Create a Grafana user for your Cockpit's Grafana instance. Make sure you
* save the automatically-generated password and the Grafana user ID.
*
* @param request - The request {@link CreateGrafanaUserRequest}
* @returns A Promise of GrafanaUser
Expand Down Expand Up @@ -446,8 +461,8 @@ export class API extends ParentAPI {
)

/**
* List Grafana users. Get a list of Grafana users who are able to connect to
* the Cockpit's Grafana instance.
* Get a list of Grafana users who are able to connect to the Cockpit's
* Grafana instance.
*
* @param request - The request {@link ListGrafanaUsersRequest}
* @returns A Promise of ListGrafanaUsersResponse
Expand All @@ -456,8 +471,8 @@ export class API extends ParentAPI {
enrichForPagination('grafanaUsers', this.pageOfListGrafanaUsers, request)

/**
* Delete a Grafana user. Delete a Grafana user from a Grafana instance,
* specified by the Cockpit's Project ID and the Grafana user ID.
* Delete a Grafana user from a Grafana instance, specified by the Cockpit's
* Project ID and the Grafana user ID.
*
* @param request - The request {@link DeleteGrafanaUserRequest}
*/
Expand All @@ -475,8 +490,8 @@ export class API extends ParentAPI {
})

/**
* Reset a Grafana user's password. Reset a Grafana user's password specified
* by the Cockpit's Project ID and the Grafana user ID.
* Reset a Grafana user's password specified by the Cockpit's Project ID and
* the Grafana user ID.
*
* @param request - The request {@link ResetGrafanaUserPasswordRequest}
* @returns A Promise of GrafanaUser
Expand Down Expand Up @@ -517,7 +532,7 @@ export class API extends ParentAPI {
)

/**
* List pricing plans. Get a list of all pricing plans available.
* Get a list of all pricing plans available.
*
* @param request - The request {@link ListPlansRequest}
* @returns A Promise of ListPlansResponse
Expand All @@ -526,9 +541,8 @@ export class API extends ParentAPI {
enrichForPagination('plans', this.pageOfListPlans, request)

/**
* Select pricing plan. Select your chosen pricing plan for your Cockpit,
* specifying the Cockpit's Project ID and the pricing plan's ID in the
* request.
* Select your chosen pricing plan for your Cockpit, specifying the Cockpit's
* Project ID and the pricing plan's ID in the request.
*
* @param request - The request {@link SelectPlanRequest}
* @returns A Promise of SelectPlanResponse
Expand Down
3 changes: 3 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ export type {
ContactPoint,
ContactPointEmail,
CreateContactPointRequest,
CreateDatasourceRequest,
CreateGrafanaUserRequest,
CreateTokenRequest,
Datasource,
DatasourceType,
DeactivateCockpitRequest,
DeleteContactPointRequest,
DeleteGrafanaUserRequest,
Expand Down
27 changes: 27 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import type {
ContactPoint,
ContactPointEmail,
CreateContactPointRequest,
CreateDatasourceRequest,
CreateGrafanaUserRequest,
CreateTokenRequest,
Datasource,
DeactivateCockpitRequest,
DeleteContactPointRequest,
DeleteGrafanaUserRequest,
Expand Down Expand Up @@ -179,6 +181,22 @@ export const unmarshalCockpitMetrics = (data: unknown) => {
} as CockpitMetrics
}

export const unmarshalDatasource = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'Datasource' failed as data isn't a dictionary.`,
)
}

return {
id: data.id,
name: data.name,
projectId: data.project_id,
type: data.type,
url: data.url,
} as Datasource
}

export const unmarshalListContactPointsResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -302,6 +320,15 @@ export const marshalCreateContactPointRequest = (
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalCreateDatasourceRequest = (
request: CreateDatasourceRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
name: request.name,
project_id: request.projectId ?? defaults.defaultProjectId,
type: request.type ?? 'unknown_datasource_type',
})

export const marshalCreateGrafanaUserRequest = (
request: CreateGrafanaUserRequest,
defaults: DefaultValues,
Expand Down
30 changes: 30 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export type CockpitStatus =
| 'updating'
| 'error'

export type DatasourceType =
| 'unknown_datasource_type'
| 'metrics'
| 'logs'
| 'traces'
| 'alerts'

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

export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc'
Expand Down Expand Up @@ -74,6 +81,20 @@ export interface ContactPointEmail {
to: string
}

/** Datasource. */
export interface Datasource {
/** ID of the datasource. */
id: string
/** ID of the Project the Cockpit belongs to. */
projectId: string
/** Datasource name. */
name: string
/** Datasource URL. */
url: string
/** Datasource type. */
type: DatasourceType
}

/** Grafana user. */
export interface GrafanaUser {
/** ID of the Grafana user. */
Expand Down Expand Up @@ -217,6 +238,15 @@ export type ResetCockpitGrafanaRequest = {
projectId?: string
}

export type CreateDatasourceRequest = {
/** ID of the Project the Cockpit belongs to. */
projectId?: string
/** Datasource name. */
name: string
/** Datasource type. */
type?: DatasourceType
}

export type CreateTokenRequest = {
/** ID of the Project. */
projectId?: string
Expand Down