Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dynamic file loader #96

Merged
merged 82 commits into from
Feb 7, 2024
Merged

feat: dynamic file loader #96

merged 82 commits into from
Feb 7, 2024

Conversation

lvlcn-t
Copy link
Collaborator

@lvlcn-t lvlcn-t commented Jan 31, 2024

Motivation

To also dynamically load the runtime config locally with a file.

Closes #85

Changes

I've adjusted the file loader to run in the same interval as the http loader.

Additionally I've fixed some race conditions in the http loader tests and harmonized both loaders.

For additional information look at the commits.

Tests done

I've provided some unit tests for the file loader.

  • Unit tests succeeded.
  • E2E tests succeeded.

Manual E2E test

Logs (with debug logs):

$ go run main.go run --config .tmp/config/start-config.yaml 
Using config file: .tmp/config/start-config.yaml
{"time":"2024-01-31T16:11:21.857325647+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/cmd.NewCmdRun.run.func1","file":"/home/installadm/dev/github/sparrow/cmd/run.go","line":81},"msg":"Running sparrow"}
{"time":"2024-01-31T16:11:21.857438975+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow.(*Sparrow).api.func1","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/api.go","line":81},"msg":"Serving Api","addr":":8080"}
{"time":"2024-01-31T16:11:21.857460883+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).Reconcile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":81},"msg":"Starting global gitlabTargetManager reconciler"}
{"time":"2024-01-31T16:11:51.872199193+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/config.(*FileLoader).Run","file":"/home/installadm/dev/github/sparrow/pkg/config/file.go","line":79},"msg":"Successfully got local runtime configuration"}
{"time":"2024-01-31T16:11:51.872274206+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Startup","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":121},"msg":"Initializing health check"}
{"time":"2024-01-31T16:11:51.872306316+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":93},"msg":"Starting healthcheck","interval":"20s"}
{"time":"2024-01-31T16:12:11.872464888+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":194},"msg":"Checking health"}
{"time":"2024-01-31T16:12:11.872526771+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":199},"msg":"Getting health status for each target in separate routine","amount":2}
{"time":"2024-01-31T16:12:11.872569466+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":236},"msg":"Waiting for all routines to finish"}
{"time":"2024-01-31T16:12:11.872594262+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":221},"msg":"Starting retry routine to get health status","target":"https://www.google.com"}
{"time":"2024-01-31T16:12:11.8726504+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":221},"msg":"Starting retry routine to get health status","target":"https://www.example.com"}
{"time":"2024-01-31T16:12:12.006130511+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":227},"msg":"Successfully got health status of target","target":"https://www.google.com","status":"healthy"}
{"time":"2024-01-31T16:12:12.287731427+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":227},"msg":"Successfully got health status of target","target":"https://www.example.com","status":"healthy"}
{"time":"2024-01-31T16:12:12.287776716+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":239},"msg":"Successfully got health status from all targets"}
{"time":"2024-01-31T16:12:12.287801659+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":113},"msg":"Successfully finished health check run"}
{"time":"2024-01-31T16:12:21.863085495+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/gitlab.(*Client).fetchFileList","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/gitlab/gitlab.go","line":203},"msg":"Fetching file list from gitlab"}
{"time":"2024-01-31T16:12:21.873305744+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/config.(*FileLoader).Run","file":"/home/installadm/dev/github/sparrow/pkg/config/file.go","line":79},"msg":"Successfully got local runtime configuration"}
{"time":"2024-01-31T16:12:21.948094557+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/gitlab.(*Client).fetchFileList","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/gitlab/gitlab.go","line":253},"msg":"Successfully fetched file list","files":2}
{"time":"2024-01-31T16:12:22.022215896+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/gitlab.(*Client).fetchFile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/gitlab/gitlab.go","line":195},"msg":"Successfully fetched file","file":"dev-tom.local.sparrow.com.json"}
{"time":"2024-01-31T16:12:22.105700518+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/gitlab.(*Client).fetchFile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/gitlab/gitlab.go","line":195},"msg":"Successfully fetched file","file":"tom.local.sparrow.de.json"}
{"time":"2024-01-31T16:12:22.10572891+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/gitlab.(*Client).FetchFiles","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/gitlab/gitlab.go","line":149},"msg":"Successfully fetched all target files","files":2}
{"time":"2024-01-31T16:12:22.105741206+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).refreshTargets","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":215},"msg":"Skipping unhealthy target","target":{"url":"https://dev-tom.local.sparrow.com","lastSeen":"2024-01-26T18:03:45.46397814Z"}}
{"time":"2024-01-31T16:12:22.105764532+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).refreshTargets","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":211},"msg":"Found self as global target","lastSeenMin":1.6363695812333332}
{"time":"2024-01-31T16:12:22.105776707+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).refreshTargets","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":222},"msg":"Updated global targets","targets":1}
{"time":"2024-01-31T16:12:22.105793738+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).updateRegistration","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":160},"msg":"Updating registration"}
{"time":"2024-01-31T16:12:22.105814393+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/gitlab.(*Client).PutFile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/gitlab/gitlab.go","line":261},"msg":"Registering sparrow instance to gitlab"}
{"time":"2024-01-31T16:12:22.4599661+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).updateRegistration","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":179},"msg":"Successfully updated registration"}
{"time":"2024-01-31T16:12:32.288176868+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":194},"msg":"Checking health"}
{"time":"2024-01-31T16:12:32.288229653+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":199},"msg":"Getting health status for each target in separate routine","amount":3}
{"time":"2024-01-31T16:12:32.288256339+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":236},"msg":"Waiting for all routines to finish"}
{"time":"2024-01-31T16:12:32.288267021+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":221},"msg":"Starting retry routine to get health status","target":"https://www.telekom.de"}
{"time":"2024-01-31T16:12:32.288295019+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":221},"msg":"Starting retry routine to get health status","target":"https://www.example.com"}
{"time":"2024-01-31T16:12:32.288325164+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":221},"msg":"Starting retry routine to get health status","target":"https://www.google.com"}
{"time":"2024-01-31T16:12:32.351792774+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":227},"msg":"Successfully got health status of target","target":"https://www.google.com","status":"healthy"}
{"time":"2024-01-31T16:12:32.355092395+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":227},"msg":"Successfully got health status of target","target":"https://www.telekom.de","status":"healthy"}
{"time":"2024-01-31T16:12:32.391033677+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check.func2","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":227},"msg":"Successfully got health status of target","target":"https://www.example.com","status":"healthy"}
{"time":"2024-01-31T16:12:32.391116899+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).check","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":239},"msg":"Successfully got health status from all targets"}
{"time":"2024-01-31T16:12:32.391135177+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":113},"msg":"Successfully finished health check run"}

TODO

  • I've assigned this PR to myself
  • I've labeled this PR correctly

niklastreml and others added 30 commits January 16, 2024 18:20
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
…m/sparrow into feat/simplify-helm-chart-config
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
@lvlcn-t lvlcn-t added the feature Introduces a new feature label Jan 31, 2024
@lvlcn-t lvlcn-t self-assigned this Jan 31, 2024
@lvlcn-t lvlcn-t force-pushed the feat/dynamic-file-loader branch from 72e6a60 to 3ea387e Compare January 31, 2024 15:28
Copy link
Collaborator

@puffitos puffitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must still review the tests.

pkg/config/http.go Outdated Show resolved Hide resolved
pkg/config/file.go Show resolved Hide resolved
pkg/config/file.go Outdated Show resolved Hide resolved
pkg/config/file.go Outdated Show resolved Hide resolved
* chore: adjust godoc
* chore: log with path
* fix: handle file close error
* test: add unit test for file close error
* feat: validate file path config
* test: add file path config validation tests
Copy link
Collaborator

@puffitos puffitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, everything seems fine by me. I would additionally comment the methods of the test package which mock the fs.File interface.

pkg/config/file_test.go Outdated Show resolved Hide resolved
pkg/config/file.go Outdated Show resolved Hide resolved
@lvlcn-t lvlcn-t merged commit 577d5c7 into main Feb 7, 2024
11 checks passed
@lvlcn-t lvlcn-t deleted the feat/dynamic-file-loader branch February 7, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: File Loader should also dynamically load files
3 participants