Skip to content

Commit b6b9e54

Browse files
authored
feat(cockpit): add retention setup in datasource (scaleway#2294)
1 parent ea71690 commit b6b9e54

File tree

1 file changed

+69
-6
lines changed

1 file changed

+69
-6
lines changed

api/cockpit/v1/cockpit_sdk.go

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ const (
9292
DataSourceTypeLogs = DataSourceType("logs")
9393
// Traces data source type, used to store and query traces using Grafana Tempo.
9494
DataSourceTypeTraces = DataSourceType("traces")
95-
// Alerts data source type, used as an endpoint for firing alerts using the Grafana Mimir alert manager.
96-
DataSourceTypeAlerts = DataSourceType("alerts")
9795
)
9896

9997
func (enum DataSourceType) String() string {
@@ -110,7 +108,6 @@ func (enum DataSourceType) Values() []DataSourceType {
110108
"metrics",
111109
"logs",
112110
"traces",
113-
"alerts",
114111
}
115112
}
116113

@@ -524,6 +521,15 @@ type ContactPointEmail struct {
524521
To string `json:"to"`
525522
}
526523

524+
// GetConfigResponseRetention: get config response retention.
525+
type GetConfigResponseRetention struct {
526+
MinDays uint32 `json:"min_days"`
527+
528+
MaxDays uint32 `json:"max_days"`
529+
530+
DefaultDays uint32 `json:"default_days"`
531+
}
532+
527533
// ContactPoint: Contact point.
528534
type ContactPoint struct {
529535
// Email: email address to send alerts to.
@@ -565,6 +571,9 @@ type DataSource struct {
565571
// SynchronizedWithGrafana: indicates whether the data source is synchronized with Grafana.
566572
SynchronizedWithGrafana bool `json:"synchronized_with_grafana"`
567573

574+
// RetentionDays: bETA - Duration for which the data will be retained in the data source.
575+
RetentionDays uint32 `json:"retention_days"`
576+
568577
// Region: region of the data source.
569578
Region scw.Region `json:"region"`
570579
}
@@ -716,6 +725,18 @@ type AlertManager struct {
716725
Region scw.Region `json:"region"`
717726
}
718727

728+
// GetConfigResponse: Cockpit configuration.
729+
type GetConfigResponse struct {
730+
// MetricsRetention: metrics retention configuration.
731+
MetricsRetention *GetConfigResponseRetention `json:"metrics_retention"`
732+
733+
// LogsRetention: logs retention configuration.
734+
LogsRetention *GetConfigResponseRetention `json:"logs_retention"`
735+
736+
// TracesRetention: traces retention configuration.
737+
TracesRetention *GetConfigResponseRetention `json:"traces_retention"`
738+
}
739+
719740
// GlobalAPICreateGrafanaUserRequest: Create a Grafana user.
720741
type GlobalAPICreateGrafanaUserRequest struct {
721742
// ProjectID: ID of the Project in which to create the Grafana user.
@@ -1062,6 +1083,9 @@ type RegionalAPICreateDataSourceRequest struct {
10621083
// Type: data source type.
10631084
// Default value: unknown_type
10641085
Type DataSourceType `json:"type"`
1086+
1087+
// RetentionDays: default values are 30 days for metrics, 7 days for logs and traces.
1088+
RetentionDays *uint32 `json:"retention_days,omitempty"`
10651089
}
10661090

10671091
// RegionalAPICreateTokenRequest: Create a token.
@@ -1155,6 +1179,12 @@ type RegionalAPIGetAlertManagerRequest struct {
11551179
ProjectID string `json:"project_id"`
11561180
}
11571181

1182+
// RegionalAPIGetConfigRequest: Get Cockpit configuration.
1183+
type RegionalAPIGetConfigRequest struct {
1184+
// Region: region to target. If none is passed will use default region from the config.
1185+
Region scw.Region `json:"-"`
1186+
}
1187+
11581188
// RegionalAPIGetDataSourceRequest: Retrieve a data source.
11591189
type RegionalAPIGetDataSourceRequest struct {
11601190
// Region: region to target. If none is passed will use default region from the config.
@@ -1284,6 +1314,9 @@ type RegionalAPIUpdateDataSourceRequest struct {
12841314

12851315
// Name: updated name of the data source.
12861316
Name *string `json:"name,omitempty"`
1317+
1318+
// RetentionDays: bETA - Duration for which the data will be retained in the data source.
1319+
RetentionDays *uint32 `json:"retention_days,omitempty"`
12871320
}
12881321

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

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

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

1589-
// 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.
1623+
// 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.
1624+
// Deprecated, retention is now managed at the data source level.
15901625
func (s *GlobalAPI) SelectPlan(req *GlobalAPISelectPlanRequest, opts ...scw.RequestOption) (*Plan, error) {
15911626
var err error
15921627

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

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

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

1695+
// GetConfig: Get the Cockpit configuration.
1696+
func (s *RegionalAPI) GetConfig(req *RegionalAPIGetConfigRequest, opts ...scw.RequestOption) (*GetConfigResponse, error) {
1697+
var err error
1698+
1699+
if req.Region == "" {
1700+
defaultRegion, _ := s.client.GetDefaultRegion()
1701+
req.Region = defaultRegion
1702+
}
1703+
1704+
if fmt.Sprint(req.Region) == "" {
1705+
return nil, errors.New("field Region cannot be empty in request")
1706+
}
1707+
1708+
scwReq := &scw.ScalewayRequest{
1709+
Method: "GET",
1710+
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/config",
1711+
}
1712+
1713+
var resp GetConfigResponse
1714+
1715+
err = s.client.Do(scwReq, &resp, opts...)
1716+
if err != nil {
1717+
return nil, err
1718+
}
1719+
return &resp, nil
1720+
}
1721+
16591722
// CreateDataSource: You must specify the data source type upon creation. Available data source types include:
16601723
// - metrics
16611724
// - logs

0 commit comments

Comments
 (0)