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/latency check #19

Merged
merged 17 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"args": [
"run",
"--config",
".vscode/config/local.config.yaml"
"config.yaml",
"--apiAddress",
":9090"
]
},
{
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,35 @@ checks:
healthEndpoint: false
```

### Check: Latency

Available configuration options:

- `checks`
- `latency`
- `enabled` (boolean): Currently not used.
- `interval` (integer): Interval in seconds to perform the latency check.
- `timeout` (integer): Timeout in seconds for the latency check.
- `retry`
- `count` (integer): Number of retries for the latency check.
- `delay` (integer): Delay in seconds between retries for the latency check.
- `targets` (list of strings): List of targets to send latency probe. Needs to be a valid url. Can be another `sparrow` instance. Use latency endpoint, e.g. `https://sparrow-dns.telekom.de/checks/latency`. The remote `sparrow` instance needs the `latencyEndpoint` enabled.
- `latencyEndpoint` (boolean): Needs to be activated when the `sparrow` should expose its own latency endpoint. Mandatory if another `sparrow` instance wants perform a latency check.
Example configuration:

```yaml
checks:
latency:
enabled: true
interval: 1
timeout: 3
retry:
count: 3
delay: 1
targets:
- https://example.com/
- https://google.com/
```

### API

Expand Down
8 changes: 4 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// NewCmdRun creates a new run command
func NewCmdRun() *cobra.Command {
flagMapping := config.RunFlagsNameMapping{
ApiListeningAddress: "apiListeningAddress",
ApiAddress: "apiAddress",
LoaderType: "loaderType",
LoaderInterval: "loaderInterval",
LoaderHttpUrl: "loaderHttpUrl",
Expand All @@ -50,7 +50,7 @@ func NewCmdRun() *cobra.Command {
Run: run(&flagMapping),
}

cmd.PersistentFlags().String(flagMapping.ApiListeningAddress, ":8080", "api: The address the server is listening on")
cmd.PersistentFlags().String(flagMapping.ApiAddress, ":8080", "api: The address the server is listening on")

cmd.PersistentFlags().StringP(flagMapping.LoaderType, "l", "http",
"defines the loader type that will load the checks configuration during the runtime. The fallback is the fileLoader")
Expand All @@ -62,7 +62,7 @@ func NewCmdRun() *cobra.Command {
cmd.PersistentFlags().Int(flagMapping.LoaderHttpRetryDelay, 1, "http loader: The initial delay between retries in seconds")
cmd.PersistentFlags().String(flagMapping.LoaderFilePath, "config.yaml", "file loader: The path to the file to read the runtime config from")

viper.BindPFlag(flagMapping.ApiListeningAddress, cmd.PersistentFlags().Lookup(flagMapping.ApiListeningAddress))
viper.BindPFlag(flagMapping.ApiAddress, cmd.PersistentFlags().Lookup(flagMapping.ApiAddress))

viper.BindPFlag(flagMapping.LoaderType, cmd.PersistentFlags().Lookup(flagMapping.LoaderType))
viper.BindPFlag(flagMapping.LoaderInterval, cmd.PersistentFlags().Lookup(flagMapping.LoaderInterval))
Expand All @@ -84,7 +84,7 @@ func run(fm *config.RunFlagsNameMapping) func(cmd *cobra.Command, args []string)

cfg := config.NewConfig()

cfg.SetApiListeningAddress(viper.GetString(fm.ApiListeningAddress))
cfg.SetApiAddress(viper.GetString(fm.ApiAddress))

cfg.SetLoaderType(viper.GetString(fm.LoaderType))
cfg.SetLoaderInterval(viper.GetInt(fm.LoaderInterval))
Expand Down
21 changes: 21 additions & 0 deletions config.yaml
niklastreml marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: 0.0.1
kind: Config
LoaderType: file
loaderFile: config.yaml

checks:
latency:
enabled: true
interval: 1
timeout: 3
retry:
count: 3
delay: 1
targets:
- https://example.com/
- https://google.com/
- https://httpbin.org/delay/2
- https://httpbin.org/status/500
- http://localhost:8080/checks/v1alpha1/latency
- http://localhost:8081/checks/v1alpha1/latency
apiAddress: :8080
14 changes: 14 additions & 0 deletions config2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: 0.0.1
kind: Config
LoaderType: file
loaderFile: config.yaml

checks:
latency:
enabled: true
interval: 1
targets:
# - http://localhost:8080/v1/metrics/latency
- https://example.com/
# - https://google.com/
apiPort: :8081
2 changes: 1 addition & 1 deletion docs/sparrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ The check results are exposed via an API.
* [sparrow gen-docs](sparrow_gen-docs.md) - Generate markdown documentation
* [sparrow run](sparrow_run.md) - Run sparrow

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
2 changes: 1 addition & 1 deletion docs/sparrow_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ See each sub-command's help for details on how to use the generated script.
* [sparrow completion powershell](sparrow_completion_powershell.md) - Generate the autocompletion script for powershell
* [sparrow completion zsh](sparrow_completion_zsh.md) - Generate the autocompletion script for zsh

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
2 changes: 1 addition & 1 deletion docs/sparrow_completion_bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ sparrow completion bash

* [sparrow completion](sparrow_completion.md) - Generate the autocompletion script for the specified shell

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
2 changes: 1 addition & 1 deletion docs/sparrow_completion_fish.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ sparrow completion fish [flags]

* [sparrow completion](sparrow_completion.md) - Generate the autocompletion script for the specified shell

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
2 changes: 1 addition & 1 deletion docs/sparrow_completion_powershell.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ sparrow completion powershell [flags]

* [sparrow completion](sparrow_completion.md) - Generate the autocompletion script for the specified shell

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
2 changes: 1 addition & 1 deletion docs/sparrow_completion_zsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ sparrow completion zsh [flags]

* [sparrow completion](sparrow_completion.md) - Generate the autocompletion script for the specified shell

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
2 changes: 1 addition & 1 deletion docs/sparrow_gen-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ sparrow gen-docs [flags]

* [sparrow](sparrow.md) - Sparrow, the infrastructure monitoring agent

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
22 changes: 11 additions & 11 deletions docs/sparrow_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ sparrow run [flags]
### Options

```
--apiListeningAddress string api: The address the server is listening on (default ":8080")
-h, --help help for run
--loaderFilePath string file loader: The path to the file to read the runtime config from (default "config.yaml")
--loaderHttpRetryCount int http loader: Amount of retries trying to load the configuration (default 3)
--loaderHttpRetryDelay int http loader: The initial delay between retries in seconds (default 1)
--loaderHttpTimeout int http loader: The timeout for the http request in seconds (default 30)
--loaderHttpToken string http loader: Bearer token to authenticate the http endpoint
--loaderHttpUrl string http loader: The url where to get the remote configuration
--loaderInterval int defines the interval the loader reloads the configuration in seconds (default 300)
-l, --loaderType string defines the loader type that will load the checks configuration during the runtime. The fallback is the fileLoader (default "http")
--apiAddress string api: The address the server is listening on (default ":8080")
-h, --help help for run
--loaderFilePath string file loader: The path to the file to read the runtime config from (default "config.yaml")
--loaderHttpRetryCount int http loader: Amount of retries trying to load the configuration (default 3)
--loaderHttpRetryDelay int http loader: The initial delay between retries in seconds (default 1)
--loaderHttpTimeout int http loader: The timeout for the http request in seconds (default 30)
--loaderHttpToken string http loader: Bearer token to authenticate the http endpoint
--loaderHttpUrl string http loader: The url where to get the remote configuration
--loaderInterval int defines the interval the loader reloads the configuration in seconds (default 300)
-l, --loaderType string defines the loader type that will load the checks configuration during the runtime. The fallback is the fileLoader (default "http")
```

### Options inherited from parent commands
Expand All @@ -35,4 +35,4 @@ sparrow run [flags]

* [sparrow](sparrow.md) - Sparrow, the infrastructure monitoring agent

###### Auto generated by spf13/cobra on 27-Nov-2023
###### Auto generated by spf13/cobra on 30-Nov-2023
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
golang.org/x/sync v0.3.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
3 changes: 2 additions & 1 deletion pkg/checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
// The key is the name of the Check
// The name needs to map the configuration item key
var RegisteredChecks = map[string]func() Check{
"health": NewHealthCheck,
"health": NewHealthCheck,
"latency": NewLatencyCheck,
}

//go:generate moq -out checks_moq.go . Check
Expand Down
Loading