b332a108f3
* Alerting: Notification history query API. First cut at defining a namespace scoped route on the historian.alerting app to query notification history. * Address review comments
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana-app-sdk/app"
|
|
"github.com/grafana/grafana-app-sdk/simple"
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"github.com/grafana/grafana/apps/alerting/historian/pkg/apis/alertinghistorian/v0alpha1"
|
|
"github.com/grafana/grafana/apps/alerting/historian/pkg/app/config"
|
|
)
|
|
|
|
func New(cfg app.Config) (app.App, error) {
|
|
runtimeConfig := cfg.SpecificConfig.(config.RuntimeConfig)
|
|
|
|
simpleConfig := simple.AppConfig{
|
|
Name: "alerting.historian",
|
|
KubeConfig: cfg.KubeConfig,
|
|
VersionedCustomRoutes: map[string]simple.AppVersionRouteHandlers{
|
|
"v0alpha1": {
|
|
{
|
|
Namespaced: true,
|
|
Path: "/alertstate/history",
|
|
Method: "GET",
|
|
}: runtimeConfig.GetAlertStateHistoryHandler,
|
|
{
|
|
Namespaced: true,
|
|
Path: "/notification/query",
|
|
Method: "POST",
|
|
}: UnimplementedHandler,
|
|
},
|
|
},
|
|
// TODO: Remove when SDK is fixed.
|
|
ManagedKinds: []simple.AppManagedKind{
|
|
{
|
|
Kind: v0alpha1.DummyKind(),
|
|
},
|
|
},
|
|
}
|
|
|
|
a, err := simple.NewApp(simpleConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = a.ValidateManifest(cfg.ManifestData)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
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",
|
|
},
|
|
}
|
|
}
|