Skip to content

Commit

Permalink
refactor: check reconcilation (#102)
Browse files Browse the repository at this point in the history
* refactor: squash merge refactor/check-reconcilation into refactor/check-reconcile for clean git tree

commit 911c29f
Author: lvlcn-t <[email protected]>
Date:   Wed Feb 7 23:03:32 2024 +0100

    chore: add license headers

commit 3bc0ee1
Author: lvlcn-t <[email protected]>
Date:   Wed Feb 7 23:00:06 2024 +0100

    test: add error listener tests & fix: error assertion

commit 90d6f24
Author: lvlcn-t <[email protected]>
Date:   Wed Feb 7 21:31:00 2024 +0100

    chore: rm unused Done() method from Check interface

commit b17973b
Author: lvlcn-t <[email protected]>
Date:   Wed Feb 7 20:35:52 2024 +0100

    chore: remove unused methods from Checks struct

commit 9d20b8c
Author: lvlcn-t <[email protected]>
Date:   Wed Feb 7 20:34:50 2024 +0100

    refactor: simplify reconcile logic

commit 29750bc
Author: lvlcn-t <[email protected]>
Date:   Wed Feb 7 18:12:00 2024 +0100

    refactor: finish check controller implementation

    * test: adjust sparrow tests to check controller
    * refactor: move oapi spec generation to check controller
    * refactor: rm reconciler abstraction layer
    * test: adjust check tests to new interface

commit 793d9e3
Author: lvlcn-t <[email protected]>
Date:   Tue Feb 6 23:38:09 2024 +0100

    refactor: implement new interface methods to checks

commit 7c82283
Author: lvlcn-t <[email protected]>
Date:   Tue Feb 6 23:37:35 2024 +0100

    refactor: extract check reconcilation to reconciler component and check controller

commit 2c1b1ae
Author: lvlcn-t <[email protected]>
Date:   Tue Feb 6 15:41:44 2024 +0100

    refactor: simplify route registering

commit 76aa330
Author: lvlcn-t <[email protected]>
Date:   Fri Feb 2 21:16:34 2024 +0100

    chore: mv api config struct

commit cd57f16
Author: lvlcn-t <[email protected]>
Date:   Fri Feb 2 20:49:40 2024 +0100

    refactor: custom error type

commit 42722b9
Author: lvlcn-t <[email protected]>
Date:   Fri Feb 2 20:23:18 2024 +0100

    chore: extract api startup to dedicated method

commit b9a8b6a
Author: lvlcn-t <[email protected]>
Date:   Thu Feb 1 16:06:19 2024 +0100

    chore: licensing

commit b364676
Author: lvlcn-t <[email protected]>
Date:   Thu Feb 1 15:58:05 2024 +0100

    chore: revert viper bump

commit 526eabd
Merge: 2ff55bc ed1adca
Author: lvlcn-t <[email protected]>
Date:   Thu Feb 1 15:41:10 2024 +0100

    Merge branch 'main' into refactor/api

commit 2ff55bc
Author: lvlcn-t <[email protected]>
Date:   Tue Jan 30 16:06:21 2024 +0100

    chore: correct metric name

commit 7131a3e
Author: lvlcn-t <[email protected]>
Date:   Tue Jan 30 15:42:09 2024 +0100

    test: add run api and gen check specs unittests

commit bed6004
Author: lvlcn-t <[email protected]>
Date:   Tue Jan 30 13:46:39 2024 +0100

    fix: return error if no routes are registered

commit b6ffe0a
Author: lvlcn-t <[email protected]>
Date:   Tue Jan 30 13:22:26 2024 +0100

    chore: mv metrics back to sparrow

commit 97a376b
Merge: 743d79b d91def5
Author: lvlcn-t <[email protected]>
Date:   Tue Jan 30 10:46:42 2024 +0100

    Merge branch 'refactor/typed-runtime-cfg' into refactor/api

commit d91def5
Author: Bruno Bressi <[email protected]>
Date:   Tue Jan 30 00:25:26 2024 +0100

    feat: gitlab tm handles dns targets

    Signed-off-by: Bruno Bressi <[email protected]>

commit 743d79b
Merge: d1d1bdc 3f5416b
Author: lvlcn-t <[email protected]>
Date:   Mon Jan 29 12:41:28 2024 +0100

    Merge branch 'main' into refactor/api

commit 2251399
Merge: c551e23 585c9c1
Author: Bruno Bressi <[email protected]>
Date:   Mon Jan 29 12:09:57 2024 +0100

    chore: merged from main

    Signed-off-by: Bruno Bressi <[email protected]>

commit d1d1bdc
Author: lvlcn-t <[email protected]>
Date:   Sun Jan 28 15:14:06 2024 +0100

    chore: embedded struct naming

commit 2dc94fd
Author: lvlcn-t <[email protected]>
Date:   Sun Jan 28 15:07:25 2024 +0100

    chore: add godocs and improve naming

commit 4670b16
Author: lvlcn-t <[email protected]>
Date:   Sun Jan 28 14:57:14 2024 +0100

    test: add route registering tests

commit 9bf603c
Author: lvlcn-t <[email protected]>
Date:   Sun Jan 28 14:09:00 2024 +0100

    chore: licensing

commit fbdfc6d
Author: lvlcn-t <[email protected]>
Date:   Sun Jan 28 14:06:45 2024 +0100

    fix: metrics route

commit c551e23
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 22:02:49 2024 +0100

    chore: godocs of tests corrected

    Signed-off-by: Bruno Bressi <[email protected]>

commit 8bda6ac
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 21:57:41 2024 +0100

    chore: fixed variable shadowing

    Signed-off-by: Bruno Bressi <[email protected]>

commit 4f3a355
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 21:50:15 2024 +0100

    chore: renamed runtime cfg channel

    Signed-off-by: Bruno Bressi <[email protected]>

commit b24fe36
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 21:45:41 2024 +0100

    fix: latency tests correct comparison, removed error string comparison

    Signed-off-by: Bruno Bressi <[email protected]>

commit 5a7dacc
Merge: 69e0105 0b84250
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 21:38:19 2024 +0100

    chore: merged from feat/dns-checks

commit e9b711f
Merge: 9717641 55616be
Author: lvlcn-t <[email protected]>
Date:   Sat Jan 27 18:21:33 2024 +0100

    Merge branch 'refactor/sparrow-api' into refactor/api

commit 9717641
Author: lvlcn-t <[email protected]>
Date:   Sat Jan 27 16:56:17 2024 +0100

    chore: rm dynamic routing tree

commit 99e1cb6
Author: lvlcn-t <[email protected]>
Date:   Sat Jan 27 16:53:57 2024 +0100

    refactor: rm unused dynamic check handlers

commit 69e0105
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 16:48:58 2024 +0100

    General cleanup:
    - chore: removed non-used validate methods
    - tests: unexposed size method -> change tests that used it
    - chore: better variable naming in reconcilechecks

commit 0b84250
Author: lvlcn-t <[email protected]>
Date:   Sat Jan 27 16:26:04 2024 +0100

    docs: add dns check

commit 0c8c779
Author: lvlcn-t <[email protected]>
Date:   Sat Jan 27 16:17:21 2024 +0100

    docs: adjust metrics godocs

commit 9732fc3
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 15:12:54 2024 +0100

    chore: adapted helm chart to new checksconfig

    Signed-off-by: Bruno Bressi <[email protected]>

commit b9f14c6
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 14:53:14 2024 +0100

    refactor: removed uneeded Checks field from check's configuration

    Signed-off-by: Bruno Bressi <[email protected]>

commit f83241d
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 14:36:14 2024 +0100

    refactor: factory moved outside checks

    Signed-off-by: Bruno Bressi <[email protected]>

commit 53ce54f
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 14:20:27 2024 +0100

    [no ci] chore: remove binary from repo

    Signed-off-by: Bruno Bressi <[email protected]>

commit adf8bfa
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 09:27:25 2024 +0100

    chore: added black magic back

    Signed-off-by: Bruno Bressi <[email protected]>

commit 31a26d7
Merge: a0a5a84 ecd5c24
Author: Bruno Bressi <[email protected]>
Date:   Sat Jan 27 08:49:01 2024 +0100

    chore: merged from feat/dns-checks

    Signed-off-by: Bruno Bressi <[email protected]>

commit ecd5c24
Author: lvlcn-t <[email protected]>
Date:   Fri Jan 26 22:15:00 2024 +0100

    test: add more set config test cases

commit 2777514
Merge: d3928f0 9f1d0d3
Author: lvlcn-t <[email protected]>
Date:   Fri Jan 26 20:13:47 2024 +0100

    Merge branch 'main' into feat/dns-check

commit d3928f0
Author: lvlcn-t <[email protected]>
Date:   Fri Jan 26 19:23:55 2024 +0100

    chore: PR review

    * chore: adjust metric names
    * test: add metric collector tests
    * chore: rephrase logging message

commit 1d3f671
Author: lvlcn-t <[email protected]>
Date:   Fri Jan 26 18:10:00 2024 +0100

    fix: handle injected global targets

commit 3367913
Author: lvlcn-t <[email protected]>
Date:   Fri Jan 26 18:01:17 2024 +0100

    test: create ctx for each test

commit 89dc498
Author: lvlcn-t <[email protected]>
Date:   Fri Jan 26 17:56:12 2024 +0100

    chore: rm unused check handlers

commit 90b36ef
Author: lvlcn-t <[email protected]>
Date:   Fri Jan 26 12:40:17 2024 +0100

    chore: rename test functions

commit e873397
Author: lvlcn-t <[email protected]>
Date:   Thu Jan 25 19:53:11 2024 +0100

    test: add context cancelation test

commit 89aa3a1
Author: lvlcn-t <[email protected]>
Date:   Thu Jan 25 16:04:08 2024 +0100

    chore: adjust log messages

commit dc0c6cd
Author: lvlcn-t <[email protected]>
Date:   Thu Jan 25 15:45:51 2024 +0100

    feat: mv metrics to dedicated file

commit 5434508
Author: lvlcn-t <[email protected]>
Date:   Thu Jan 25 15:37:41 2024 +0100

    fix: retry on lookup failures

commit aa628e6
Author: lvlcn-t <[email protected]>
Date:   Thu Jan 25 14:34:50 2024 +0100

    chore: mv route name to constant

commit 0441d58
Author: lvlcn-t <[email protected]>
Date:   Wed Jan 24 23:31:22 2024 +0100

    chore: licensing headers

commit 3f7ce94
Author: lvlcn-t <[email protected]>
Date:   Wed Jan 24 23:30:28 2024 +0100

    feat: add dns check to check register

commit bae1f8e
Author: lvlcn-t <[email protected]>
Date:   Wed Jan 24 23:04:14 2024 +0100

    feat: implement the rest of the dns check

    * feat: add dns metrics
    * test: add unit tests for dns check methods

commit a0a5a84
Author: Bruno Bressi <[email protected]>
Date:   Wed Jan 24 19:12:14 2024 +0100

    chore: updated docs of structs for more clarity

    Signed-off-by: Bruno Bressi <[email protected]>

commit cc5e74c
Merge: 2742590 6b006c3
Author: Bruno Bressi <[email protected]>
Date:   Wed Jan 24 19:08:49 2024 +0100

    chore: merged from main

    Signed-off-by: Bruno Bressi <[email protected]>

commit 5cc774f
Author: lvlcn-t <[email protected]>
Date:   Wed Jan 24 18:52:03 2024 +0100

    feat: add dns check

commit 2742590
Merge: eb5fc0a 823a439
Author: Bruno Bressi <[email protected]>
Date:   Tue Jan 23 15:53:45 2024 +0100

    Merge remote-tracking branch 'origin/main' into refactor/typed-runtime-cfg

commit eb5fc0a
Merge: 2f6333b c4a6b54
Author: Bruno Bressi <[email protected]>
Date:   Fri Jan 19 17:40:31 2024 +0100

    chore: merge from main

    Signed-off-by: Bruno Bressi <[email protected]>

commit 2f6333b
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 19:18:39 2024 +0100

    fix: target manager nil check when enriching

    Signed-off-by: Bruno Bressi <[email protected]>

commit 3d0971f
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 18:50:25 2024 +0100

    fix: checks are properly configured on start

    Signed-off-by: Bruno Bressi <[email protected]>

commit 90988e7
Merge: 7fa28db 9339cdd
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 17:57:16 2024 +0100

    Merge branch 'feat/simplify-helm-chart-config' into refactor/typed-runtime-cfg

commit 9339cdd
Merge: c6f0ca7 0c4042f
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 17:55:43 2024 +0100

    chore: merge from main

    Signed-off-by: Bruno Bressi <[email protected]>

commit 0c4042f
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 17:52:41 2024 +0100

    docs: envfromSecrets

commit c6f0ca7
Merge: 0bd9674 2a1cb4c
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 17:48:37 2024 +0100

    Merge branch 'feat/simplify-helm-chart-config' of github.com:caas-team/sparrow into feat/simplify-helm-chart-config

commit 0bd9674
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 17:47:05 2024 +0100

    chore: added helm docs

    Signed-off-by: Bruno Bressi <[email protected]>

commit 2a1cb4c
Merge: d81ad4a fc72395
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 17:44:55 2024 +0100

    Merge branch 'chore/bump-chart-version' into feat/simplify-helm-chart-config

commit fc72395
Merge: 761d7c4 9dc3eed
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 17:44:03 2024 +0100

    Merge branch 'main' into chore/bump-chart-version

commit 7fa28db
Merge: 3f40604 9dc3eed
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 17:43:46 2024 +0100

    Merge remote-tracking branch 'origin' into refactor/typed-runtime-cfg

commit 3f40604
Merge: 68d066a d81ad4a
Author: Bruno Bressi <[email protected]>
Date:   Thu Jan 18 17:43:18 2024 +0100

    Merge remote-tracking branch 'origin/feat/simplify-helm-chart-config' into refactor/typed-runtime-cfg

commit d81ad4a
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 17:36:02 2024 +0100

    feat: allow mounting extra secrets as env variables

commit 551f07c
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 17:26:48 2024 +0100

    fix: bug where env variables would not be read correctly

commit 8f0d564
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 15:47:13 2024 +0100

    fix: e2e tests

commit c8c764a
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 15:38:05 2024 +0100

    feat: separate checks and sparrow config

commit 8bb3f07
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 11:56:41 2024 +0100

    fix: register healthcheck for e2e test

commit b9abd15
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 11:41:19 2024 +0100

    fix: remove -n

commit 2fa7fb2
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 11:37:24 2024 +0100

    feat: simplify helm chart

commit 761d7c4
Author: Niklas Treml <[email protected]>
Date:   Thu Jan 18 10:36:12 2024 +0100

    fix: remove default runtime config in helm chart

commit 68d066a
Author: Bruno Bressi <[email protected]>
Date:   Wed Jan 17 23:22:10 2024 +0100

    refactor: restructure checks pkg

    Signed-off-by: Bruno Bressi <[email protected]>

commit 4a2d58f
Merge: 078de7c c4602b2
Author: Bruno Bressi <[email protected]>
Date:   Wed Jan 17 23:14:58 2024 +0100

    chore: merged from main

    Signed-off-by: Bruno Bressi <[email protected]>

commit 975e77f
Author: lvlcn-t <[email protected]>
Date:   Wed Jan 17 22:52:31 2024 +0100

    fix: newline indent

commit 078de7c
Author: Bruno Bressi <[email protected]>
Date:   Wed Jan 17 19:45:31 2024 +0100

    chore: removed decode (RIP)

    Signed-off-by: Bruno Bressi <[email protected]>

commit 02e06b5
Author: Bruno Bressi <[email protected]>
Date:   Wed Jan 17 19:38:17 2024 +0100

    refactor: remove any configurations

    Signed-off-by: Bruno Bressi <[email protected]>

commit da317cc
Author: lvlcn-t <[email protected]>
Date:   Wed Jan 17 18:03:14 2024 +0100

    fix: incorrect formatting on empty labels

commit 820cd55
Author: Niklas Treml <[email protected]>
Date:   Wed Jan 17 10:50:07 2024 +0100

    chore: bump appVersion to v0.3.0

commit 6f759d9
Author: Niklas Treml <[email protected]>
Date:   Tue Jan 16 18:20:08 2024 +0100

    chore: updated helm chart version to 0.0.4

commit 55616be
Author: lvlcn-t <[email protected]>
Date:   Sun Jan 14 20:00:27 2024 +0100

    refactor: mv api and metrics to dedicated packages

* fix: squash merge mistakes

* fix: runtime checks race conditions

* fix: controller error listen test

* test: add unregister assertion

* chore: PR review

* chore: rm struct compositions
* refactor: mv shutdown err HasError method

* chore: add loader moq

* refactor: mv reconcile method to check controller

* chore: mv check removal to controller method

* fix: trigger graceful shutdown if ctx.Done in controller

* chore: invert update checks if block

* refactor: use one result channel for all checks (#106)

* refactor: use one result channel for all checks

* chore: rm unused Result error field

* refactor: simplify check removal
  • Loading branch information
lvlcn-t authored Feb 15, 2024
1 parent eea2e55 commit 66ee8fd
Show file tree
Hide file tree
Showing 25 changed files with 1,167 additions and 712 deletions.
2 changes: 0 additions & 2 deletions chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,3 @@ A Helm chart to install Sparrow
| sparrowConfig | object | `{"loader":{"path":"/config/checks.yaml","type":"file"},"name":"sparrow.com"}` | Sparrow configuration read on startup see: https://github.com/caas-team/sparrow/blob/main/docs/sparrow_run.md |
| tolerations | list | `[]` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0)
18 changes: 18 additions & 0 deletions cmd/flag.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// sparrow
// (C) 2024, Deutsche Telekom IT GmbH
//
// Deutsche Telekom IT GmbH and all other contributors /
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package cmd

import (
Expand Down
56 changes: 0 additions & 56 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"time"

"github.com/caas-team/sparrow/internal/logger"
"github.com/caas-team/sparrow/pkg/checks"
"github.com/getkin/kin-openapi/openapi3"
"github.com/go-chi/chi/v5"
)

Expand Down Expand Up @@ -162,57 +160,3 @@ func okHandler(ctx context.Context) http.Handler {
}
})
}

var oapiBoilerplate = openapi3.T{
// this object should probably be user defined
OpenAPI: "3.0.0",
Info: &openapi3.Info{
Title: "Sparrow Metrics API",
Description: "Serves metrics collected by sparrows checks",
Contact: &openapi3.Contact{
URL: "https://caas.telekom.de",
Email: "[email protected]",
Name: "CaaS Team",
},
},
Paths: make(openapi3.Paths),
Extensions: make(map[string]any),
Components: &openapi3.Components{
Schemas: make(openapi3.Schemas),
},
Servers: openapi3.Servers{},
}

// GenerateCheckSpecs generates the OpenAPI specifications for the given checks
// Returns the complete OpenAPI specification for all checks
func GenerateCheckSpecs(ctx context.Context, cks map[string]checks.Check) (openapi3.T, error) {
log := logger.FromContext(ctx)
doc := oapiBoilerplate
for name, c := range cks {
ref, err := c.Schema()
if err != nil {
log.Error("Failed to get schema for check", "name", name, "error", err)
return openapi3.T{}, &ErrCreateOpenapiSchema{name: name, err: err}
}

routeDesc := fmt.Sprintf("Returns the performance data for check %s", name)
bodyDesc := fmt.Sprintf("Metrics for check %s", name)
doc.Paths["/v1/metrics/"+name] = &openapi3.PathItem{
Description: name,
Get: &openapi3.Operation{
Description: routeDesc,
Tags: []string{"Metrics", name},
Responses: openapi3.Responses{
fmt.Sprint(http.StatusOK): &openapi3.ResponseRef{
Value: &openapi3.Response{
Description: &bodyDesc,
Content: openapi3.NewContentWithSchemaRef(ref, []string{"application/json"}),
},
},
},
},
}
}

return doc, nil
}
80 changes: 0 additions & 80 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ package api
import (
"context"
"errors"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/caas-team/sparrow/pkg/checks"
"github.com/getkin/kin-openapi/openapi3"
"github.com/go-chi/chi/v5"
)

Expand Down Expand Up @@ -239,80 +236,3 @@ func Test_okHandler(t *testing.T) {
rr.Body.String(), expected)
}
}

func TestGenerateCheckSpecs(t *testing.T) {
tests := []struct {
name string
checks map[string]checks.Check
wantErr bool
validate func(t *testing.T, doc openapi3.T)
}{
{
name: "successful generation",
checks: map[string]checks.Check{
"check1": &checks.CheckMock{
SchemaFunc: func() (*openapi3.SchemaRef, error) {
type CheckResultSpec struct {
name string
}
res := CheckResultSpec{name: "check1"}
return checks.OpenapiFromPerfData[CheckResultSpec](res)
},
},
"check2": &checks.CheckMock{
SchemaFunc: func() (*openapi3.SchemaRef, error) {
type CheckResultSpec struct {
name string
}
res := CheckResultSpec{name: "check2"}
return checks.OpenapiFromPerfData[CheckResultSpec](res)
},
},
},
wantErr: false,
validate: func(t *testing.T, doc openapi3.T) {
if _, ok := doc.Paths["/v1/metrics/check1"]; !ok {
t.Errorf("Expected path '/v1/metrics/check1' not found")
}
if _, ok := doc.Paths["/v1/metrics/check2"]; !ok {
t.Errorf("Expected path '/v1/metrics/check2' not found")
}
},
},
{
name: "error in schema generation",
checks: map[string]checks.Check{
"failingCheck": &checks.CheckMock{
SchemaFunc: func() (*openapi3.SchemaRef, error) {
return nil, fmt.Errorf("some error")
},
},
},
wantErr: true,
validate: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
doc, err := GenerateCheckSpecs(ctx, tt.checks)

if (err != nil) != tt.wantErr {
t.Fatalf("GenerateCheckSpecs() error = %v, wantErr %v", err, tt.wantErr)
}

if tt.validate != nil {
tt.validate(t, doc)
}

if tt.wantErr {
var schemaErr *ErrCreateOpenapiSchema
t.Logf("Error = %v", err)
if !errors.As(err, &schemaErr) {
t.Error("Expected ErrCreateOpenapiSchema")
}
}
})
}
}
15 changes: 3 additions & 12 deletions pkg/checks/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ type Check interface {
// Run is called once, to start running the check. The check should
// run until the context is canceled and handle problems itself.
// Returning a non-nil error will cause the shutdown of the check.
Run(ctx context.Context) error
// Startup is called once when the check is registered
// In the Run() method, the check should send results to the cResult channel
// this will cause sparrow to update its data store with the results
Startup(ctx context.Context, cResult chan<- Result) error
Run(ctx context.Context, cResult chan ResultDTO) error
// Shutdown is called once when the check is unregistered or sparrow shuts down
Shutdown(ctx context.Context) error
// SetConfig is called once when the check is registered
Expand All @@ -67,10 +63,8 @@ type Check interface {
type CheckBase struct {
// Mutex for thread-safe access to shared resources within the check implementation
Mu sync.Mutex
// Essential for passing check results back to the Sparrow; must be utilized by Check implementations
CResult chan<- Result
// Signal channel used to notify about shutdown of a check
Done chan bool
DoneChan chan struct{}
}

// Runtime is the interface that all check configurations must implement
Expand All @@ -83,13 +77,10 @@ type Runtime interface {

// Result encapsulates the outcome of a check run.
type Result struct {
// data contains performance metrics about the check run
// Data contains performance metrics about the check run
Data any `json:"data"`
// Timestamp is the UTC time the check was run
Timestamp time.Time `json:"timestamp"`
// Err should be nil if the check ran successfully indicating the check is "healthy"
// if the check failed, this should be an error message that will be logged and returned to an API user
Err string `json:"error"`
}

// ResultDTO is a data transfer object used to associate a check's name with its result.
Expand Down
72 changes: 14 additions & 58 deletions pkg/checks/base_moq.go

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

Loading

0 comments on commit 66ee8fd

Please sign in to comment.