Skip to content

Commit

Permalink
chore(cockpit): add regional get cockpit metrics (scaleway#2321)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Nov 20, 2024
1 parent 7146d32 commit edea130
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions api/cockpit/v1/cockpit_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const (
DataSourceOriginUnknownOrigin = DataSourceOrigin("unknown_origin")
// Data source managed by Scaleway, used to store and query metrics and logs from Scaleway resources.
DataSourceOriginScaleway = DataSourceOrigin("scaleway")
// Data source created by the user, used to store and query metrics, logs and traces from user's external resources.
DataSourceOriginExternal = DataSourceOrigin("external")
// Data source created by the user, used to store and query metrics, logs and traces from user's custom resources.
DataSourceOriginCustom = DataSourceOrigin("custom")
)

func (enum DataSourceOrigin) String() string {
Expand All @@ -62,7 +62,7 @@ func (enum DataSourceOrigin) Values() []DataSourceOrigin {
return []DataSourceOrigin{
"unknown_origin",
"scaleway",
"external",
"custom",
}
}

Expand Down Expand Up @@ -725,6 +725,11 @@ type AlertManager struct {
Region scw.Region `json:"region"`
}

// CockpitMetrics: cockpit metrics.
type CockpitMetrics struct {
Timeseries []*scw.TimeSeries `json:"timeseries"`
}

// GetConfigResponse: Cockpit configuration.
type GetConfigResponse struct {
// CustomMetricsRetention: custom metrics retention configuration.
Expand Down Expand Up @@ -1185,6 +1190,17 @@ type RegionalAPIGetAlertManagerRequest struct {
ProjectID string `json:"project_id"`
}

// RegionalAPIGetCockpitMetricsRequest: regional api get cockpit metrics request.
type RegionalAPIGetCockpitMetricsRequest struct {
ProjectID string `json:"-"`

StartDate *time.Time `json:"-"`

EndDate *time.Time `json:"-"`

Query string `json:"-"`
}

// RegionalAPIGetConfigRequest: Get Cockpit configuration.
type RegionalAPIGetConfigRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -2471,3 +2487,33 @@ func (s *RegionalAPI) TriggerTestAlert(req *RegionalAPITriggerTestAlertRequest,
}
return nil
}

// GetCockpitMetrics:
func (s *RegionalAPI) GetCockpitMetrics(req *RegionalAPIGetCockpitMetricsRequest, opts ...scw.RequestOption) (*CockpitMetrics, error) {
var err error

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "project_id", req.ProjectID)
parameter.AddToQuery(query, "start_date", req.StartDate)
parameter.AddToQuery(query, "end_date", req.EndDate)
parameter.AddToQuery(query, "query", req.Query)

scwReq := &scw.ScalewayRequest{
Method: "GET",
Path: "/cockpit/v1beta1/cockpit/metrics",
Query: query,
}

var resp CockpitMetrics

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

0 comments on commit edea130

Please sign in to comment.