Skip to content

Commit 8d4e3c1

Browse files
rbajoria26yec-akamailgarber-akamai
authored
Adding ACLP monitor APIs (#722)
* Adding ACLP monitor APIs * updating variables names to avoid potential conflicting names * updating variables names to avoid potential conflicting names * updating variables names to avoid potential conflicting names * Update monitor_dashboards.go Co-authored-by: Ye Chen <[email protected]> * Update monitor_dashboards.go Co-authored-by: Lena Garber <[email protected]> * updated names for metric-definitions unit types * updating variables names to avoid potential conflicting names * updating variables names to avoid potential conflicting names --------- Co-authored-by: Ye Chen <[email protected]> Co-authored-by: Lena Garber <[email protected]>
1 parent e0741f6 commit 8d4e3c1

23 files changed

Lines changed: 7052 additions & 0 deletions

monitor_dashboards.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"time"
7+
8+
"github.com/linode/linodego/internal/parseabletime"
9+
)
10+
11+
// MonitorDashboard represents an ACLP Dashboard object
12+
type MonitorDashboard struct {
13+
ID int `json:"id"`
14+
Type DashboardType `json:"type"`
15+
ServiceType ServiceType `json:"service_type"`
16+
Label string `json:"label"`
17+
Created *time.Time `json:"-"`
18+
Updated *time.Time `json:"-"`
19+
Widgets []DashboardWidget `json:"widgets"`
20+
}
21+
22+
// enum object for serviceType
23+
type ServiceType string
24+
25+
const (
26+
ServiceTypeLinode ServiceType = "linode"
27+
ServiceTypeLKE ServiceType = "lke"
28+
ServiceTypeDBaaS ServiceType = "dbaas"
29+
ServiceTypeACLB ServiceType = "aclb"
30+
ServiceTypeNodeBalancer ServiceType = "nodebalancer"
31+
ServiceTypeObjectStorage ServiceType = "objectstorage"
32+
ServiceTypeVPC ServiceType = "vpc"
33+
ServiceTypeFirewallService ServiceType = "firewall"
34+
)
35+
36+
// enum object for DashboardType
37+
type DashboardType string
38+
39+
const (
40+
DashboardTypeStandard DashboardType = "standard"
41+
DashboardTypeCustom DashboardType = "custom"
42+
)
43+
44+
// DashboardWidget represents an ACLP DashboardWidget object
45+
type DashboardWidget struct {
46+
Metric string `json:"metric"`
47+
Unit string `json:"unit"`
48+
Label string `json:"label"`
49+
Color string `json:"color"`
50+
Size int `json:"size"`
51+
ChartType ChartType `json:"chart_type"`
52+
YLabel string `json:"y_label"`
53+
AggregateFunction AggregateFunction `json:"aggregate_function"`
54+
}
55+
56+
// Enum object for AggregateFunction
57+
type AggregateFunction string
58+
59+
const (
60+
AggregateFunctionMin AggregateFunction = "min"
61+
AggregateFunctionMax AggregateFunction = "max"
62+
AggregateFunctionAvg AggregateFunction = "avg"
63+
AggregateFunctionSum AggregateFunction = "sum"
64+
AggregateFunctionRate AggregateFunction = "rate"
65+
AggregateFunctionIncrease AggregateFunction = "increase"
66+
AggregateFunctionCount AggregateFunction = "count"
67+
AggregateFunctionLast AggregateFunction = "last"
68+
)
69+
70+
// Enum object for Chart type
71+
type ChartType string
72+
73+
const (
74+
ChartTypeLine ChartType = "line"
75+
ChartTypeArea ChartType = "area"
76+
)
77+
78+
// ListMonitorDashboards lists all the ACLP Monitor Dashboards
79+
func (c *Client) ListMonitorDashboards(ctx context.Context, opts *ListOptions) ([]MonitorDashboard, error) {
80+
return getPaginatedResults[MonitorDashboard](ctx, c, "monitor/dashboards", opts)
81+
}
82+
83+
// GetMonitorDashboard gets an ACLP Monitor Dashboard for a given dashboardID
84+
func (c *Client) GetMonitorDashboard(ctx context.Context, dashboardID int) (*MonitorDashboard, error) {
85+
e := formatAPIPath("monitor/dashboards/%d", dashboardID)
86+
return doGETRequest[MonitorDashboard](ctx, c, e)
87+
}
88+
89+
// ListMonitorDashboardsByServiceType lists ACLP Monitor Dashboards for a given serviceType
90+
func (c *Client) ListMonitorDashboardsByServiceType(ctx context.Context, serviceType string, opts *ListOptions) ([]MonitorDashboard, error) {
91+
e := formatAPIPath("monitor/services/%s/dashboards", serviceType)
92+
return getPaginatedResults[MonitorDashboard](ctx, c, e, opts)
93+
}
94+
95+
// UnmarshalJSON implements the json.Unmarshaler interface
96+
func (i *MonitorDashboard) UnmarshalJSON(b []byte) error {
97+
type Mask MonitorDashboard
98+
99+
p := struct {
100+
*Mask
101+
Created *parseabletime.ParseableTime `json:"created"`
102+
Updated *parseabletime.ParseableTime `json:"updated"`
103+
}{
104+
Mask: (*Mask)(i),
105+
}
106+
107+
if err := json.Unmarshal(b, &p); err != nil {
108+
return err
109+
}
110+
111+
i.Created = (*time.Time)(p.Created)
112+
i.Updated = (*time.Time)(p.Updated)
113+
114+
return nil
115+
}

monitor_metrics_definitions.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// MonitorMetricsDefinition represents an ACLP MetricsDefinition object
8+
type MonitorMetricsDefinition struct {
9+
AvailableAggregateFunctions []AggregateFunction `json:"available_aggregate_functions"`
10+
Dimensions []MonitorDimension `json:"dimensions"`
11+
IsAlertable bool `json:"is_alertable"`
12+
Label string `json:"label"`
13+
Metric string `json:"metric"`
14+
MetricType MetricType `json:"metric_type"`
15+
ScrapeInterval string `json:"scrape_interval"`
16+
Unit MetricUnit `json:"unit"`
17+
}
18+
19+
// Enum object for MetricType
20+
type MetricType string
21+
22+
const (
23+
MetricTypeCounter MetricType = "counter"
24+
MetricTypeHistogram MetricType = "histogram"
25+
MetricTypeGauge MetricType = "gauge"
26+
MetricTypeSummary MetricType = "summary"
27+
)
28+
29+
// Enum object for Unit
30+
type MetricUnit string
31+
32+
const (
33+
MetricUnitCount MetricUnit = "count"
34+
MetricUnitPercent MetricUnit = "percent"
35+
MetricUnitByte MetricUnit = "byte"
36+
MetricUnitSecond MetricUnit = "second"
37+
MetricUnitBitsPerSecond MetricUnit = "bits_per_second"
38+
MetricUnitMillisecond MetricUnit = "millisecond"
39+
MetricUnitKB MetricUnit = "KB"
40+
MetricUnitMB MetricUnit = "MB"
41+
MetricUnitGB MetricUnit = "GB"
42+
MetricUnitRate MetricUnit = "rate"
43+
MetricUnitBytesPerSecond MetricUnit = "bytes_per_second"
44+
MetricUnitPercentile MetricUnit = "percentile"
45+
MetricUnitRatio MetricUnit = "ratio"
46+
MetricUnitOpsPerSecond MetricUnit = "ops_per_second"
47+
MetricUnitIops MetricUnit = "iops"
48+
)
49+
50+
// MonitorDimension represents an ACLP MonitorDimension object
51+
type MonitorDimension struct {
52+
DimensionLabel string `json:"dimension_label"`
53+
Label string `json:"label"`
54+
Values []string `json:"values"`
55+
}
56+
57+
// ListMonitorMetricsDefinitionByServiceType lists metric definitions
58+
func (c *Client) ListMonitorMetricsDefinitionByServiceType(ctx context.Context, serviceType string, opts *ListOptions) ([]MonitorMetricsDefinition, error) {
59+
e := formatAPIPath("monitor/services/%s/metric-definitions", serviceType)
60+
return getPaginatedResults[MonitorMetricsDefinition](ctx, c, e, opts)
61+
}

monitor_services.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// MonitorService represents a MonitorService object
8+
type MonitorService struct {
9+
Label string `json:"label"`
10+
ServiceType string `json:"service_type"`
11+
}
12+
13+
// ListMonitorServices lists all the registered ACLP MonitorServices
14+
func (c *Client) ListMonitorServices(ctx context.Context, opts *ListOptions) ([]MonitorService, error) {
15+
return getPaginatedResults[MonitorService](ctx, c, "monitor/services", opts)
16+
}
17+
18+
// ListMonitorServiceByType lists monitor services by a given service_type
19+
func (c *Client) ListMonitorServiceByType(ctx context.Context, serviceType string, opts *ListOptions) ([]MonitorService, error) {
20+
e := formatAPIPath("monitor/services/%s", serviceType)
21+
return getPaginatedResults[MonitorService](ctx, c, e, opts)
22+
}

monitor_services_create_token.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// MonitorServiceToken represents a MonitorServiceToken object
8+
type MonitorServiceToken struct {
9+
Token string `json:"token"`
10+
}
11+
12+
// Create token options
13+
type MonitorTokenCreateOptions struct {
14+
EntityIDs []int `json:"entity_ids"`
15+
}
16+
17+
// CreateMonitorServiceTokenForServiceType to create token for a given serviceType
18+
func (c *Client) CreateMonitorServiceTokenForServiceType(ctx context.Context, serviceType string, opts MonitorTokenCreateOptions) (*MonitorServiceToken, error) {
19+
e := formatAPIPath("monitor/services/%s/token", serviceType)
20+
return doPOSTRequest[MonitorServiceToken](ctx, c, e, opts)
21+
}

0 commit comments

Comments
 (0)