Merge pull request #699 from Tazer/fix-constants-alertmanager

fix: added support for custom alertmanager url
This commit is contained in:
Ankit Nayan 2022-02-10 11:46:12 +05:30 committed by GitHub
commit 10f4fb53ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 6 deletions

View File

@ -33,7 +33,9 @@ SigNoz helps developers monitor applications and troubleshoot problems in their
👉 Run aggregates on trace data to get business relevant metrics
![SigNoz Feature](https://signoz-public.s3.us-east-2.amazonaws.com/signoz_hero_github.png)
![screenzy-1644432902955](https://user-images.githubusercontent.com/504541/153270713-1b2156e6-ec03-42de-975b-3c02b8ec1836.png)
![screenzy-1644432986784](https://user-images.githubusercontent.com/504541/153270725-0efb73b3-06ed-4207-bf13-9b7e2e17c4b8.png)
<br /><br />

View File

@ -660,7 +660,7 @@ func (r *ClickHouseReader) LoadChannel(channel *model.ChannelItem) *model.ApiErr
return &model.ApiError{Typ: model.ErrorBadData, Err: err}
}
response, err := http.Post(constants.ALERTMANAGER_API_PREFIX+"v1/receivers", "application/json", bytes.NewBuffer([]byte(channel.Data)))
response, err := http.Post(constants.GetAlertManagerApiPrefix()+"v1/receivers", "application/json", bytes.NewBuffer([]byte(channel.Data)))
if err != nil {
zap.S().Errorf("Error in getting response of API call to alertmanager/v1/receivers\n", err)
@ -730,7 +730,7 @@ func (r *ClickHouseReader) DeleteChannel(id string) *model.ApiError {
values := map[string]string{"name": channelToDelete.Name}
jsonValue, _ := json.Marshal(values)
req, err := http.NewRequest(http.MethodDelete, constants.ALERTMANAGER_API_PREFIX+"v1/receivers", bytes.NewBuffer(jsonValue))
req, err := http.NewRequest(http.MethodDelete, constants.GetAlertManagerApiPrefix()+"v1/receivers", bytes.NewBuffer(jsonValue))
if err != nil {
zap.S().Errorf("Error in creating new delete request to alertmanager/v1/receivers\n", err)
@ -855,7 +855,7 @@ func (r *ClickHouseReader) EditChannel(receiver *model.Receiver, id string) (*mo
}
}
req, err := http.NewRequest(http.MethodPut, constants.ALERTMANAGER_API_PREFIX+"v1/receivers", bytes.NewBuffer(receiverString))
req, err := http.NewRequest(http.MethodPut, constants.GetAlertManagerApiPrefix()+"v1/receivers", bytes.NewBuffer(receiverString))
if err != nil {
zap.S().Errorf("Error in creating new update request to alertmanager/v1/receivers\n", err)
@ -917,7 +917,7 @@ func (r *ClickHouseReader) CreateChannel(receiver *model.Receiver) (*model.Recei
}
}
response, err := http.Post(constants.ALERTMANAGER_API_PREFIX+"v1/receivers", "application/json", bytes.NewBuffer(receiverString))
response, err := http.Post(constants.GetAlertManagerApiPrefix()+"v1/receivers", "application/json", bytes.NewBuffer(receiverString))
if err != nil {
zap.S().Errorf("Error in getting response of API call to alertmanager/v1/receivers\n", err)

View File

@ -23,7 +23,13 @@ func IsTelemetryEnabled() bool {
const TraceTTL = "traces"
const MetricsTTL = "metrics"
const ALERTMANAGER_API_PREFIX = "http://alertmanager:9093/api/"
func GetAlertManagerApiPrefix() string {
if os.Getenv("ALERTMANAGER_API_PREFIX") != "" {
return os.Getenv("ALERTMANAGER_API_PREFIX")
}
return "http://alertmanager:9093/api/"
}
const RELATIONAL_DATASOURCE_PATH = "/var/lib/signoz/signoz.db"
const (

View File

@ -0,0 +1,20 @@
package constants
import (
. "github.com/smartystreets/goconvey/convey"
"os"
"testing"
)
func TestGetAlertManagerApiPrefix(t *testing.T) {
Convey("TestGetAlertManagerApiPrefix", t, func() {
res := GetAlertManagerApiPrefix()
So(res, ShouldEqual, "http://alertmanager:9093/api/")
Convey("WithEnvSet", func() {
os.Setenv("ALERTMANAGER_API_PREFIX", "http://test:9093/api/")
res = GetAlertManagerApiPrefix()
So(res, ShouldEqual, "http://test:9093/api/")
})
})
}