Skip to content

Commit 4607842

Browse files
authored
fix(check): Failing checks and default location (#18)
* 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
1 parent b234e8a commit 4607842

File tree

9 files changed

+68
-25
lines changed

9 files changed

+68
-25
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Ignore build and test binaries.
33
bin/
44
testbin/
5+
hack/
56

67
# direnv
78
.envrc

apis/checkly/v1alpha1/apicheck_types.go

-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ type ApiCheckSpec struct {
3434
// Muted determines if the created alert is muted or not, default false
3535
Muted bool `json:"muted,omitempty"`
3636

37-
// 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
38-
Locations []string `json:"locations,omitempty"`
39-
4037
// Endpoint determines which URL to monitor, ex. https://foo.bar/baz
4138
Endpoint string `json:"endpoint"`
4239

apis/checkly/v1alpha1/zz_generated.deepcopy.go

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/k8s.checklyhq.com_apichecks.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ spec:
6464
description: Group determines in which group does the check belong
6565
to
6666
type: string
67-
locations:
68-
description: Locations determines the locations where the checks are
69-
run from, see https://www.checklyhq.com/docs/monitoring/global-locations/
70-
for a list, use AWS Region codes, ex. eu-west-1 for Ireland
71-
items:
72-
type: string
73-
type: array
7467
maxresponsetime:
7568
description: MaxResponseTime determines what the maximum number of
7669
miliseconds can pass before the check fails, default 15000

config/samples/checkly_v1alpha1_apicheck.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@ spec:
99
frequency: 10 # Default 5
1010
muted: true # Default "false"
1111
group: "group-sample"
12-
# locations: # Default eu-west-1
13-
# - eu-west-1
14-
# - ap-northeast-2

controllers/checkly/apicheck_controller.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ func (r *ApiCheckReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
139139
Name: apiCheck.Name,
140140
Namespace: apiCheck.Namespace,
141141
Frequency: apiCheck.Spec.Frequency,
142-
MaxResponseTime: apiCheck.Spec.Frequency,
143-
Locations: apiCheck.Spec.Locations,
142+
MaxResponseTime: apiCheck.Spec.MaxResponseTime,
144143
Endpoint: apiCheck.Spec.Endpoint,
145144
SuccessCode: apiCheck.Spec.Success,
146145
ID: apiCheck.Status.ID,

external/checkly/check.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type Check struct {
3030
Namespace string
3131
Frequency int
3232
MaxResponseTime int
33-
Locations []string
3433
Endpoint string
3534
SuccessCode string
3635
GroupID int64
@@ -70,7 +69,7 @@ func checklyCheck(apiCheck Check) (check checkly.Check) {
7069
SSLCheck: false,
7170
LocalSetupScript: "",
7271
LocalTearDownScript: "",
73-
Locations: checkValueArray(apiCheck.Locations, []string{"eu-west-1"}),
72+
Locations: []string{},
7473
Tags: []string{
7574
apiCheck.Namespace,
7675
"checkly-operator",

external/checkly/check_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func TestChecklyCheck(t *testing.T) {
3131
Namespace: "bar",
3232
Frequency: 15,
3333
MaxResponseTime: 2000,
34-
Locations: []string{"basement"},
3534
Endpoint: "https://foo.bar/baz",
3635
SuccessCode: "200",
3736
Muted: true,
@@ -84,7 +83,6 @@ func TestChecklyCheckActions(t *testing.T) {
8483
Namespace: "bar",
8584
Frequency: 15,
8685
MaxResponseTime: 2000,
87-
Locations: []string{"basement"},
8886
Endpoint: "https://foo.bar/baz",
8987
SuccessCode: "200",
9088
ID: "",

hack/debug-checks.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"errors"
6+
"flag"
7+
"fmt"
8+
"os"
9+
"time"
10+
11+
"github.com/checkly/checkly-go-sdk"
12+
ctrl "sigs.k8s.io/controller-runtime"
13+
)
14+
15+
// The script returns the data for a specific checkly check from the checklyhq API,
16+
// it's meant to be used as a debug tool for issues with checks created.
17+
18+
func main() {
19+
20+
setupLog := ctrl.Log.WithName("setup")
21+
22+
var checklyID string
23+
24+
flag.StringVar(&checklyID, "c", "", "Specify the checkly check ID")
25+
flag.Parse()
26+
27+
if checklyID == "" {
28+
setupLog.Error(errors.New("ChecklyID is empty"), "exiting due to missing information")
29+
os.Exit(1)
30+
}
31+
32+
baseUrl := "https://api.checklyhq.com"
33+
apiKey := os.Getenv("CHECKLY_API_KEY")
34+
if apiKey == "" {
35+
setupLog.Error(errors.New("checklyhq.com API key environment variable is undefined"), "checklyhq.com credentials missing")
36+
os.Exit(1)
37+
}
38+
39+
accountId := os.Getenv("CHECKLY_ACCOUNT_ID")
40+
if accountId == "" {
41+
setupLog.Error(errors.New("checklyhq.com Account ID environment variable is undefined"), "checklyhq.com credentials missing")
42+
os.Exit(1)
43+
}
44+
45+
client := checkly.NewClient(
46+
baseUrl,
47+
apiKey,
48+
nil, //custom http client, defaults to http.DefaultClient
49+
nil, //io.Writer to output debug messages
50+
)
51+
52+
client.SetAccountId(accountId)
53+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
54+
defer cancel()
55+
56+
returnedCheck, err := client.Get(ctx, checklyID)
57+
if err != nil {
58+
setupLog.Error(err, "failed to get check")
59+
os.Exit(1)
60+
}
61+
62+
fmt.Printf("%+v", returnedCheck)
63+
64+
}

0 commit comments

Comments
 (0)