mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-27 02:14:38 +01:00
feat(ui): Implement endpoints[].ui.hide-conditions
This commit is contained in:
parent
7efe7429dd
commit
e0ab35e86a
@ -267,6 +267,7 @@ You can then configure alerts to be triggered when an endpoint is unhealthy once
|
|||||||
| `endpoints[].alerts` | List of all alerts for a given endpoint. <br />See [Alerting](#alerting). | `[]` |
|
| `endpoints[].alerts` | List of all alerts for a given endpoint. <br />See [Alerting](#alerting). | `[]` |
|
||||||
| `endpoints[].client` | [Client configuration](#client-configuration). | `{}` |
|
| `endpoints[].client` | [Client configuration](#client-configuration). | `{}` |
|
||||||
| `endpoints[].ui` | UI configuration at the endpoint level. | `{}` |
|
| `endpoints[].ui` | UI configuration at the endpoint level. | `{}` |
|
||||||
|
| `endpoints[].ui.hide-conditions` | Whether to hide conditions from the results. Note that this only hides conditions from results evaluated from the moment this was enabled. | `false` |
|
||||||
| `endpoints[].ui.hide-hostname` | Whether to hide the hostname in the result. | `false` |
|
| `endpoints[].ui.hide-hostname` | Whether to hide the hostname in the result. | `false` |
|
||||||
| `endpoints[].ui.hide-url` | Whether to ensure the URL is not displayed in the results. Useful if the URL contains a token. | `false` |
|
| `endpoints[].ui.hide-url` | Whether to ensure the URL is not displayed in the results. Useful if the URL contains a token. | `false` |
|
||||||
| `endpoints[].ui.dont-resolve-failed-conditions` | Whether to resolve failed conditions for the UI. | `false` |
|
| `endpoints[].ui.dont-resolve-failed-conditions` | Whether to resolve failed conditions for the UI. | `false` |
|
||||||
|
@ -299,6 +299,9 @@ func (endpoint *Endpoint) EvaluateHealth() *Result {
|
|||||||
}
|
}
|
||||||
result.Hostname = ""
|
result.Hostname = ""
|
||||||
}
|
}
|
||||||
|
if endpoint.UIConfig.HideConditions {
|
||||||
|
result.ConditionResults = nil
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,25 @@ func TestEndpoint(t *testing.T) {
|
|||||||
return &http.Response{StatusCode: http.StatusBadGateway, Body: http.NoBody}
|
return &http.Response{StatusCode: http.StatusBadGateway, Body: http.NoBody}
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "failed-status-condition-with-hidden-conditions",
|
||||||
|
Endpoint: Endpoint{
|
||||||
|
Name: "website-health",
|
||||||
|
URL: "https://twin.sh/health",
|
||||||
|
Conditions: []Condition{"[STATUS] == 200"},
|
||||||
|
UIConfig: &ui.Config{HideConditions: true},
|
||||||
|
},
|
||||||
|
ExpectedResult: &Result{
|
||||||
|
Success: false,
|
||||||
|
Connected: true,
|
||||||
|
Hostname: "twin.sh",
|
||||||
|
ConditionResults: []*ConditionResult{}, // Because UIConfig.HideConditions is true, the condition results should not be shown.
|
||||||
|
DomainExpiration: 0, // Because there's no [DOMAIN_EXPIRATION] condition, this is not resolved, so it should be 0.
|
||||||
|
},
|
||||||
|
MockRoundTripper: test.MockRoundTripper(func(r *http.Request) *http.Response {
|
||||||
|
return &http.Response{StatusCode: http.StatusBadGateway, Body: http.NoBody}
|
||||||
|
}),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "condition-with-failed-certificate-expiration",
|
Name: "condition-with-failed-certificate-expiration",
|
||||||
Endpoint: Endpoint{
|
Endpoint: Endpoint{
|
||||||
|
@ -4,6 +4,9 @@ import "errors"
|
|||||||
|
|
||||||
// Config is the UI configuration for core.Endpoint
|
// Config is the UI configuration for core.Endpoint
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// HideConditions whether to hide the condition results on the UI
|
||||||
|
HideConditions bool `yaml:"hide-conditions"`
|
||||||
|
|
||||||
// HideHostname whether to hide the hostname in the Result
|
// HideHostname whether to hide the hostname in the Result
|
||||||
HideHostname bool `yaml:"hide-hostname"`
|
HideHostname bool `yaml:"hide-hostname"`
|
||||||
|
|
||||||
@ -52,6 +55,7 @@ func GetDefaultConfig() *Config {
|
|||||||
HideHostname: false,
|
HideHostname: false,
|
||||||
HideURL: false,
|
HideURL: false,
|
||||||
DontResolveFailedConditions: false,
|
DontResolveFailedConditions: false,
|
||||||
|
HideConditions: false,
|
||||||
Badge: &Badge{
|
Badge: &Badge{
|
||||||
ResponseTime: &ResponseTime{
|
ResponseTime: &ResponseTime{
|
||||||
Thresholds: []int{50, 200, 300, 500, 750},
|
Thresholds: []int{50, 200, 300, 500, 750},
|
||||||
|
53
core/ui/ui_test.go
Normal file
53
core/ui/ui_test.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidateAndSetDefaults(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
config *Config
|
||||||
|
wantErr error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "with-valid-config",
|
||||||
|
config: &Config{
|
||||||
|
Badge: &Badge{
|
||||||
|
ResponseTime: &ResponseTime{Thresholds: []int{50, 200, 300, 500, 750}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with-invalid-threshold-length",
|
||||||
|
config: &Config{
|
||||||
|
Badge: &Badge{
|
||||||
|
ResponseTime: &ResponseTime{Thresholds: []int{50, 200, 300, 500}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: ErrInvalidBadgeResponseTimeConfig,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with-invalid-thresholds-order",
|
||||||
|
config: &Config{
|
||||||
|
Badge: &Badge{ResponseTime: &ResponseTime{Thresholds: []int{50, 200, 500, 300, 750}}},
|
||||||
|
},
|
||||||
|
wantErr: ErrInvalidBadgeResponseTimeConfig,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with-no-badge-configured", // should give default badge cfg
|
||||||
|
config: &Config{},
|
||||||
|
wantErr: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if err := tt.config.ValidateAndSetDefaults(); !errors.Is(err, tt.wantErr) {
|
||||||
|
t.Errorf("Expected error %v, got %v", tt.wantErr, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user