Skip to content

Commit

Permalink
chore: add checkpoints select support
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Nov 30, 2022
1 parent cfa82c4 commit f5e9921
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 10 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ This can be an interval from `1` to `60` minutes.

This can be used to add the monitor to a Monitor Group identified with a `MonitorGroupID`.

### `uptrends.ionos-cloud.github.io/monitor.regions` Default:`""`

This is a list of regions to include as checkpoints. An example `"54,1007"`

### `uptrends.ionos-cloud.github.io/monitor.checkpoints` Default:`""`

This is a list of point of presence to include.

### `uptrends.ionos-cloud.github.io/monitor.exclude` Default: `""`

This is a list of point of presence to exclude as checkpoints.

## Examples

[/examples](/examples/) contains the example of an `Ingress` and `Uptrends` based monitor.
Expand Down
14 changes: 13 additions & 1 deletion api/v1alpha1/uptrends.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ type UptrendsSpec struct {
// Url of the Monitor.
Url string `json:"url"`
// MonitorGroup associates a monitor group.
Group MonitorGroup `json:"group"`
Group MonitorGroup `json:"group,omitempty"`
// Checkpoints are the checkpoints to use for monitoring.
Checkpoints MonitorCheckpoints `json:"checkpoints,omitempty"`
}

// MonitorCheckpoints defines the set of point of presence to check from.
type MonitorCheckpoints struct {
// Regions is the set of entire regions to use.
Regions []int32 `json:"regions,omitempty"`
// Checkpoints are single point of presence to use.
Checkpoints []int32 `json:"checkpoints,omitempty"`
// ExcludeCheckpoints is a list of point of presence to execlude to use.
ExcludeCheckpoints []int32 `json:"exclude,omitempty"`
}

// MonitorGroup defines a monitor group.
Expand Down
33 changes: 32 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion charts/uptrends/templates/crds/crd-uptrends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ spec:
spec:
description: UptrendsSpec defines the desired state of Uptrends
properties:
checkpoints:
description: Checkpoints are the checkpoints to use for monitoring.
properties:
checkpoints:
description: Checkpoints are single point of presence to use.
items:
format: int32
type: integer
type: array
exclude:
description: ExcludeCheckpoints is a list of point of presence
to execlude to use.
items:
format: int32
type: integer
type: array
regions:
description: Regions is the set of entire regions to use.
items:
format: int32
type: integer
type: array
type: object
description:
description: Description of the Monitor.
type: string
Expand All @@ -62,7 +85,6 @@ spec:
type: string
required:
- description
- group
- interval
- name
- type
Expand Down
5 changes: 4 additions & 1 deletion examples/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ metadata:
uptrends.ionos-cloud.github.io/monitor.type: HTTPS
uptrends.ionos-cloud.github.io/monitor.interval: "1"
uptrends.ionos-cloud.github.io/monitor.guid: ""
uptrends.ionos-cloud.github.io/monitor.regions: "54,1007"
uptrends.ionos-cloud.github.io/monitor.checkpoints: ""
uptrends.ionos-cloud.github.io/monitor.exclude: ""
spec:
rules:
- host: ionos.com
Expand All @@ -18,4 +21,4 @@ spec:
name: service1
port:
number: 80


Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ spec:
spec:
description: UptrendsSpec defines the desired state of Uptrends
properties:
checkpoints:
description: Checkpoints are the checkpoints to use for monitoring.
properties:
checkpoints:
description: Checkpoints are single point of presence to use.
items:
format: int32
type: integer
type: array
exclude:
description: ExcludeCheckpoints is a list of point of presence
to execlude to use.
items:
format: int32
type: integer
type: array
regions:
description: Regions is the set of entire regions to use.
items:
format: int32
type: integer
type: array
type: object
description:
description: Description of the Monitor.
type: string
Expand All @@ -62,7 +85,6 @@ spec:
type: string
required:
- description
- group
- interval
- name
- type
Expand Down
24 changes: 23 additions & 1 deletion manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ spec:
spec:
description: UptrendsSpec defines the desired state of Uptrends
properties:
checkpoints:
description: Checkpoints are the checkpoints to use for monitoring.
properties:
checkpoints:
description: Checkpoints are single point of presence to use.
items:
format: int32
type: integer
type: array
exclude:
description: ExcludeCheckpoints is a list of point of presence
to execlude to use.
items:
format: int32
type: integer
type: array
regions:
description: Regions is the set of entire regions to use.
items:
format: int32
type: integer
type: array
type: object
description:
description: Description of the Monitor.
type: string
Expand All @@ -63,7 +86,6 @@ spec:
type: string
required:
- description
- group
- interval
- name
- type
Expand Down
37 changes: 33 additions & 4 deletions pkg/controller/ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ func (c *ingressReconciler) reconcileResources(ctx context.Context, in *networki
Name: name,
},
Spec: v1alpha1.UptrendsSpec{
Name: fmt.Sprintf("%s - Uptime", r.Host),
Interval: 5,
Type: "HTTPS",
Group: v1alpha1.MonitorGroup{},
Name: fmt.Sprintf("%s - Uptime", r.Host),
Interval: 5,
Type: "HTTPS",
Group: v1alpha1.MonitorGroup{},
Checkpoints: v1alpha1.MonitorCheckpoints{},
},
}

Expand All @@ -132,6 +133,34 @@ func (c *ingressReconciler) reconcileResources(ctx context.Context, in *networki
}
}

if v, ok := annotations["regions"]; ok {
regions := strings.Split(v, ",")

for _, r := range regions {
if i, err := strconv.Atoi(strings.TrimSpace(r)); err == nil {
monitor.Spec.Checkpoints.Regions = append(monitor.Spec.Checkpoints.Regions, int32(i))
}
}
}

if v, ok := annotations["checkpoints"]; ok {
checkpoints := strings.Split(v, ",")
for _, r := range checkpoints {
if i, err := strconv.Atoi(strings.TrimSpace(r)); err == nil {
monitor.Spec.Checkpoints.Checkpoints = append(monitor.Spec.Checkpoints.Checkpoints, int32(i))
}
}
}

if v, ok := annotations["exclude"]; ok {
excludes := strings.Split(v, ",")
for _, r := range excludes {
if i, err := strconv.Atoi(strings.TrimSpace(r)); err == nil {
monitor.Spec.Checkpoints.ExcludeCheckpoints = append(monitor.Spec.Checkpoints.ExcludeCheckpoints, int32(i))
}
}
}

if v, ok := annotations["guid"]; ok {
monitor.Spec.Group.GUID = v
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/monitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (m *monitorReconcile) reconcileUpdate(ctx context.Context, mon *v1alpha1.Up
MonitorType: utils.PtrMonitor(sw.MonitorType(mon.Spec.Type)),
Notes: mon.Spec.Description,
CheckInterval: int32(mon.Spec.Interval),
SelectedCheckpoints: &sw.SelectedCheckpoints{
Regions: mon.Spec.Checkpoints.Regions,
Checkpoints: mon.Spec.Checkpoints.Checkpoints,
ExcludeLocations: mon.Spec.Checkpoints.ExcludeCheckpoints,
},
}

_, err := client.MonitorApi.MonitorPatchMonitor(
Expand Down

0 comments on commit f5e9921

Please sign in to comment.