Skip to content

Commit

Permalink
fix(check): Failing checks and default location (#18)
Browse files Browse the repository at this point in the history
* fix(check): Set MaxResponseTime correctly

Previously we've been setting MaxResponseTime as the Frequency,
MaxResponseTime is supposed to be in miliseconds, thus setting Frequency
to 5, would make MaxResponseTime 5 miliseconds, the checklyhq backend
didn't know what to do with this number so it was empty, created checks
failed immediately.

This fixes #17.

* fix(check): Do not set location for checks

Checks are tied to group, each group has location settings, we shouldn't
set the default location to eu-west-1 anymore

* test(debug): Add debug script for checkly checks
  • Loading branch information
akosveres authored Jul 7, 2022
1 parent b234e8a commit 4607842
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 25 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Ignore build and test binaries.
bin/
testbin/
hack/

# direnv
.envrc
3 changes: 0 additions & 3 deletions apis/checkly/v1alpha1/apicheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ type ApiCheckSpec struct {
// Muted determines if the created alert is muted or not, default false
Muted bool `json:"muted,omitempty"`

// 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"`

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

Expand Down
7 changes: 1 addition & 6 deletions apis/checkly/v1alpha1/zz_generated.deepcopy.go

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

7 changes: 0 additions & 7 deletions config/crd/bases/k8s.checklyhq.com_apichecks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ spec:
description: Group determines in which group does the check belong
to
type: string
locations:
description: 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
items:
type: string
type: array
maxresponsetime:
description: MaxResponseTime determines what the maximum number of
miliseconds can pass before the check fails, default 15000
Expand Down
3 changes: 0 additions & 3 deletions config/samples/checkly_v1alpha1_apicheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ spec:
frequency: 10 # Default 5
muted: true # Default "false"
group: "group-sample"
# locations: # Default eu-west-1
# - eu-west-1
# - ap-northeast-2
3 changes: 1 addition & 2 deletions controllers/checkly/apicheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func (r *ApiCheckReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
Name: apiCheck.Name,
Namespace: apiCheck.Namespace,
Frequency: apiCheck.Spec.Frequency,
MaxResponseTime: apiCheck.Spec.Frequency,
Locations: apiCheck.Spec.Locations,
MaxResponseTime: apiCheck.Spec.MaxResponseTime,
Endpoint: apiCheck.Spec.Endpoint,
SuccessCode: apiCheck.Spec.Success,
ID: apiCheck.Status.ID,
Expand Down
3 changes: 1 addition & 2 deletions external/checkly/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Check struct {
Namespace string
Frequency int
MaxResponseTime int
Locations []string
Endpoint string
SuccessCode string
GroupID int64
Expand Down Expand Up @@ -70,7 +69,7 @@ func checklyCheck(apiCheck Check) (check checkly.Check) {
SSLCheck: false,
LocalSetupScript: "",
LocalTearDownScript: "",
Locations: checkValueArray(apiCheck.Locations, []string{"eu-west-1"}),
Locations: []string{},
Tags: []string{
apiCheck.Namespace,
"checkly-operator",
Expand Down
2 changes: 0 additions & 2 deletions external/checkly/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestChecklyCheck(t *testing.T) {
Namespace: "bar",
Frequency: 15,
MaxResponseTime: 2000,
Locations: []string{"basement"},
Endpoint: "https://foo.bar/baz",
SuccessCode: "200",
Muted: true,
Expand Down Expand Up @@ -84,7 +83,6 @@ func TestChecklyCheckActions(t *testing.T) {
Namespace: "bar",
Frequency: 15,
MaxResponseTime: 2000,
Locations: []string{"basement"},
Endpoint: "https://foo.bar/baz",
SuccessCode: "200",
ID: "",
Expand Down
64 changes: 64 additions & 0 deletions hack/debug-checks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"context"
"errors"
"flag"
"fmt"
"os"
"time"

"github.com/checkly/checkly-go-sdk"
ctrl "sigs.k8s.io/controller-runtime"
)

// The script returns the data for a specific checkly check from the checklyhq API,
// it's meant to be used as a debug tool for issues with checks created.

func main() {

setupLog := ctrl.Log.WithName("setup")

var checklyID string

flag.StringVar(&checklyID, "c", "", "Specify the checkly check ID")
flag.Parse()

if checklyID == "" {
setupLog.Error(errors.New("ChecklyID is empty"), "exiting due to missing information")
os.Exit(1)
}

baseUrl := "https://api.checklyhq.com"
apiKey := os.Getenv("CHECKLY_API_KEY")
if apiKey == "" {
setupLog.Error(errors.New("checklyhq.com API key environment variable is undefined"), "checklyhq.com credentials missing")
os.Exit(1)
}

accountId := os.Getenv("CHECKLY_ACCOUNT_ID")
if accountId == "" {
setupLog.Error(errors.New("checklyhq.com Account ID environment variable is undefined"), "checklyhq.com credentials missing")
os.Exit(1)
}

client := checkly.NewClient(
baseUrl,
apiKey,
nil, //custom http client, defaults to http.DefaultClient
nil, //io.Writer to output debug messages
)

client.SetAccountId(accountId)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

returnedCheck, err := client.Get(ctx, checklyID)
if err != nil {
setupLog.Error(err, "failed to get check")
os.Exit(1)
}

fmt.Printf("%+v", returnedCheck)

}

0 comments on commit 4607842

Please sign in to comment.