mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00

### Summary Integrate the new implementations of the alertmanager along with changes to the ruler. This change can be broadly categoried into 3 parts: #### Frontend - The earlier `/api/v1/alerts` api was double encoding the response in json and sending it to the frontend. This PR fixes the json response object. For instance, we have gone from the response `{ "status": "success", "data": "{\"status\":\"success\",\"data\":[{\"labels\":{\"alertname\":\"[platform][consumer] consumer is above 100% memory utilization\",\"bu\":\"platform\",\"...... }` to the response `{"status":"success","data":[{"labels":{"alertname":"[Metrics] Pod CP......` - `msteams` has been changed to `msteamsv2` wherever applicable #### Ruler The following changes have been done in the ruler component: - Removal of the old alertmanager and notifier - The RuleDB methods `Create`, `Edit` and `Delete` have been made transactional - Introduction of a new `testPrepareNotifyFunc` for sending test notifications - Integration with the new alertmanager #### Alertmanager Although a huge chunk of the alertmanagers have been merged in previous PRs (the list can be found at https://github.com/SigNoz/platform-pod/issues/404), this PR takes care of changes needed in order to incorporate it with the ruler - Addition of ruleId based matching - Support for marshalling the global configuration directly from the upstream alertmanager - Addition of orgId to the legacy alertmanager - Support for always adding defaults to both routes and receivers while creating them - Migration to create the required alertmanager tables - Migration for msteams to msteamsv2 has been added. We will start using msteamv2 config for the new alertmanager and keep using msteams for the old one. #### Related Issues / PR's Closes https://github.com/SigNoz/platform-pod/issues/404 Closes https://github.com/SigNoz/platform-pod/issues/176
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package alertmanager
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prometheus/common/model"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.signoz.io/signoz/pkg/config"
|
|
"go.signoz.io/signoz/pkg/config/envprovider"
|
|
"go.signoz.io/signoz/pkg/factory"
|
|
)
|
|
|
|
func TestNewWithEnvProvider(t *testing.T) {
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_PROVIDER", "legacy")
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_LEGACY_API__URL", "http://localhost:9093/api")
|
|
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")
|
|
|
|
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{}
|
|
err = conf.Unmarshal("alertmanager", actual, "yaml")
|
|
require.NoError(t, err)
|
|
|
|
def := NewConfigFactory().New().(Config)
|
|
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",
|
|
}
|
|
|
|
expected := &Config{
|
|
Provider: "legacy",
|
|
Legacy: Legacy{
|
|
ApiURL: &url.URL{
|
|
Scheme: "http",
|
|
Host: "localhost:9093",
|
|
Path: "/api",
|
|
},
|
|
},
|
|
Signoz: def.Signoz,
|
|
}
|
|
|
|
assert.Equal(t, expected, actual)
|
|
assert.NoError(t, actual.Validate())
|
|
}
|