2025-03-05 10:01:02 +05:30
|
|
|
package alertmanager
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-03-10 01:30:42 +05:30
|
|
|
"net/url"
|
2025-03-05 10:01:02 +05:30
|
|
|
"testing"
|
2025-03-10 01:30:42 +05:30
|
|
|
"time"
|
2025-03-05 10:01:02 +05:30
|
|
|
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/config"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/config/envprovider"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/factory"
|
2025-03-10 01:30:42 +05:30
|
|
|
"github.com/prometheus/common/model"
|
2025-03-05 10:01:02 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNewWithEnvProvider(t *testing.T) {
|
2025-09-10 13:58:13 +05:30
|
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_PROVIDER", "signoz")
|
2025-03-05 10:01:02 +05:30
|
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_LEGACY_API__URL", "http://localhost:9093/api")
|
2025-03-10 01:30:42 +05:30
|
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_SIGNOZ_ROUTE_REPEAT__INTERVAL", "5m")
|
|
|
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_SIGNOZ_EXTERNAL__URL", "https://example.com/test")
|
|
|
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_SIGNOZ_GLOBAL_RESOLVE__TIMEOUT", "10s")
|
2025-03-05 10:01:02 +05:30
|
|
|
|
|
|
|
|
conf, err := config.New(
|
|
|
|
|
context.Background(),
|
|
|
|
|
config.ResolverConfig{
|
|
|
|
|
Uris: []string{"env:"},
|
|
|
|
|
ProviderFactories: []config.ProviderFactory{
|
|
|
|
|
envprovider.NewFactory(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
[]factory.ConfigFactory{
|
|
|
|
|
NewConfigFactory(),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
actual := &Config{}
|
2025-03-10 01:30:42 +05:30
|
|
|
err = conf.Unmarshal("alertmanager", actual, "yaml")
|
2025-03-05 10:01:02 +05:30
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
def := NewConfigFactory().New().(Config)
|
2025-03-10 01:30:42 +05:30
|
|
|
def.Signoz.Global.ResolveTimeout = model.Duration(10 * time.Second)
|
|
|
|
|
def.Signoz.Route.RepeatInterval = 5 * time.Minute
|
|
|
|
|
def.Signoz.ExternalURL = &url.URL{
|
|
|
|
|
Scheme: "https",
|
|
|
|
|
Host: "example.com",
|
|
|
|
|
Path: "/test",
|
|
|
|
|
}
|
2025-03-05 10:01:02 +05:30
|
|
|
|
|
|
|
|
expected := &Config{
|
2025-09-10 13:58:13 +05:30
|
|
|
Provider: "signoz",
|
|
|
|
|
Signoz: def.Signoz,
|
2025-03-05 10:01:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
|
assert.NoError(t, actual.Validate())
|
|
|
|
|
}
|