Skip to content

Commit

Permalink
feat(cockpit): add retention setup in datasource (scaleway#2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Nov 4, 2024
1 parent ea71690 commit b6b9e54
Showing 1 changed file with 69 additions and 6 deletions.
75 changes: 69 additions & 6 deletions api/cockpit/v1/cockpit_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ const (
DataSourceTypeLogs = DataSourceType("logs")
// Traces data source type, used to store and query traces using Grafana Tempo.
DataSourceTypeTraces = DataSourceType("traces")
// Alerts data source type, used as an endpoint for firing alerts using the Grafana Mimir alert manager.
DataSourceTypeAlerts = DataSourceType("alerts")
)

func (enum DataSourceType) String() string {
Expand All @@ -110,7 +108,6 @@ func (enum DataSourceType) Values() []DataSourceType {
"metrics",
"logs",
"traces",
"alerts",
}
}

Expand Down Expand Up @@ -524,6 +521,15 @@ type ContactPointEmail struct {
To string `json:"to"`
}

// GetConfigResponseRetention: get config response retention.
type GetConfigResponseRetention struct {
MinDays uint32 `json:"min_days"`

MaxDays uint32 `json:"max_days"`

DefaultDays uint32 `json:"default_days"`
}

// ContactPoint: Contact point.
type ContactPoint struct {
// Email: email address to send alerts to.
Expand Down Expand Up @@ -565,6 +571,9 @@ type DataSource struct {
// SynchronizedWithGrafana: indicates whether the data source is synchronized with Grafana.
SynchronizedWithGrafana bool `json:"synchronized_with_grafana"`

// RetentionDays: bETA - Duration for which the data will be retained in the data source.
RetentionDays uint32 `json:"retention_days"`

// Region: region of the data source.
Region scw.Region `json:"region"`
}
Expand Down Expand Up @@ -716,6 +725,18 @@ type AlertManager struct {
Region scw.Region `json:"region"`
}

// GetConfigResponse: Cockpit configuration.
type GetConfigResponse struct {
// MetricsRetention: metrics retention configuration.
MetricsRetention *GetConfigResponseRetention `json:"metrics_retention"`

// LogsRetention: logs retention configuration.
LogsRetention *GetConfigResponseRetention `json:"logs_retention"`

// TracesRetention: traces retention configuration.
TracesRetention *GetConfigResponseRetention `json:"traces_retention"`
}

// GlobalAPICreateGrafanaUserRequest: Create a Grafana user.
type GlobalAPICreateGrafanaUserRequest struct {
// ProjectID: ID of the Project in which to create the Grafana user.
Expand Down Expand Up @@ -1062,6 +1083,9 @@ type RegionalAPICreateDataSourceRequest struct {
// Type: data source type.
// Default value: unknown_type
Type DataSourceType `json:"type"`

// RetentionDays: default values are 30 days for metrics, 7 days for logs and traces.
RetentionDays *uint32 `json:"retention_days,omitempty"`
}

// RegionalAPICreateTokenRequest: Create a token.
Expand Down Expand Up @@ -1155,6 +1179,12 @@ type RegionalAPIGetAlertManagerRequest struct {
ProjectID string `json:"project_id"`
}

// RegionalAPIGetConfigRequest: Get Cockpit configuration.
type RegionalAPIGetConfigRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Region scw.Region `json:"-"`
}

// RegionalAPIGetDataSourceRequest: Retrieve a data source.
type RegionalAPIGetDataSourceRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -1284,6 +1314,9 @@ type RegionalAPIUpdateDataSourceRequest struct {

// Name: updated name of the data source.
Name *string `json:"name,omitempty"`

// RetentionDays: bETA - Duration for which the data will be retained in the data source.
RetentionDays *uint32 `json:"retention_days,omitempty"`
}

// UsageOverview: usage overview.
Expand Down Expand Up @@ -1557,7 +1590,8 @@ func (s *GlobalAPI) GetGrafanaProductDashboard(req *GlobalAPIGetGrafanaProductDa
return &resp, nil
}

// ListPlans: Retrieve a list of available pricing plan types.
// Deprecated: ListPlans: Retrieve a list of available pricing plan types.
// Deprecated, retention is now managed at the data source level.
func (s *GlobalAPI) ListPlans(req *GlobalAPIListPlansRequest, opts ...scw.RequestOption) (*ListPlansResponse, error) {
var err error

Expand Down Expand Up @@ -1586,7 +1620,8 @@ func (s *GlobalAPI) ListPlans(req *GlobalAPIListPlansRequest, opts ...scw.Reques
return &resp, nil
}

// SelectPlan: Apply a pricing plan on a given Project. You must specify the ID of the pricing plan type. Note that you will be billed for the plan you apply.
// Deprecated: SelectPlan: Apply a pricing plan on a given Project. You must specify the ID of the pricing plan type. Note that you will be billed for the plan you apply.
// Deprecated, retention is now managed at the data source level.
func (s *GlobalAPI) SelectPlan(req *GlobalAPISelectPlanRequest, opts ...scw.RequestOption) (*Plan, error) {
var err error

Expand Down Expand Up @@ -1614,7 +1649,8 @@ func (s *GlobalAPI) SelectPlan(req *GlobalAPISelectPlanRequest, opts ...scw.Requ
return &resp, nil
}

// GetCurrentPlan: Retrieve a pricing plan for the given Project, specified by the ID of the Project.
// Deprecated: GetCurrentPlan: Retrieve a pricing plan for the given Project, specified by the ID of the Project.
// Deprecated, retention is now managed at the data source level.
func (s *GlobalAPI) GetCurrentPlan(req *GlobalAPIGetCurrentPlanRequest, opts ...scw.RequestOption) (*Plan, error) {
var err error

Expand Down Expand Up @@ -1656,6 +1692,33 @@ func (s *RegionalAPI) Regions() []scw.Region {
return []scw.Region{scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw}
}

// GetConfig: Get the Cockpit configuration.
func (s *RegionalAPI) GetConfig(req *RegionalAPIGetConfigRequest, opts ...scw.RequestOption) (*GetConfigResponse, error) {
var err error

if req.Region == "" {
defaultRegion, _ := s.client.GetDefaultRegion()
req.Region = defaultRegion
}

if fmt.Sprint(req.Region) == "" {
return nil, errors.New("field Region cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "GET",
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/config",
}

var resp GetConfigResponse

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// CreateDataSource: You must specify the data source type upon creation. Available data source types include:
// - metrics
// - logs
Expand Down

0 comments on commit b6b9e54

Please sign in to comment.