Alerting: Allow missing NGAlert in historian.alerting app (#114750)
This commit is contained in:
@@ -16,6 +16,12 @@ import (
|
||||
func New(cfg app.Config) (app.App, error) {
|
||||
runtimeConfig := cfg.SpecificConfig.(config.RuntimeConfig)
|
||||
|
||||
alertStateHandler := runtimeConfig.GetAlertStateHistoryHandler
|
||||
if alertStateHandler == nil {
|
||||
alertStateHandler = NewErrorHandler("no alert state handler")
|
||||
}
|
||||
notificationHandler := NewErrorHandler("unimplemented")
|
||||
|
||||
simpleConfig := simple.AppConfig{
|
||||
Name: "alerting.historian",
|
||||
KubeConfig: cfg.KubeConfig,
|
||||
@@ -25,12 +31,12 @@ func New(cfg app.Config) (app.App, error) {
|
||||
Namespaced: true,
|
||||
Path: "/alertstate/history",
|
||||
Method: "GET",
|
||||
}: runtimeConfig.GetAlertStateHistoryHandler,
|
||||
}: alertStateHandler,
|
||||
{
|
||||
Namespaced: true,
|
||||
Path: "/notification/query",
|
||||
Method: "POST",
|
||||
}: UnimplementedHandler,
|
||||
}: notificationHandler,
|
||||
},
|
||||
},
|
||||
// TODO: Remove when SDK is fixed.
|
||||
@@ -54,12 +60,14 @@ func New(cfg app.Config) (app.App, error) {
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func UnimplementedHandler(ctx context.Context, writer app.CustomRouteResponseWriter, request *app.CustomRouteRequest) error {
|
||||
return &apierrors.StatusError{
|
||||
ErrStatus: metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Code: http.StatusUnprocessableEntity,
|
||||
Message: "unimplemented",
|
||||
},
|
||||
func NewErrorHandler(message string) simple.AppCustomRouteHandler {
|
||||
return func(ctx context.Context, writer app.CustomRouteResponseWriter, request *app.CustomRouteRequest) error {
|
||||
return &apierrors.StatusError{
|
||||
ErrStatus: metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Code: http.StatusUnprocessableEntity,
|
||||
Message: message,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,19 +26,21 @@ func RegisterAppInstaller(
|
||||
cfg *setting.Cfg,
|
||||
ng *ngalert.AlertNG,
|
||||
) (*AlertingHistorianAppInstaller, error) {
|
||||
if ng.IsDisabled() {
|
||||
log.New("app-registry").Info("Skipping Kubernetes Alerting Historian apiserver (historian.alerting.grafana.app): Unified Alerting is disabled")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
installer := &AlertingHistorianAppInstaller{}
|
||||
appSpecificConfig := historianAppConfig.RuntimeConfig{}
|
||||
|
||||
handlers := &handlers{
|
||||
historian: ng.Api.Historian,
|
||||
}
|
||||
// If we're provided an AlertNG, then call back into that for things we need.
|
||||
// This is a temporary whilst building out the app; we should not depend on it.
|
||||
if ng != nil {
|
||||
if ng.IsDisabled() {
|
||||
log.New("app-registry").Info("Skipping Kubernetes Alerting Historian apiserver (historian.alerting.grafana.app): Unified Alerting is disabled")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
appSpecificConfig := historianAppConfig.RuntimeConfig{
|
||||
GetAlertStateHistoryHandler: handlers.GetAlertStateHistoryHandler,
|
||||
handlers := &handlers{
|
||||
historian: ng.Api.Historian,
|
||||
}
|
||||
appSpecificConfig.GetAlertStateHistoryHandler = handlers.GetAlertStateHistoryHandler
|
||||
}
|
||||
|
||||
provider := simple.NewAppProvider(apis.LocalManifest(), appSpecificConfig, historianApp.New)
|
||||
|
||||
Reference in New Issue
Block a user