Skip to content

Commit bd2b866

Browse files
authored
feat(cockpit): add getRulesCount endpoint (scaleway#2623)
1 parent 4421125 commit bd2b866

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

api/cockpit/v1/cockpit_sdk.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,18 @@ type GetConfigResponseRetention struct {
550550
DefaultDays uint32 `json:"default_days"`
551551
}
552552

553+
// RulesCount: rules count.
554+
type RulesCount struct {
555+
// DataSourceID: ID of the data source.
556+
DataSourceID string `json:"data_source_id"`
557+
558+
// DataSourceName: name of the data source.
559+
DataSourceName string `json:"data_source_name"`
560+
561+
// RulesCount: total count of rules associated with this data source.
562+
RulesCount int32 `json:"rules_count"`
563+
}
564+
553565
// Alert: Structure representing an alert.
554566
type Alert struct {
555567
// Region: the region in which the alert is defined.
@@ -799,6 +811,18 @@ type GetConfigResponse struct {
799811
ProductLogsRetention *GetConfigResponseRetention `json:"product_logs_retention"`
800812
}
801813

814+
// GetRulesCountResponse: get rules count response.
815+
type GetRulesCountResponse struct {
816+
// RulesCountByDatasource: total count of rules grouped by data source.
817+
RulesCountByDatasource []*RulesCount `json:"rules_count_by_datasource"`
818+
819+
// PreconfiguredRulesCount: total count of preconfigured rules.
820+
PreconfiguredRulesCount int32 `json:"preconfigured_rules_count"`
821+
822+
// CustomRulesCount: total count of custom rules.
823+
CustomRulesCount int32 `json:"custom_rules_count"`
824+
}
825+
802826
// GlobalAPICreateGrafanaUserRequest: Create a Grafana user.
803827
type GlobalAPICreateGrafanaUserRequest struct {
804828
// ProjectID: ID of the Project in which to create the Grafana user.
@@ -1283,6 +1307,15 @@ type RegionalAPIGetDataSourceRequest struct {
12831307
DataSourceID string `json:"-"`
12841308
}
12851309

1310+
// RegionalAPIGetRulesCountRequest: regional api get rules count request.
1311+
type RegionalAPIGetRulesCountRequest struct {
1312+
// Region: region to target. If none is passed will use default region from the config.
1313+
Region scw.Region `json:"-"`
1314+
1315+
// ProjectID: ID of the Project to retrieve the rule count for.
1316+
ProjectID string `json:"project_id"`
1317+
}
1318+
12861319
// RegionalAPIGetTokenRequest: Get a token.
12871320
type RegionalAPIGetTokenRequest struct {
12881321
// Region: region to target. If none is passed will use default region from the config.
@@ -2300,6 +2333,42 @@ func (s *RegionalAPI) DisableAlertManager(req *RegionalAPIDisableAlertManagerReq
23002333
return &resp, nil
23012334
}
23022335

2336+
// GetRulesCount: Get a detailed count of enabled rules in the specified Project. Includes preconfigured and custom alerting and recording rules.
2337+
func (s *RegionalAPI) GetRulesCount(req *RegionalAPIGetRulesCountRequest, opts ...scw.RequestOption) (*GetRulesCountResponse, error) {
2338+
var err error
2339+
2340+
if req.Region == "" {
2341+
defaultRegion, _ := s.client.GetDefaultRegion()
2342+
req.Region = defaultRegion
2343+
}
2344+
2345+
if req.ProjectID == "" {
2346+
defaultProjectID, _ := s.client.GetDefaultProjectID()
2347+
req.ProjectID = defaultProjectID
2348+
}
2349+
2350+
query := url.Values{}
2351+
parameter.AddToQuery(query, "project_id", req.ProjectID)
2352+
2353+
if fmt.Sprint(req.Region) == "" {
2354+
return nil, errors.New("field Region cannot be empty in request")
2355+
}
2356+
2357+
scwReq := &scw.ScalewayRequest{
2358+
Method: "GET",
2359+
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/rules/count",
2360+
Query: query,
2361+
}
2362+
2363+
var resp GetRulesCountResponse
2364+
2365+
err = s.client.Do(scwReq, &resp, opts...)
2366+
if err != nil {
2367+
return nil, err
2368+
}
2369+
return &resp, nil
2370+
}
2371+
23032372
// CreateContactPoint: Contact points are email addresses associated with the default receiver, that the Alert manager sends alerts to.
23042373
// The source of the alerts are data sources within the same Project and region as the Alert manager.
23052374
// If you need to receive alerts for other receivers, you can create additional contact points and receivers in Grafana. Make sure that you select the Scaleway Alert manager.

0 commit comments

Comments
 (0)