Skip to content

Commit

Permalink
Merge pull request #11 from IMGARENA/BAU_apiCheck_cleanup
Browse files Browse the repository at this point in the history
Add muted feature
  • Loading branch information
akosveres authored Jun 28, 2022
2 parents e711bde + b8a8267 commit a5f23da
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 31 deletions.
3 changes: 0 additions & 3 deletions apis/checkly/v1alpha1/apicheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ type ApiCheckSpec struct {
// Locations determines the locations where the checks are run from, see https://www.checklyhq.com/docs/monitoring/global-locations/ for a list, use AWS Region codes, ex. eu-west-1 for Ireland
Locations []string `json:"locations,omitempty"`

// Team determines who owns this API Check
Team string `json:"team"`

// Endpoint determines which URL to monitor, ex. https://foo.bar/baz
Endpoint string `json:"endpoint"`

Expand Down
12 changes: 1 addition & 11 deletions config/crd/bases/checkly.imgarena.com_apichecks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: apichecks.checkly.imgarena.com
spec:
Expand Down Expand Up @@ -82,14 +82,10 @@ spec:
success:
description: Success determines the returned success code, ex. 200
type: string
team:
description: Team determines who owns this API Check
type: string
required:
- endpoint
- group
- success
- team
type: object
status:
description: ApiCheckStatus defines the observed state of ApiCheck
Expand All @@ -111,9 +107,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
8 changes: 1 addition & 7 deletions config/crd/bases/checkly.imgarena.com_groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: groups.checkly.imgarena.com
spec:
Expand Down Expand Up @@ -67,9 +67,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 1 addition & 0 deletions config/samples/network_v1_ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ metadata:
# checkly.imgarena.com/endpoint: "foo.baaz" - Default read from spec.rules[0].host
# checkly.imgarena.com/success: "200" - Default "200"
checkly.imgarena.com/group: "group-sample"
# checkly.imgarena.com/muted: "false" # If not set, default "true"
spec:
rules:
- host: "foo.bar"
Expand Down
1 change: 1 addition & 0 deletions controllers/checkly/apicheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (r *ApiCheckReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
SuccessCode: apiCheck.Spec.Success,
ID: apiCheck.Status.ID,
GroupID: group.Status.ID,
Muted: apiCheck.Spec.Muted,
}

// /////////////////////////////
Expand Down
12 changes: 8 additions & 4 deletions controllers/checkly/apicheck_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ var _ = Describe("ApiCheck Controller", func() {
Namespace: key.Namespace,
},
Spec: checklyv1alpha1.ApiCheckSpec{
Team: "does-not-exist",
Endpoint: "http://bar.baz/quoz",
Success: "200",
Group: groupKey.Name,
Muted: true,
},
}

Expand All @@ -103,11 +103,15 @@ var _ = Describe("ApiCheck Controller", func() {
Eventually(func() bool {
f := &checklyv1alpha1.ApiCheck{}
err := k8sClient.Get(context.Background(), key, f)
if f.Status.ID == "2" && err == nil {
return true
} else {
if f.Status.ID != "2" && err != nil {
return false
}

if f.Spec.Muted != true {
return false
}

return true
}, timeout, interval).Should(BeTrue())

// Finalizer should be present
Expand Down
11 changes: 10 additions & 1 deletion controllers/networking/ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (r *IngressReconciler) gatherApiCheckData(ingress *networkingv1.Ingress) (a
annotationEndpoint := fmt.Sprintf("%s/endpoint", annotationHost)
annotationSuccess := fmt.Sprintf("%s/success", annotationHost)
annotationGroup := fmt.Sprintf("%s/group", annotationHost)
annotationMuted := fmt.Sprintf("%s/muted", annotationHost)

// Construct the endpoint
path := ""
Expand Down Expand Up @@ -175,11 +176,19 @@ func (r *IngressReconciler) gatherApiCheckData(ingress *networkingv1.Ingress) (a
err = fmt.Errorf("could not find a value for the group annotation, can't continue without one")
}

// Muted
var muted bool
if ingress.Annotations[annotationMuted] == "false" {
muted = false
} else {
muted = true
}

apiCheckSpec = checklyv1alpha1.ApiCheckSpec{
Endpoint: endpoint,
Group: group,
Team: "group-test",
Success: success,
Muted: muted,
}

// Last return
Expand Down
16 changes: 13 additions & 3 deletions controllers/networking/ingress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var _ = Describe("Ingress Controller", func() {
Expect(f.Spec.Endpoint == fmt.Sprintf("https://%s%s", testHost, testPath)).To(BeTrue())
Expect(f.Spec.Group).To(Equal(testGroup))
Expect(f.Spec.Success).To(Equal(testSuccessCode))
Expect(f.Spec.Muted).To(Equal(true))

for _, o := range f.OwnerReferences {
if o.Name != key.Name {
Expand All @@ -118,6 +119,7 @@ var _ = Describe("Ingress Controller", func() {
annotation["checkly.imgarena.com/path"] = updatePath
annotation["checkly.imgarena.com/endpoint"] = updateHost
annotation["checkly.imgarena.com/success"] = ""
annotation["checkly.imgarena.com/muted"] = "false"
ingress = &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Expand Down Expand Up @@ -154,6 +156,10 @@ var _ = Describe("Ingress Controller", func() {
return false
}

if f.Spec.Muted {
return false
}

return true
}, timeout, interval).Should(BeTrue())

Expand Down Expand Up @@ -218,6 +224,7 @@ var _ = Describe("Ingress Controller", func() {
annotation["checkly.imgarena.com/enabled"] = "false"
annotation["checkly.imgarena.com/path"] = testPath
annotation["checkly.imgarena.com/success"] = testSuccessCode
annotation["checkly.imgarena.com/muted"] = "false"

rules := make([]networkingv1.IngressRule, 0)
rules = append(rules, networkingv1.IngressRule{
Expand All @@ -244,10 +251,13 @@ var _ = Describe("Ingress Controller", func() {
}
Expect(k8sClient.Create(context.Background(), ingress)).Should(Succeed())

// Test group annotation missing
time.Sleep(time.Second * 5)

updated := &networkingv1.Ingress{}
Expect(k8sClient.Get(context.Background(), key, updated)).Should(Succeed())
annotation["checkly.imgarena.com/enabled"] = "true"
ingress.Annotations = annotation
Expect(k8sClient.Update(context.Background(), ingress)).Should(Succeed())
updated.Annotations = annotation
Expect(k8sClient.Update(context.Background(), updated)).Should(Succeed())

// Delete
By("Expecting to delete successfully")
Expand Down
3 changes: 2 additions & 1 deletion external/checkly/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Check struct {
SuccessCode string
GroupID int64
ID string
Muted bool
}

func checklyCheck(apiCheck Check) (check checkly.Check) {
Expand Down Expand Up @@ -63,7 +64,7 @@ func checklyCheck(apiCheck Check) (check checkly.Check) {
DegradedResponseTime: 5000,
MaxResponseTime: checkValueInt(apiCheck.MaxResponseTime, 15000),
Activated: true,
Muted: true, // muted for development
Muted: apiCheck.Muted, // muted for development
ShouldFail: false,
DoubleCheck: false,
SSLCheck: false,
Expand Down
5 changes: 5 additions & 0 deletions external/checkly/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestChecklyCheck(t *testing.T) {
Locations: []string{"basement"},
Endpoint: "https://foo.bar/baz",
SuccessCode: "200",
Muted: true,
}

testData := checklyCheck(data)
Expand All @@ -50,6 +51,10 @@ func TestChecklyCheck(t *testing.T) {
t.Errorf("Expected %d, got %d", data.Frequency, testData.Frequency)
}

if testData.Muted != data.Muted {
t.Errorf("Expected %t, got %t", data.Muted, testData.Muted)
}

data = Check{
Name: "foo",
Namespace: "bar",
Expand Down
2 changes: 1 addition & 1 deletion external/checkly/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func checklyGroup(group Group) (check checkly.Group) {
check = checkly.Group{
Name: group.Name,
Activated: true,
Muted: true, // muted for development
Muted: false, // muted for development
DoubleCheck: false,
LocalSetupScript: "",
LocalTearDownScript: "",
Expand Down

0 comments on commit a5f23da

Please sign in to comment.