caas-team / sparrow

A monitoring tool to gather infrastructure network information
Apache License 2.0
6 stars 4 forks source link

refactor: genericize target manager #122

Closed lvlcn-t closed 3 months ago

lvlcn-t commented 3 months ago

Motivation

This is the second PR to address #66.

Initially the target manager was built to implement the feature of #30 asap. The manager logic was implemented in a way around the gitlab API interactions. To be able to support other remote state backends for global registration we need to genericize the target manager.

Changes

Pretty much everything is moving and renaming in this PR.

The only thing I've really changed is that the config now has a type which specifies the type of the remote interactor used kind of like we already do for the loader.

The new target manager config looks like this:

targetManager:
  type: gitlab # <- This is the new type config option.
  checkInterval: 1m
  registrationInterval: 1m
  updateInterval: 2m
  unhealthyThreshold: 3m
  gitlab:
    baseUrl: https://gitlab.com
    projectId: 123456

I'll change the docs and chart for this later with the last PR regarding #66 that will close the issue.

For additional information look at the commits.

Tests done

Manual e2e tests

Logs

$ go run main.go run --config .tmp/config/start-config.yaml 
Using config file: .tmp/config/start-config.yaml
time=09:35:17 level=INFO source=/home/installadm/dev/github/sparrow/cmd/run.go:81 msg="Running sparrow"
time=09:35:17 level=INFO source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/manager.go:82 msg="Starting target manager reconciliation"
time=09:35:17 level=INFO source=/home/installadm/dev/github/sparrow/pkg/api/api.go:76 msg="Serving Api" addr=:8080
time=09:35:17 level=INFO source=/home/installadm/dev/github/sparrow/pkg/config/file.go:69 msg="File Loader disabled"
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/remote/gitlab/gitlab.go:142 msg="Fetching file list from gitlab"
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/remote/gitlab/gitlab.go:192 msg="Successfully fetched file list" files=3
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/remote/gitlab/gitlab.go:134 msg="Successfully fetched file" file=dev-tom.local.sparrow.com.json
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/remote/gitlab/gitlab.go:134 msg="Successfully fetched file" file=tom.dev.sparrow.com.json
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/remote/gitlab/gitlab.go:134 msg="Successfully fetched file" file=tom.local.sparrow.de.json
time=09:36:17 level=INFO source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/remote/gitlab/gitlab.go:88 msg="Successfully fetched all target files" files=3
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/manager.go:244 msg="Skipping unhealthy target" target="{Url:https://dev-tom.local.sparrow.com LastSeen:2024-02-27 21:30:38.576875669 +0000 UTC}"
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/manager.go:244 msg="Skipping unhealthy target" target="{Url:https://tom.dev.sparrow.com LastSeen:2024-02-29 19:19:44.803342416 +0000 UTC}"
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/manager.go:234 msg="Found self as global target" lastSeenMin=9.450534298533332
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/manager.go:244 msg="Skipping unhealthy target" target="{Url:https://tom.local.sparrow.de LastSeen:2024-03-07 08:26:50.399523487 +0000 UTC}"
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/manager.go:251 msg="Updated global targets" targets=0
time=09:36:17 level=DEBUG source=/home/installadm/dev/github/sparrow/pkg/sparrow/targets/manager.go:164 msg="Already registered as global target"

Remote Repository

image

TODO