Compare commits

..

4 Commits

Author SHA1 Message Date
Konrad Lalik
8595844334 Alerting: Migrate IRM/OnCall/Incident plugin detection to async hooks
Replace synchronous config.apps-based plugin detection with async
hook-based approach using the new useIrmPlugin hook.

Previously, functions like getIrmIfPresentOrOnCallPluginId() read from
config.apps synchronously, which wasn't reliable as it depended on
config being pre-populated. This caused issues where API calls were
made without knowing which plugin was actually installed.

Changes:
- Add useIrmPlugin hook that checks for IRM first, falls back to
  OnCall/Incident. Returns pluginId so callers know which plugin to use
- Update all RTK Query endpoints to accept pluginId as parameter
- Remove synchronous helpers: getIsIrmPluginPresent(),
  getIrmIfPresentOrIncidentPluginId(), getIrmIfPresentOrOnCallPluginId()
- Update all consumers to use useIrmPlugin hook
- Add comprehensive tests for useIrmPlugin hook
- Clean up ESLint suppressions for removed config.apps usage
2026-01-14 16:59:11 +01:00
Konrad Lalik
fd955f90ac Alerting: Enable server-side folder search for GMA rules (#116201)
* Alerting: Support backend filtering for folder search

Updates the Grafana managed rules API and filter logic to support
server-side filtering by folder (namespace).

Changes:
- Add `searchFolder` parameter to `getGrafanaGroups` API endpoint
- Map filter state `namespace` to `searchFolder` in backend filter
- Disable client-side namespace filtering when backend filtering is enabled
- Update tests to verify correct behavior for folder search with backend filters

* Add missing property in filter options

* Update tests
2026-01-14 09:48:07 +01:00
Sonia Aguilar
ccb032f376 Alerting: Single alertmanager contact points versions (#116076)
* POC ssingle AM

* wip

* add query param ?version=2

* wip2

* wip3

* Update logic

* update badges and tests

* remove unsused import

* fix: update NewReceiverView snapshots to include version field

* update translations

* fix: delegate version determination to backend for new integrations

- Remove hardcoded version: 'v1' from defaultChannelValues
- Reset version to undefined when integration type changes
- Backend uses GetCurrentVersion() when no version is provided
- Update snapshots to reflect version handling changes
- Remove unused getDefaultVersionForNotifier function

* update snapshot

* fix(alerting): fix contact point form issues

- Fix empty info alert showing when notifier.dto.info is undefined
- Fix options not loading for new contact points by using default creatable version

* fix(alerting): only show version badge for legacy integrations

* update tests for version badge and getOptionsForVersion changes

* docs: add comment explaining currentVersion field in NotifierDTO

* Show user-friendly 'Legacy' label for legacy integrations

- Replace technical version strings (v0mimir1, v0mimir2) with user-friendly labels
- v0mimir1 -> 'Legacy', v0mimir2 -> 'Legacy v2', etc.
- Technical version is still shown in tooltip for reference
- Add getLegacyVersionLabel() utility function
- Update tests for badge display and utility function

* Add v0mimir2 to test mock for Legacy v2 badge test

* hasLegacyIntegrations now uses isLegacyVersion

- Accept notifiers array to properly check canCreate: false
- No longer relies on version string comparison (v1 check)
- Uses isLegacyVersion for consistent legacy detection
- Update tests to pass notifiers and test correct behavior

* update translations
2026-01-14 08:31:13 +01:00
Alex Khomenko
cf452c167b Provisioning: Do not show the page when the toggle is off (#116206) 2026-01-14 07:41:10 +02:00
49 changed files with 1554 additions and 1519 deletions

View File

@@ -1337,11 +1337,6 @@
"count": 2
}
},
"public/app/features/alerting/unified/api/onCallApi.test.ts": {
"no-restricted-syntax": {
"count": 2
}
},
"public/app/features/alerting/unified/components/AnnotationDetailsField.tsx": {
"@typescript-eslint/consistent-type-assertions": {
"count": 1
@@ -1627,11 +1622,6 @@
"count": 1
}
},
"public/app/features/alerting/unified/mocks/server/configure.ts": {
"no-restricted-syntax": {
"count": 1
}
},
"public/app/features/alerting/unified/mocks/server/handlers/plugins.ts": {
"no-restricted-syntax": {
"count": 1
@@ -1662,16 +1652,6 @@
"count": 1
}
},
"public/app/features/alerting/unified/utils/config.test.ts": {
"no-restricted-syntax": {
"count": 6
}
},
"public/app/features/alerting/unified/utils/config.ts": {
"no-restricted-syntax": {
"count": 1
}
},
"public/app/features/alerting/unified/utils/datasource.ts": {
"no-restricted-syntax": {
"count": 2

View File

@@ -42,7 +42,7 @@ func (r *converter) asDataSource(ds *datasources.DataSource) (*datasourceV0.Data
Generation: int64(ds.Version),
},
Spec: datasourceV0.UnstructuredSpec{},
Secure: ToInlineSecureValues("", ds.UID, maps.Keys(ds.SecureJsonData)),
Secure: ToInlineSecureValues(ds.Type, ds.UID, maps.Keys(ds.SecureJsonData)),
}
obj.UID = gapiutil.CalculateClusterWideUID(obj)
obj.Spec.SetTitle(ds.Name).
@@ -82,11 +82,18 @@ func (r *converter) asDataSource(ds *datasources.DataSource) (*datasourceV0.Data
// ToInlineSecureValues converts secure json into InlineSecureValues with reference names
// The names are predictable and can be used while we implement dual writing for secrets
func ToInlineSecureValues(_ string, dsUID string, keys iter.Seq[string]) common.InlineSecureValues {
func ToInlineSecureValues(dsType string, dsUID string, keys iter.Seq[string]) common.InlineSecureValues {
values := make(common.InlineSecureValues)
for k := range keys {
h := sha256.New()
h.Write([]byte(dsType)) // plugin id
h.Write([]byte("|"))
h.Write([]byte(dsUID)) // unique identifier
h.Write([]byte("|"))
h.Write([]byte(k)) // property name
n := hex.EncodeToString(h.Sum(nil))
values[k] = common.InlineSecureValue{
Name: getLegacySecureValueName(dsUID, k),
Name: "ds-" + n[0:10], // predictable name for dual writing
}
}
if len(values) == 0 {
@@ -95,15 +102,6 @@ func ToInlineSecureValues(_ string, dsUID string, keys iter.Seq[string]) common.
return values
}
func getLegacySecureValueName(dsUID string, key string) string {
h := sha256.New()
h.Write([]byte(dsUID)) // unique identifier
h.Write([]byte("|"))
h.Write([]byte(key)) // property name
n := hex.EncodeToString(h.Sum(nil))
return "ds-" + n[0:10] // predictable name for dual writing
}
func (r *converter) toAddCommand(ds *datasourceV0.DataSource) (*datasources.AddDataSourceCommand, error) {
if r.group != "" && ds.APIVersion != "" && !strings.HasPrefix(ds.APIVersion, r.group) {
return nil, fmt.Errorf("expecting APIGroup: %s", r.group)

View File

@@ -11,11 +11,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apimachinery/utils"
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
"github.com/grafana/grafana/pkg/infra/metrics/metricutil"
"github.com/grafana/grafana/pkg/storage/legacysql/dualwrite"
)
var (
@@ -92,20 +90,6 @@ func (s *legacyStorage) Create(ctx context.Context, obj runtime.Object, createVa
if !ok {
return nil, fmt.Errorf("expected a datasource object")
}
// Verify the secure value commands
for _, v := range ds.Secure {
if v.Create.IsZero() {
return nil, fmt.Errorf("secure values must use create when creating a new datasource")
}
if v.Remove {
return nil, fmt.Errorf("secure values can not use remove when creating a new datasource")
}
if v.Name != "" {
return nil, fmt.Errorf("secure values can not specify a name when creating a new datasource")
}
}
return s.datasources.CreateDataSource(ctx, ds)
}
@@ -138,26 +122,6 @@ func (s *legacyStorage) Update(ctx context.Context, name string, objInfo rest.Up
return nil, false, fmt.Errorf("expected a datasource object (old)")
}
// Expose any secure value changes to the dual writer
var secureChanges common.InlineSecureValues
for k, v := range ds.Secure {
if v.Remove || v.Create != "" {
if secureChanges == nil {
secureChanges = make(common.InlineSecureValues)
}
secureChanges[k] = v
dualwrite.SetUpdatedSecureValues(ctx, ds.Secure)
continue
}
// The legacy store must use fixed names generated by the internal system
// we can not support external shared secrets when using the SQL backing for datasources
validName := getLegacySecureValueName(name, k)
if v.Name != validName {
return nil, false, fmt.Errorf("invalid secure value name %q, expected %q", v.Name, validName)
}
}
// Keep all the old secure values
if len(oldDS.Secure) > 0 {
for k, v := range oldDS.Secure {

View File

@@ -30,7 +30,6 @@ import (
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/apiserver/builder"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/storage/unified/apistore"
"github.com/grafana/grafana/pkg/tsdb/grafana-testdata-datasource/kinds"
)
@@ -103,10 +102,10 @@ func RegisterAPIService(
datasources.GetDatasourceProvider(pluginJSON),
contextProvider,
accessControl,
//nolint:staticcheck // not yet migrated to OpenFeature
DataSourceAPIBuilderConfig{
//nolint:staticcheck // not yet migrated to OpenFeature
LoadQueryTypes: features.IsEnabledGlobally(featuremgmt.FlagDatasourceQueryTypes),
UseDualWriter: features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs),
UseDualWriter: false,
},
)
if err != nil {
@@ -225,12 +224,6 @@ func (b *DataSourceAPIBuilder) AllowedV0Alpha1Resources() []string {
}
func (b *DataSourceAPIBuilder) UpdateAPIGroupInfo(apiGroupInfo *genericapiserver.APIGroupInfo, opts builder.APIGroupOptions) error {
opts.StorageOptsRegister(b.datasourceResourceInfo.GroupResource(), apistore.StorageOptions{
EnableFolderSupport: false,
Scheme: opts.Scheme, // allows for generic Type applied to multiple groups
})
storage := map[string]rest.Storage{}
// Register the raw datasource connection

View File

@@ -33,7 +33,7 @@
},
"secure": {
"password": {
"name": "ds-0d27eff323"
"name": "ds-d5c1b093af"
}
}
}

View File

@@ -22,10 +22,10 @@
},
"secure": {
"extra": {
"name": "ds-6ed1b76e5d"
"name": "ds-bb8b5d8b32"
},
"password": {
"name": "ds-edc8fde0ac"
"name": "ds-973a1eb29d"
}
}
}

View File

@@ -60,7 +60,7 @@ func (s *LocalInlineSecureValueService) CanReference(ctx context.Context, owner
}
if owner.APIGroup == "" || owner.APIVersion == "" || owner.Kind == "" || owner.Name == "" {
return fmt.Errorf("owner reference must have a valid API group, API version, kind and name [CanReference]")
return fmt.Errorf("owner reference must have a valid API group, API version, kind and name")
}
if len(names) == 0 {
@@ -167,7 +167,7 @@ func (s *LocalInlineSecureValueService) verifyOwnerAndAuth(ctx context.Context,
}
if owner.Namespace == "" || owner.APIGroup == "" || owner.APIVersion == "" || owner.Kind == "" || owner.Name == "" {
return nil, fmt.Errorf("owner reference must have a valid API group, API version, kind, namespace and name [verifyOwnerAndAuth:%+v]", owner)
return nil, fmt.Errorf("owner reference must have a valid API group, API version, kind, namespace and name")
}
return authInfo, nil

View File

@@ -54,8 +54,7 @@ func (s *ServiceImpl) getAdminNode(c *contextmodel.ReqContext) (*navtree.NavLink
}
//nolint:staticcheck // not yet migrated to OpenFeature
if c.HasRole(identity.RoleAdmin) &&
(s.cfg.StackID == "" || // show OnPrem even when provisioning is disabled
s.features.IsEnabledGlobally(featuremgmt.FlagProvisioning)) {
s.features.IsEnabledGlobally(featuremgmt.FlagProvisioning) {
generalNodeLinks = append(generalNodeLinks, &navtree.NavLink{
Text: "Provisioning",
Id: "provisioning",

View File

@@ -1,35 +0,0 @@
package dualwrite
import (
"context"
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
)
type ctxKey struct{}
type dualWriteContext struct {
updatedSecureValues common.InlineSecureValues
}
func addToContext(ctx context.Context) context.Context {
return context.WithValue(ctx, ctxKey{}, &dualWriteContext{})
}
// Get the Requester from context
func SetUpdatedSecureValues(ctx context.Context, sv common.InlineSecureValues) {
u, ok := ctx.Value(ctxKey{}).(*dualWriteContext)
if !ok || u == nil {
return // OK, this can happen when things are in mode 0 (legacy only)
}
u.updatedSecureValues = sv
}
// Get the Requester from context
func getUpdatedSecureValues(ctx context.Context) common.InlineSecureValues {
u, ok := ctx.Value(ctxKey{}).(*dualWriteContext)
if !ok || u == nil {
return nil
}
return u.updatedSecureValues
}

View File

@@ -16,15 +16,14 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
"github.com/grafana/grafana-app-sdk/logging"
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apimachinery/utils"
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
)
var (
_ grafanarest.Storage = (*dualWriter)(nil)
tracer = otel.Tracer("github.com/grafana/grafana/pkg/storage/legacysql/dualwrite")
_ grafanarest.Storage = (*dualWriter)(nil)
tracer = otel.Tracer("github.com/grafana/grafana/pkg/storage/legacysql/dualwrite")
)
const (
@@ -204,7 +203,7 @@ func (d *dualWriter) Create(ctx context.Context, in runtime.Object, createValida
log := logging.FromContext(ctx).With("method", "Create")
accIn, err := utils.MetaAccessor(in)
accIn, err := meta.Accessor(in)
if err != nil {
return nil, err
}
@@ -217,19 +216,19 @@ func (d *dualWriter) Create(ctx context.Context, in runtime.Object, createValida
return nil, fmt.Errorf("name or generatename have to be set")
}
secure, err := accIn.GetSecureValues()
if err != nil {
return nil, fmt.Errorf("unable to read secure values %w", err)
}
readFromUnifiedWriteToBothStorages := d.readUnified && d.legacy != nil && d.unified != nil
permissions := ""
if readFromUnifiedWriteToBothStorages {
objIn, err := utils.MetaAccessor(in)
if err != nil {
return nil, err
}
// keep permissions, we will set it back after the object is created
permissions = accIn.GetAnnotation(utils.AnnoKeyGrantPermissions)
permissions = objIn.GetAnnotation(utils.AnnoKeyGrantPermissions)
if permissions != "" {
accIn.SetAnnotation(utils.AnnoKeyGrantPermissions, "") // remove the annotation for now
objIn.SetAnnotation(utils.AnnoKeyGrantPermissions, "") // remove the annotation for now
}
}
@@ -242,36 +241,35 @@ func (d *dualWriter) Create(ctx context.Context, in runtime.Object, createValida
}
createdCopy := createdFromLegacy.DeepCopyObject()
accCreated, err := utils.MetaAccessor(createdCopy)
accCreated, err := meta.Accessor(createdCopy)
if err != nil {
return nil, err
}
accCreated.SetResourceVersion("")
accCreated.SetUID("")
if secure != nil {
if err = accCreated.SetSecureValues(secure); err != nil {
return nil, fmt.Errorf("unable to set secure values on duplicate object %w", err)
}
}
if readFromUnifiedWriteToBothStorages {
objCopy, err := utils.MetaAccessor(createdCopy)
if err != nil {
return nil, err
}
// restore the permissions annotation, as we removed it before creating in legacy
if permissions != "" {
accCreated.SetAnnotation(utils.AnnoKeyGrantPermissions, permissions)
objCopy.SetAnnotation(utils.AnnoKeyGrantPermissions, permissions)
}
// Propagate annotations and labels to the object saved in
// unified storage, making sure the `deprecatedID` is saved
// as well as provisioning metadata, when present.
for name, val := range accIn.GetAnnotations() {
accCreated.SetAnnotation(name, val)
objCopy.SetAnnotation(name, val)
}
legacyAcc, err := meta.Accessor(createdFromLegacy)
if err != nil {
return nil, err
}
accCreated.SetLabels(legacyAcc.GetLabels())
objCopy.SetLabels(legacyAcc.GetLabels())
}
// If unified storage is the primary storage, let's just create it in the foreground and return it.
@@ -386,7 +384,6 @@ func (d *dualWriter) Update(ctx context.Context, name string, objInfo rest.Updat
// but legacy failed, the user would get a failure, but see the update did apply to the source
// of truth, and be less likely to retry to save (and get the stores in sync again)
ctx = addToContext(ctx)
legacyInfo := objInfo
legacyForceCreate := forceAllowCreate
unifiedInfo := objInfo
@@ -420,14 +417,6 @@ func (d *dualWriter) Update(ctx context.Context, name string, objInfo rest.Updat
}
}
// Propagate secure values from the update request to the unified storage update.
if secure := getUpdatedSecureValues(ctx); secure != nil {
wrapped, ok := unifiedInfo.(*wrappedUpdateInfo)
if ok {
wrapped.updatedSecureValues = secure
}
}
if d.readUnified {
return d.unified.Update(ctx, name, unifiedInfo, createValidation, updateValidation, unifiedForceCreate, options)
} else if d.errorIsOK {
@@ -526,10 +515,9 @@ func (d *dualWriter) ConvertToTable(ctx context.Context, object runtime.Object,
}
type wrappedUpdateInfo struct {
objInfo rest.UpdatedObjectInfo
legacyLabels map[string]string
legacyAnnotations map[string]string
updatedSecureValues common.InlineSecureValues
objInfo rest.UpdatedObjectInfo
legacyLabels map[string]string
legacyAnnotations map[string]string
}
// Preconditions implements rest.UpdatedObjectInfo.
@@ -572,13 +560,6 @@ func (w *wrappedUpdateInfo) UpdatedObject(ctx context.Context, oldObj runtime.Ob
meta.SetResourceVersion("")
meta.SetUID("")
if w.updatedSecureValues != nil {
if err = meta.SetSecureValues(w.updatedSecureValues); err != nil {
return nil, fmt.Errorf("unable to set secure values on duplicate object %w", err)
}
}
return obj, err
}

View File

@@ -3,10 +3,8 @@ package apistore
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"time"
"github.com/dustin/go-humanize"
@@ -85,9 +83,6 @@ func (s *Storage) prepareObjectForStorage(ctx context.Context, newObject runtime
if !ok {
return v, errors.New("missing auth info")
}
if err := s.checkGVK(newObject); err != nil {
return v, err
}
obj, err := utils.MetaAccessor(newObject)
if err != nil {
@@ -143,7 +138,8 @@ func (s *Storage) prepareObjectForStorage(ctx context.Context, newObject runtime
return v, err
}
if err = s.encode(newObject, &v.raw); err == nil {
err = s.codec.Encode(newObject, &v.raw)
if err == nil {
err = s.handleLargeResources(ctx, obj, &v.raw)
}
return v, err
@@ -156,9 +152,6 @@ func (s *Storage) prepareObjectForUpdate(ctx context.Context, updateObject runti
if !ok {
return v, errors.New("missing auth info")
}
if err := s.checkGVK(updateObject); err != nil {
return v, err
}
obj, err := utils.MetaAccessor(updateObject)
if err != nil {
@@ -240,7 +233,8 @@ func (s *Storage) prepareObjectForUpdate(ctx context.Context, updateObject runti
obj.SetAnnotation(utils.AnnoKeyUpdatedTimestamp, previous.GetAnnotation(utils.AnnoKeyUpdatedTimestamp))
}
if err = s.encode(updateObject, &v.raw); err == nil {
err = s.codec.Encode(updateObject, &v.raw)
if err == nil {
err = s.handleLargeResources(ctx, obj, &v.raw)
}
return v, err
@@ -274,51 +268,7 @@ func (s *Storage) handleLargeResources(ctx context.Context, obj utils.GrafanaMet
}
// Now encode the smaller version
return s.encode(orig, buf)
return s.codec.Encode(orig, buf)
}
return nil
}
func (s *Storage) checkGVK(obj runtime.Object) error {
if s.opts.Scheme == nil {
return nil // we can not do anything
}
// Ensure group+version+kind are configured
info := obj.GetObjectKind()
gvk := info.GroupVersionKind()
if gvk.Group == "" || gvk.Kind == "" || gvk.Version == "" {
gvks, _, err := s.opts.Scheme.ObjectKinds(obj)
if err != nil {
return fmt.Errorf("unknown object kind %w", err)
}
for _, v := range gvks {
if v.Group != s.gr.Group {
continue // skip values not in this group
}
gvk.Group = v.Group
gvk.Kind = v.Kind
if gvk.Version == "" {
gvk.Version = v.Version
}
info.SetGroupVersionKind(gvk)
return nil
}
}
return nil
}
func (s *Storage) encode(obj runtime.Object, w io.Writer) error {
// The standard encoder is fine when only one type maps to a group
if s.opts.Scheme == nil {
return s.codec.Encode(obj, w)
}
if err := s.checkGVK(obj); err != nil {
return err
}
// This will always write the saved GVK, unlike:
// https://github.com/kubernetes/kubernetes/blob/v1.34.3/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go#L267
// that picks an arbitrary GVK that may not match the same group!
return json.NewEncoder(w).Encode(obj)
}

View File

@@ -33,11 +33,9 @@ func TestPrepareObjectForStorage(t *testing.T) {
node, err := snowflake.NewNode(rand.Int64N(1024))
require.NoError(t, err)
s := &Storage{
gr: dashv1.DashboardResourceInfo.GroupResource(),
codec: apitesting.TestCodec(rtcodecs, dashv1.DashboardResourceInfo.GroupVersion()),
snowflake: node,
opts: StorageOptions{
Scheme: rtscheme,
EnableFolderSupport: true,
LargeObjectSupport: nil,
MaximumNameLength: 100,

View File

@@ -57,8 +57,6 @@ type DefaultPermissionSetter = func(ctx context.Context, key *resourcepb.Resourc
// Optional settings that apply to a single resource
type StorageOptions struct {
Scheme *runtime.Scheme
// ????: should we constrain this to only dashboards for now?
// Not yet clear if this is a good general solution, or just a stop-gap
LargeObjectSupport LargeObjectSupport

View File

@@ -5,8 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"slices"
"testing"
"github.com/stretchr/testify/require"
@@ -15,11 +13,9 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/grafana/grafana/pkg/apimachinery/utils"
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tests/apis"
"github.com/grafana/grafana/pkg/tests/testinfra"
"github.com/grafana/grafana/pkg/tests/testsuite"
@@ -32,192 +28,112 @@ func TestMain(m *testing.M) {
func TestIntegrationTestDatasource(t *testing.T) {
testutil.SkipIntegrationTestInShortMode(t)
expectedAPIVersion := "grafana-testdata-datasource.datasource.grafana.app/v0alpha1"
for _, mode := range []grafanarest.DualWriterMode{
grafanarest.Mode0, // Legacy only
grafanarest.Mode2, // write both, read legacy
grafanarest.Mode3, // write both, read unified
grafanarest.Mode5, // Unified only
} {
t.Run(fmt.Sprintf("testdata (mode:%d)", mode), func(t *testing.T) {
ctx := context.Background()
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
DisableAnonymous: true,
EnableFeatureToggles: []string{
featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the datasource api servers
featuremgmt.FlagQueryServiceWithConnections, // enables CRUD endpoints
},
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
"datasources.grafana-testdata-datasource.datasource.grafana.app": {
DualWriterMode: mode,
},
},
})
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
AppModeProduction: false, // dev mode required for datasource connections
DisableAnonymous: true,
EnableFeatureToggles: []string{
featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service
},
})
client := helper.Org1.Admin.ResourceClient(t, schema.GroupVersionResource{
Group: "grafana-testdata-datasource.datasource.grafana.app",
Version: "v0alpha1",
Resource: "datasources",
}).Namespace("default")
// Create a single datasource
ds := helper.CreateDS(&datasources.AddDataSourceCommand{
Name: "test",
Type: datasources.DS_TESTDATA,
UID: "test",
OrgID: int64(1),
t.Run("create", func(t *testing.T) {
out, err := client.Create(ctx, &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": "grafana-testdata-datasource.datasource.grafana.app/v0alpha1",
"kind": "DataSource",
"metadata": map[string]any{
"name": "test",
},
"spec": map[string]any{
"title": "test",
},
"secure": map[string]any{
"aaa": map[string]any{
"create": "AAA",
},
"bbb": map[string]any{
"create": "BBB",
},
},
},
}, metav1.CreateOptions{})
require.NoError(t, err)
require.Equal(t, "test", out.GetName())
require.Equal(t, expectedAPIVersion, out.GetAPIVersion())
// These settings are not actually used, but testing that they get saved
Database: "testdb",
URL: "http://fake.url",
Access: datasources.DS_ACCESS_PROXY,
User: "example",
ReadOnly: true,
JsonData: simplejson.NewFromAny(map[string]any{
"hello": "world",
}),
SecureJsonData: map[string]string{
"aaa": "AAA",
"bbb": "BBB",
},
})
require.Equal(t, "test", ds.UID)
obj, err := utils.MetaAccessor(out)
require.NoError(t, err)
t.Run("Admin configs", func(t *testing.T) {
client := helper.Org1.Admin.ResourceClient(t, schema.GroupVersionResource{
Group: "grafana-testdata-datasource.datasource.grafana.app",
Version: "v0alpha1",
Resource: "datasources",
}).Namespace("default")
ctx := context.Background()
secure, err := obj.GetSecureValues()
require.NoError(t, err)
list, err := client.List(ctx, metav1.ListOptions{})
require.NoError(t, err)
require.Len(t, list.Items, 1, "expected a single connection")
require.Equal(t, "test", list.Items[0].GetName(), "with the test uid")
keys := slices.Collect(maps.Keys(secure))
require.ElementsMatch(t, []string{"aaa", "bbb"}, keys)
})
spec, _, _ := unstructured.NestedMap(list.Items[0].Object, "spec")
jj, _ := json.MarshalIndent(spec, "", " ")
fmt.Printf("%s\n", string(jj))
require.JSONEq(t, `{
"access": "proxy",
"database": "testdb",
"isDefault": true,
"jsonData": {
"hello": "world"
},
"readOnly": true,
"title": "test",
"url": "http://fake.url",
"user": "example"
}`, string(jj))
})
t.Run("update", func(t *testing.T) {
out, err := client.Update(ctx, &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": "grafana-testdata-datasource.datasource.grafana.app/v0alpha1",
"metadata": map[string]any{
"name": "test",
},
"spec": map[string]any{
"title": "test",
"database": "testdb",
"url": "http://fake.url",
"access": datasources.DS_ACCESS_PROXY,
"user": "example",
"isDefault": true,
"readOnly": true,
"jsonData": map[string]any{
"hello": "world",
},
},
"secure": map[string]any{
// "aaa": map[string]any{
// "remove": true, // remove does not really remove in legacy!
// },
"ccc": map[string]any{
"create": "CCC", // add a third value
},
},
},
}, metav1.UpdateOptions{})
require.NoError(t, err)
require.Equal(t, "test", out.GetName())
require.Equal(t, expectedAPIVersion, out.GetAPIVersion())
t.Run("Call subresources", func(t *testing.T) {
client := helper.Org1.Admin.ResourceClient(t, schema.GroupVersionResource{
Group: "grafana-testdata-datasource.datasource.grafana.app",
Version: "v0alpha1",
Resource: "datasources",
}).Namespace("default")
ctx := context.Background()
obj, err := utils.MetaAccessor(out)
require.NoError(t, err)
list, err := client.List(ctx, metav1.ListOptions{})
require.NoError(t, err)
require.Len(t, list.Items, 1, "expected a single connection")
require.Equal(t, "test", list.Items[0].GetName(), "with the test uid")
secure, err := obj.GetSecureValues()
require.NoError(t, err)
_, err = client.Get(ctx, "test", metav1.GetOptions{}, "health")
// endpoint is disabled currently because it has not been
// sufficiently tested.
// for more info see pkg/registry/apis/datasource/sub_health.go
require.Error(t, err)
var statusErr *apierrors.StatusError
require.True(t, errors.As(err, &statusErr))
require.Equal(t, int32(501), statusErr.ErrStatus.Code)
// require.NoError(t, err)
// body, err := rsp.MarshalJSON()
// require.NoError(t, err)
// //fmt.Printf("GOT: %v\n", string(body))
// require.JSONEq(t, `{
// "apiVersion": "testdata.datasource.grafana.app/v0alpha1",
// "code": 1,
// "kind": "HealthCheckResult",
// "message": "Data source is working",
// "status": "OK"
// }
// `, string(body))
keys := slices.Collect(maps.Keys(secure))
require.ElementsMatch(t, []string{"aaa", "bbb", "ccc"}, keys)
})
t.Run("list", func(t *testing.T) {
list, err := client.List(ctx, metav1.ListOptions{})
require.NoError(t, err)
require.Equal(t, expectedAPIVersion, list.GetAPIVersion())
require.Len(t, list.Items, 1, "expected a single datasource")
require.Equal(t, "test", list.Items[0].GetName(), "with the test uid")
spec, _, _ := unstructured.NestedMap(list.Items[0].Object, "spec")
jj, _ := json.MarshalIndent(spec, "", " ")
// fmt.Printf("%s\n", string(jj))
require.JSONEq(t, `{
"access": "proxy",
"database": "testdb",
"isDefault": true,
"jsonData": {
"hello": "world"
},
"readOnly": true,
"title": "test",
"url": "http://fake.url",
"user": "example"
}`, string(jj))
})
t.Run("execute", func(t *testing.T) {
client := helper.Org1.Admin.ResourceClient(t, schema.GroupVersionResource{
Group: "grafana-testdata-datasource.datasource.grafana.app",
Version: "v0alpha1",
Resource: "datasources",
}).Namespace("default")
ctx := context.Background()
list, err := client.List(ctx, metav1.ListOptions{})
require.NoError(t, err)
require.Len(t, list.Items, 1, "expected a single connection")
require.Equal(t, "test", list.Items[0].GetName(), "with the test uid")
_, err = client.Get(ctx, "test", metav1.GetOptions{}, "health")
// endpoint is disabled currently because it has not been
// sufficiently tested.
// for more info see pkg/registry/apis/datasource/sub_health.go
require.Error(t, err)
var statusErr *apierrors.StatusError
require.True(t, errors.As(err, &statusErr))
require.Equal(t, int32(501), statusErr.ErrStatus.Code)
// require.NoError(t, err)
// body, err := rsp.MarshalJSON()
// require.NoError(t, err)
// //fmt.Printf("GOT: %v\n", string(body))
// require.JSONEq(t, `{
// "apiVersion": "grafana-testdata-datasource.datasource.grafana.app/v0alpha1",
// "code": 1,
// "kind": "HealthCheckResult",
// "message": "Data source is working",
// "status": "OK"
// }
// `, string(body))
// Test connecting to non-JSON marshaled data
raw := apis.DoRequest[any](helper, apis.RequestParams{
User: helper.Org1.Admin,
Method: "GET",
Path: "/apis/grafana-testdata-datasource.datasource.grafana.app/v0alpha1/namespaces/default/datasources/test/resource",
}, nil)
// endpoint is disabled currently because it has not been
// sufficiently tested.
// for more info see pkg/registry/apis/datasource/sub_resource.go
require.Equal(t, int32(501), raw.Status.Code)
// require.Equal(t, `Hello world from test datasource!`, string(raw.Body))
})
t.Run("delete", func(t *testing.T) {
err := client.Delete(ctx, "test", metav1.DeleteOptions{})
require.NoError(t, err)
list, err := client.List(ctx, metav1.ListOptions{})
require.NoError(t, err)
require.Empty(t, list.Items)
})
})
}
// Test connecting to non-JSON marshaled data
raw := apis.DoRequest[any](helper, apis.RequestParams{
User: helper.Org1.Admin,
Method: "GET",
Path: "/apis/grafana-testdata-datasource.datasource.grafana.app/v0alpha1/namespaces/default/datasources/test/resource",
}, nil)
// endpoint is disabled currently because it has not been
// sufficiently tested.
// for more info see pkg/registry/apis/datasource/sub_resource.go
require.Equal(t, int32(501), raw.Status.Code)
// require.Equal(t, `Hello world from test datasource!`, string(raw.Body))
})
}

View File

@@ -103,98 +103,6 @@
],
"description": "list objects of kind DataSource",
"operationId": "listDataSource",
"parameters": [
{
"name": "allowWatchBookmarks",
"in": "query",
"description": "allowWatchBookmarks requests watch events with type \"BOOKMARK\". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "continue",
"in": "query",
"description": "The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\".\n\nThis field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldSelector",
"in": "query",
"description": "A selector to restrict the list of returned objects by their fields. Defaults to everything.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "labelSelector",
"in": "query",
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "limit",
"in": "query",
"description": "limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true.\n\nThe server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned.",
"schema": {
"type": "integer",
"uniqueItems": true
}
},
{
"name": "resourceVersion",
"in": "query",
"description": "resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "resourceVersionMatch",
"in": "query",
"description": "resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "sendInitialEvents",
"in": "query",
"description": "`sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic \"Bookmark\" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `\"k8s.io/initial-events-end\": \"true\"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched.\n\nWhen `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: - `resourceVersionMatch` = NotOlderThan\n is interpreted as \"data at least as new as the provided `resourceVersion`\"\n and the bookmark event is send when the state is synced\n to a `resourceVersion` at least as fresh as the one provided by the ListOptions.\n If `resourceVersion` is unset, this is interpreted as \"consistent read\" and the\n bookmark event is send when the state is synced at least to the moment\n when request started being processed.\n- `resourceVersionMatch` set to any other value or unset\n Invalid error is returned.\n\nDefaults to true if `resourceVersion=\"\"` or `resourceVersion=\"0\"` (for backward compatibility reasons) and to false otherwise.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "timeoutSeconds",
"in": "query",
"description": "Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.",
"schema": {
"type": "integer",
"uniqueItems": true
}
},
{
"name": "watch",
"in": "query",
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
}
],
"responses": {
"200": {
"description": "OK",
@@ -234,285 +142,52 @@
"kind": "DataSource"
}
},
"post": {
"tags": [
"DataSource"
],
"description": "create a DataSource",
"operationId": "createDataSource",
"parameters": [
{
"name": "dryRun",
"in": "query",
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldManager",
"in": "query",
"description": "fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldValidation",
"in": "query",
"description": "fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered.",
"schema": {
"type": "string",
"uniqueItems": true
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
}
},
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
}
},
"202": {
"description": "Accepted",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
}
}
},
"x-kubernetes-action": "post",
"x-kubernetes-group-version-kind": {
"group": "grafana-testdata-datasource.datasource.grafana.app",
"version": "v0alpha1",
"kind": "DataSource"
}
},
"delete": {
"tags": [
"DataSource"
],
"description": "delete collection of DataSource",
"operationId": "deletecollectionDataSource",
"parameters": [
{
"name": "continue",
"in": "query",
"description": "The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\".\n\nThis field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "dryRun",
"in": "query",
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldSelector",
"in": "query",
"description": "A selector to restrict the list of returned objects by their fields. Defaults to everything.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "gracePeriodSeconds",
"in": "query",
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
"schema": {
"type": "integer",
"uniqueItems": true
}
},
{
"name": "ignoreStoreReadErrorWithClusterBreakingPotential",
"in": "query",
"description": "if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "labelSelector",
"in": "query",
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "limit",
"in": "query",
"description": "limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true.\n\nThe server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned.",
"schema": {
"type": "integer",
"uniqueItems": true
}
},
{
"name": "orphanDependents",
"in": "query",
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "propagationPolicy",
"in": "query",
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "resourceVersion",
"in": "query",
"description": "resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "resourceVersionMatch",
"in": "query",
"description": "resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "sendInitialEvents",
"in": "query",
"description": "`sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic \"Bookmark\" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `\"k8s.io/initial-events-end\": \"true\"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched.\n\nWhen `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: - `resourceVersionMatch` = NotOlderThan\n is interpreted as \"data at least as new as the provided `resourceVersion`\"\n and the bookmark event is send when the state is synced\n to a `resourceVersion` at least as fresh as the one provided by the ListOptions.\n If `resourceVersion` is unset, this is interpreted as \"consistent read\" and the\n bookmark event is send when the state is synced at least to the moment\n when request started being processed.\n- `resourceVersionMatch` set to any other value or unset\n Invalid error is returned.\n\nDefaults to true if `resourceVersion=\"\"` or `resourceVersion=\"0\"` (for backward compatibility reasons) and to false otherwise.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "timeoutSeconds",
"in": "query",
"description": "Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.",
"schema": {
"type": "integer",
"uniqueItems": true
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
}
}
}
},
"x-kubernetes-action": "deletecollection",
"x-kubernetes-group-version-kind": {
"group": "grafana-testdata-datasource.datasource.grafana.app",
"version": "v0alpha1",
"kind": "DataSource"
}
},
"parameters": [
{
"name": "allowWatchBookmarks",
"in": "query",
"description": "allowWatchBookmarks requests watch events with type \"BOOKMARK\". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "continue",
"in": "query",
"description": "The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\".\n\nThis field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldSelector",
"in": "query",
"description": "A selector to restrict the list of returned objects by their fields. Defaults to everything.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "labelSelector",
"in": "query",
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "limit",
"in": "query",
"description": "limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true.\n\nThe server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned.",
"schema": {
"type": "integer",
"uniqueItems": true
}
},
{
"name": "namespace",
"in": "path",
@@ -531,6 +206,51 @@
"type": "string",
"uniqueItems": true
}
},
{
"name": "resourceVersion",
"in": "query",
"description": "resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "resourceVersionMatch",
"in": "query",
"description": "resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "sendInitialEvents",
"in": "query",
"description": "`sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic \"Bookmark\" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `\"k8s.io/initial-events-end\": \"true\"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched.\n\nWhen `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: - `resourceVersionMatch` = NotOlderThan\n is interpreted as \"data at least as new as the provided `resourceVersion`\"\n and the bookmark event is send when the state is synced\n to a `resourceVersion` at least as fresh as the one provided by the ListOptions.\n If `resourceVersion` is unset, this is interpreted as \"consistent read\" and the\n bookmark event is send when the state is synced at least to the moment\n when request started being processed.\n- `resourceVersionMatch` set to any other value or unset\n Invalid error is returned.\n\nDefaults to true if `resourceVersion=\"\"` or `resourceVersion=\"0\"` (for backward compatibility reasons) and to false otherwise.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "timeoutSeconds",
"in": "query",
"description": "Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.",
"schema": {
"type": "integer",
"uniqueItems": true
}
},
{
"name": "watch",
"in": "query",
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
}
]
},
@@ -570,330 +290,6 @@
"kind": "DataSource"
}
},
"put": {
"tags": [
"DataSource"
],
"description": "replace the specified DataSource",
"operationId": "replaceDataSource",
"parameters": [
{
"name": "dryRun",
"in": "query",
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldManager",
"in": "query",
"description": "fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldValidation",
"in": "query",
"description": "fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered.",
"schema": {
"type": "string",
"uniqueItems": true
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
}
},
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
}
}
},
"x-kubernetes-action": "put",
"x-kubernetes-group-version-kind": {
"group": "grafana-testdata-datasource.datasource.grafana.app",
"version": "v0alpha1",
"kind": "DataSource"
}
},
"delete": {
"tags": [
"DataSource"
],
"description": "delete a DataSource",
"operationId": "deleteDataSource",
"parameters": [
{
"name": "dryRun",
"in": "query",
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "gracePeriodSeconds",
"in": "query",
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
"schema": {
"type": "integer",
"uniqueItems": true
}
},
{
"name": "ignoreStoreReadErrorWithClusterBreakingPotential",
"in": "query",
"description": "if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "orphanDependents",
"in": "query",
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
},
{
"name": "propagationPolicy",
"in": "query",
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.",
"schema": {
"type": "string",
"uniqueItems": true
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
}
}
},
"202": {
"description": "Accepted",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
}
}
}
}
},
"x-kubernetes-action": "delete",
"x-kubernetes-group-version-kind": {
"group": "grafana-testdata-datasource.datasource.grafana.app",
"version": "v0alpha1",
"kind": "DataSource"
}
},
"patch": {
"tags": [
"DataSource"
],
"description": "partially update the specified DataSource",
"operationId": "updateDataSource",
"parameters": [
{
"name": "dryRun",
"in": "query",
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldManager",
"in": "query",
"description": "fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. This field is required for apply requests (application/apply-patch) but optional for non-apply patch types (JsonPatch, MergePatch, StrategicMergePatch).",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "fieldValidation",
"in": "query",
"description": "fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered.",
"schema": {
"type": "string",
"uniqueItems": true
}
},
{
"name": "force",
"in": "query",
"description": "Force is going to \"force\" Apply requests. It means user will re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply patch requests.",
"schema": {
"type": "boolean",
"uniqueItems": true
}
}
],
"requestBody": {
"content": {
"application/apply-patch+yaml": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
}
},
"application/json-patch+json": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
}
},
"application/merge-patch+json": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
}
},
"application/strategic-merge-patch+json": {
"schema": {
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
}
},
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/vnd.kubernetes.protobuf": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.datasource.v0alpha1.DataSource"
}
}
}
}
},
"x-kubernetes-action": "patch",
"x-kubernetes-group-version-kind": {
"group": "grafana-testdata-datasource.datasource.grafana.app",
"version": "v0alpha1",
"kind": "DataSource"
}
},
"parameters": [
{
"name": "name",
@@ -1550,54 +946,6 @@
}
}
},
"io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions": {
"description": "DeleteOptions may be provided when deleting an API object.",
"type": "object",
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"dryRun": {
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
"type": "array",
"items": {
"type": "string",
"default": ""
},
"x-kubernetes-list-type": "atomic"
},
"gracePeriodSeconds": {
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
"type": "integer",
"format": "int64"
},
"ignoreStoreReadErrorWithClusterBreakingPotential": {
"description": "if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it",
"type": "boolean"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"orphanDependents": {
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
"type": "boolean"
},
"preconditions": {
"description": "Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned.",
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Preconditions"
}
]
},
"propagationPolicy": {
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.",
"type": "string"
}
}
},
"io.k8s.apimachinery.pkg.apis.meta.v1.FieldsV1": {
"description": "FieldsV1 stores a set of fields in a data structure like a Trie, in JSON format.\n\nEach key is either a '.' representing the field itself, and will always map to an empty set, or a string representing a sub-field or item. The string will follow one of these four formats: 'f:\u003cname\u003e', where \u003cname\u003e is the name of a field in a struct, or key in a map 'v:\u003cvalue\u003e', where \u003cvalue\u003e is the exact json formatted value of a list item 'i:\u003cindex\u003e', where \u003cindex\u003e is position of a item in a list 'k:\u003ckeys\u003e', where \u003ckeys\u003e is a map of a list item's key fields to their unique values If a key maps to an empty Fields value, the field that key represents is part of the set.\n\nThe exact format is defined in sigs.k8s.io/structured-merge-diff",
"type": "object"
@@ -1821,131 +1169,6 @@
},
"x-kubernetes-map-type": "atomic"
},
"io.k8s.apimachinery.pkg.apis.meta.v1.Patch": {
"description": "Patch is provided to give a concrete name and type to the Kubernetes PATCH request body.",
"type": "object"
},
"io.k8s.apimachinery.pkg.apis.meta.v1.Preconditions": {
"description": "Preconditions must be fulfilled before an operation (update, delete, etc.) is carried out.",
"type": "object",
"properties": {
"resourceVersion": {
"description": "Specifies the target ResourceVersion",
"type": "string"
},
"uid": {
"description": "Specifies the target UID.",
"type": "string"
}
}
},
"io.k8s.apimachinery.pkg.apis.meta.v1.Status": {
"description": "Status is a return value for calls that don't return other objects.",
"type": "object",
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"code": {
"description": "Suggested HTTP return code for this status, 0 if not set.",
"type": "integer",
"format": "int32"
},
"details": {
"description": "Extended data associated with the reason. Each reason may define its own extended details. This field is optional and the data returned is not guaranteed to conform to any schema except that defined by the reason type.",
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.StatusDetails"
}
],
"x-kubernetes-list-type": "atomic"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"message": {
"description": "A human-readable description of the status of this operation.",
"type": "string"
},
"metadata": {
"description": "Standard list metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta"
}
]
},
"reason": {
"description": "A machine-readable description of why this operation is in the \"Failure\" status. If this value is empty there is no information available. A Reason clarifies an HTTP status code but does not override it.",
"type": "string"
},
"status": {
"description": "Status of the operation. One of: \"Success\" or \"Failure\". More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status",
"type": "string"
}
}
},
"io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause": {
"description": "StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.",
"type": "object",
"properties": {
"field": {
"description": "The field of the resource that has caused this error, as named by its JSON serialization. May include dot and postfix notation for nested attributes. Arrays are zero-indexed. Fields may appear more than once in an array of causes due to fields having multiple errors. Optional.\n\nExamples:\n \"name\" - the field \"name\" on the current resource\n \"items[0].name\" - the field \"name\" on the first array entry in \"items\"",
"type": "string"
},
"message": {
"description": "A human-readable description of the cause of the error. This field may be presented as-is to a reader.",
"type": "string"
},
"reason": {
"description": "A machine-readable description of the cause of the error. If this value is empty there is no information available.",
"type": "string"
}
}
},
"io.k8s.apimachinery.pkg.apis.meta.v1.StatusDetails": {
"description": "StatusDetails is a set of additional properties that MAY be set by the server to provide additional information about a response. The Reason field of a Status object defines what attributes will be set. Clients must ignore fields that do not match the defined type of each attribute, and should assume that any attribute may be empty, invalid, or under defined.",
"type": "object",
"properties": {
"causes": {
"description": "The Causes array includes more details associated with the StatusReason failure. Not all StatusReasons may provide detailed causes.",
"type": "array",
"items": {
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause"
}
]
},
"x-kubernetes-list-type": "atomic"
},
"group": {
"description": "The group attribute of the resource associated with the status StatusReason.",
"type": "string"
},
"kind": {
"description": "The kind attribute of the resource associated with the status StatusReason. On some operations may differ from the requested resource Kind. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"name": {
"description": "The name attribute of the resource associated with the status StatusReason (when there is a single name which can be described).",
"type": "string"
},
"retryAfterSeconds": {
"description": "If specified, the time in seconds before the operation should be retried. Some errors may indicate the client must take an alternate action - for those errors this field may indicate how long to wait before taking the alternate action.",
"type": "integer",
"format": "int32"
},
"uid": {
"description": "UID of the resource. (when there is a single resource which can be described). More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids",
"type": "string"
}
}
},
"io.k8s.apimachinery.pkg.apis.meta.v1.Time": {
"description": "Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.",
"type": "string",

View File

@@ -108,7 +108,9 @@ export const alertmanagerApi = alertingApi.injectEndpoints({
}),
grafanaNotifiers: build.query<NotifierDTO[], void>({
query: () => ({ url: '/api/alert-notifiers' }),
// NOTE: version=2 parameter required for versioned schema (PR #109969)
// This parameter will be removed in future when v2 becomes default
query: () => ({ url: '/api/alert-notifiers?version=2' }),
transformResponse: (response: NotifierDTO[]) => {
const populateSecureFieldKey = (
option: NotificationChannelOption,
@@ -121,11 +123,16 @@ export const alertmanagerApi = alertingApi.injectEndpoints({
),
});
// Keep versions array intact for version-specific options lookup
// Transform options with secureFieldKey population
return response.map((notifier) => ({
...notifier,
options: notifier.options.map((option) => {
return populateSecureFieldKey(option, '');
}),
options: (notifier.options || []).map((option) => populateSecureFieldKey(option, '')),
// Also transform options within each version
versions: notifier.versions?.map((version) => ({
...version,
options: (version.options || []).map((option) => populateSecureFieldKey(option, '')),
})),
}));
},
}),

View File

@@ -1,5 +1,3 @@
import { getIrmIfPresentOrIncidentPluginId } from '../utils/config';
import { alertingApi } from './alertingApi';
interface IncidentsPluginConfigDto {
@@ -7,13 +5,13 @@ interface IncidentsPluginConfigDto {
isIncidentCreated: boolean;
}
const getProxyApiUrl = (path: string) => `/api/plugins/${getIrmIfPresentOrIncidentPluginId()}/resources${path}`;
const getProxyApiUrl = (path: string, pluginId: string) => `/api/plugins/${pluginId}/resources${path}`;
export const incidentsApi = alertingApi.injectEndpoints({
endpoints: (build) => ({
getIncidentsPluginConfig: build.query<IncidentsPluginConfigDto, void>({
query: () => ({
url: getProxyApiUrl('/api/ConfigurationTrackerService.GetConfigurationTracker'),
getIncidentsPluginConfig: build.query<IncidentsPluginConfigDto, { pluginId: string }>({
query: ({ pluginId }) => ({
url: getProxyApiUrl('/api/ConfigurationTrackerService.GetConfigurationTracker', pluginId),
data: {},
method: 'POST',
showErrorAlert: false,

View File

@@ -1,26 +1,16 @@
import { config } from '@grafana/runtime';
import { pluginMeta, pluginMetaToPluginConfig } from '../testSetup/plugins';
import { SupportedPlugin } from '../types/pluginBridges';
import { getProxyApiUrl } from './onCallApi';
describe('getProxyApiUrl', () => {
it('should return URL with IRM plugin ID when IRM plugin is present', () => {
config.apps = { [SupportedPlugin.Irm]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Irm]) };
expect(getProxyApiUrl('/alert_receive_channels/')).toBe(
it('should return URL with IRM plugin ID when IRM plugin ID is passed', () => {
expect(getProxyApiUrl('/alert_receive_channels/', SupportedPlugin.Irm)).toBe(
'/api/plugins/grafana-irm-app/resources/alert_receive_channels/'
);
});
it('should return URL with OnCall plugin ID when IRM plugin is not present', () => {
config.apps = {
[SupportedPlugin.OnCall]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.OnCall]),
[SupportedPlugin.Incident]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Incident]),
};
expect(getProxyApiUrl('/alert_receive_channels/')).toBe(
it('should return URL with OnCall plugin ID when OnCall plugin ID is passed', () => {
expect(getProxyApiUrl('/alert_receive_channels/', SupportedPlugin.OnCall)).toBe(
'/api/plugins/grafana-oncall-app/resources/alert_receive_channels/'
);
});

View File

@@ -1,7 +1,6 @@
import { FetchError, isFetchError } from '@grafana/runtime';
import { GRAFANA_ONCALL_INTEGRATION_TYPE } from '../components/receivers/grafanaAppReceivers/onCall/onCall';
import { getIrmIfPresentOrOnCallPluginId } from '../utils/config';
import { alertingApi } from './alertingApi';
@@ -38,15 +37,15 @@ export interface OnCallConfigChecks {
is_integration_chatops_connected: boolean;
}
export function getProxyApiUrl(path: string) {
return `/api/plugins/${getIrmIfPresentOrOnCallPluginId()}/resources${path}`;
export function getProxyApiUrl(path: string, pluginId: string) {
return `/api/plugins/${pluginId}/resources${path}`;
}
export const onCallApi = alertingApi.injectEndpoints({
endpoints: (build) => ({
grafanaOnCallIntegrations: build.query<OnCallIntegrationDTO[], void>({
query: () => ({
url: getProxyApiUrl('/alert_receive_channels/'),
grafanaOnCallIntegrations: build.query<OnCallIntegrationDTO[], { pluginId: string }>({
query: ({ pluginId }) => ({
url: getProxyApiUrl('/alert_receive_channels/', pluginId),
// legacy_grafana_alerting is necessary for OnCall.
// We do NOT need to differentiate between these two on our side
params: {
@@ -64,31 +63,31 @@ export const onCallApi = alertingApi.injectEndpoints({
},
providesTags: ['OnCallIntegrations'],
}),
validateIntegrationName: build.query<boolean, string>({
query: (name) => ({
url: getProxyApiUrl('/alert_receive_channels/validate_name/'),
validateIntegrationName: build.query<boolean, { name: string; pluginId: string }>({
query: ({ name, pluginId }) => ({
url: getProxyApiUrl('/alert_receive_channels/validate_name/', pluginId),
params: { verbal_name: name },
showErrorAlert: false,
}),
}),
createIntegration: build.mutation<NewOnCallIntegrationDTO, CreateIntegrationDTO>({
query: (integration) => ({
url: getProxyApiUrl('/alert_receive_channels/'),
createIntegration: build.mutation<NewOnCallIntegrationDTO, CreateIntegrationDTO & { pluginId: string }>({
query: ({ pluginId, ...integration }) => ({
url: getProxyApiUrl('/alert_receive_channels/', pluginId),
data: integration,
method: 'POST',
showErrorAlert: true,
}),
invalidatesTags: ['OnCallIntegrations'],
}),
features: build.query<OnCallFeature[], void>({
query: () => ({
url: getProxyApiUrl('/features/'),
features: build.query<OnCallFeature[], { pluginId: string }>({
query: ({ pluginId }) => ({
url: getProxyApiUrl('/features/', pluginId),
showErrorAlert: false,
}),
}),
onCallConfigChecks: build.query<OnCallConfigChecks, void>({
query: () => ({
url: getProxyApiUrl('/organization/config-checks/'),
onCallConfigChecks: build.query<OnCallConfigChecks, { pluginId: string }>({
query: ({ pluginId }) => ({
url: getProxyApiUrl('/organization/config-checks/', pluginId),
showErrorAlert: false,
}),
}),

View File

@@ -46,6 +46,7 @@ export type GrafanaPromRulesOptions = Omit<PromRulesOptions, 'ruleSource' | 'nam
state?: PromAlertingRuleState[];
title?: string;
searchGroupName?: string;
searchFolder?: string;
type?: 'alerting' | 'recording';
ruleMatchers?: string[];
plugins?: 'hide' | 'only';
@@ -103,6 +104,7 @@ export const prometheusApi = alertingApi.injectEndpoints({
title,
datasources,
searchGroupName,
searchFolder,
dashboardUid,
ruleMatchers,
plugins,
@@ -123,6 +125,7 @@ export const prometheusApi = alertingApi.injectEndpoints({
datasource_uid: datasources,
'search.rule_name': title,
'search.rule_group': searchGroupName,
'search.folder': searchFolder,
dashboard_uid: dashboardUid,
rule_matcher: ruleMatchers,
plugins: plugins,

View File

@@ -36,6 +36,24 @@ export const ProvisioningAlert = ({ resource, ...rest }: ProvisioningAlertProps)
);
};
export const ImportedContactPointAlert = (props: ExtraAlertProps) => {
return (
<Alert
title={t(
'alerting.provisioning.title-imported',
'This contact point was imported and cannot be edited through the UI'
)}
severity="info"
{...props}
>
<Trans i18nKey="alerting.provisioning.body-imported">
This contact point contains integrations that were imported from an external Alertmanager and is currently
read-only. The integrations will become editable after the migration process is complete.
</Trans>
</Alert>
);
};
export const ProvisioningBadge = ({
tooltip,
provenance,

View File

@@ -1,8 +1,8 @@
import { Trans, t } from '@grafana/i18n';
import { Button, LinkButton, Menu, Tooltip } from '@grafana/ui';
import { usePluginBridge } from '../../hooks/usePluginBridge';
import { getIrmIfPresentOrIncidentPluginId } from '../../utils/config';
import { useIrmPlugin } from '../../hooks/usePluginBridge';
import { SupportedPlugin } from '../../types/pluginBridges';
import { createBridgeURL } from '../PluginBridge';
interface Props {
@@ -11,20 +11,18 @@ interface Props {
url?: string;
}
const pluginId = getIrmIfPresentOrIncidentPluginId();
export const DeclareIncidentButton = ({ title = '', severity = '', url = '' }: Props) => {
const { pluginId, loading, installed, settings } = useIrmPlugin(SupportedPlugin.Incident);
const bridgeURL = createBridgeURL(pluginId, '/incidents/declare', {
title,
severity,
url,
});
const { loading, installed, settings } = usePluginBridge(pluginId);
return (
<>
{loading === true && (
{loading && (
<Button icon="fire" size="sm" type="button" disabled>
<Trans i18nKey="alerting.declare-incident-button.declare-incident">Declare Incident</Trans>
</Button>
@@ -51,17 +49,17 @@ export const DeclareIncidentButton = ({ title = '', severity = '', url = '' }: P
};
export const DeclareIncidentMenuItem = ({ title = '', severity = '', url = '' }: Props) => {
const { pluginId, loading, installed, settings } = useIrmPlugin(SupportedPlugin.Incident);
const bridgeURL = createBridgeURL(pluginId, '/incidents/declare', {
title,
severity,
url,
});
const { loading, installed, settings } = usePluginBridge(pluginId);
return (
<>
{loading === true && (
{loading && (
<Menu.Item
label={t('alerting.declare-incident-menu-item.label-declare-incident', 'Declare incident')}
icon="fire"

View File

@@ -18,10 +18,10 @@ import { getAPINamespace } from '../../../../../api/utils';
import { alertmanagerApi } from '../../api/alertmanagerApi';
import { onCallApi } from '../../api/onCallApi';
import { useAsync } from '../../hooks/useAsync';
import { usePluginBridge } from '../../hooks/usePluginBridge';
import { useIrmPlugin } from '../../hooks/usePluginBridge';
import { useProduceNewAlertmanagerConfiguration } from '../../hooks/useProduceNewAlertmanagerConfig';
import { addReceiverAction, deleteReceiverAction, updateReceiverAction } from '../../reducers/alertmanager/receivers';
import { getIrmIfPresentOrOnCallPluginId } from '../../utils/config';
import { SupportedPlugin } from '../../types/pluginBridges';
import { enhanceContactPointsWithMetadata } from './utils';
@@ -61,8 +61,8 @@ const defaultOptions = {
* Otherwise, returns no data
*/
const useOnCallIntegrations = ({ skip }: Skippable = {}) => {
const { installed, loading } = usePluginBridge(getIrmIfPresentOrOnCallPluginId());
const oncallIntegrationsResponse = useGrafanaOnCallIntegrationsQuery(undefined, { skip: skip || !installed });
const { pluginId, installed, loading } = useIrmPlugin(SupportedPlugin.OnCall);
const oncallIntegrationsResponse = useGrafanaOnCallIntegrationsQuery({ pluginId }, { skip: skip || !installed });
return useMemo(() => {
if (installed) {
@@ -126,6 +126,10 @@ export const useGrafanaContactPoints = ({
}: GrafanaFetchOptions & Skippable = {}) => {
const namespace = getAPINamespace();
const potentiallySkip = { skip };
// Get the IRM/OnCall plugin information
const irmOrOnCallPlugin = useIrmPlugin(SupportedPlugin.OnCall);
const onCallResponse = useOnCallIntegrations(potentiallySkip);
const alertNotifiers = useGrafanaNotifiersQuery(undefined, potentiallySkip);
const contactPointsListResponse = useK8sContactPoints({ namespace }, potentiallySkip);
@@ -158,6 +162,7 @@ export const useGrafanaContactPoints = ({
status: contactPointsStatusResponse.data,
notifiers: alertNotifiers.data,
onCallIntegrations: onCallResponse?.data,
onCallPluginId: irmOrOnCallPlugin.pluginId,
contactPoints: contactPointsListResponse.data || [],
alertmanagerConfiguration: alertmanagerConfigResponse.data,
});
@@ -172,6 +177,7 @@ export const useGrafanaContactPoints = ({
contactPointsListResponse,
contactPointsStatusResponse,
onCallResponse,
irmOrOnCallPlugin.pluginId,
]);
};

View File

@@ -15,6 +15,7 @@ import {
} from 'app/plugins/datasource/alertmanager/types';
import { OnCallIntegrationDTO } from '../../api/onCallApi';
import { SupportedPlugin } from '../../types/pluginBridges';
import { extractReceivers } from '../../utils/receivers';
import { routeAdapter } from '../../utils/routeAdapter';
import { ReceiverTypes } from '../receivers/grafanaAppReceivers/onCall/onCall';
@@ -113,7 +114,8 @@ export interface ContactPointWithMetadata extends GrafanaManagedContactPoint {
type EnhanceContactPointsArgs = {
status?: ReceiversStateDTO[];
notifiers?: NotifierDTO[];
onCallIntegrations?: OnCallIntegrationDTO[] | undefined | null;
onCallIntegrations?: OnCallIntegrationDTO[];
onCallPluginId?: SupportedPlugin;
contactPoints: Receiver[];
alertmanagerConfiguration?: AlertManagerCortexConfig;
};
@@ -130,6 +132,7 @@ export function enhanceContactPointsWithMetadata({
status = [],
notifiers = [],
onCallIntegrations,
onCallPluginId,
contactPoints,
alertmanagerConfiguration,
}: EnhanceContactPointsArgs): ContactPointWithMetadata[] {
@@ -162,7 +165,7 @@ export function enhanceContactPointsWithMetadata({
[RECEIVER_META_KEY]: getNotifierMetadata(notifiers, receiver),
// if OnCall plugin is installed, we'll add it to the receiver's plugin metadata
[RECEIVER_PLUGIN_META_KEY]: isOnCallReceiver
? getOnCallMetadata(onCallIntegrations, receiver, Boolean(alertmanagerConfiguration))
? getOnCallMetadata(onCallIntegrations, receiver, Boolean(alertmanagerConfiguration), onCallPluginId)
: undefined,
};
}),

View File

@@ -1,11 +1,12 @@
import 'core-js/stable/structured-clone';
import { FormProvider, useForm } from 'react-hook-form';
import { clickSelectOption } from 'test/helpers/selectOptionInTest';
import { render } from 'test/test-utils';
import { render, screen } from 'test/test-utils';
import { byRole, byTestId } from 'testing-library-selector';
import { grafanaAlertNotifiers } from 'app/features/alerting/unified/mockGrafanaNotifiers';
import { AlertmanagerProvider } from 'app/features/alerting/unified/state/AlertmanagerContext';
import { NotifierDTO } from 'app/features/alerting/unified/types/alerting';
import { ChannelSubForm } from './ChannelSubForm';
import { GrafanaCommonChannelSettings } from './GrafanaCommonChannelSettings';
@@ -16,6 +17,7 @@ type TestChannelValues = {
type: string;
settings: Record<string, unknown>;
secureFields: Record<string, boolean>;
version?: string;
};
type TestReceiverFormValues = {
@@ -246,4 +248,241 @@ describe('ChannelSubForm', () => {
expect(slackUrl).toBeEnabled();
expect(slackUrl).toHaveValue('');
});
describe('version-specific options display', () => {
// Create a mock notifier with different options for v0 and v1
const legacyOptions = [
{
element: 'input' as const,
inputType: 'text',
label: 'Legacy URL',
description: 'The legacy endpoint URL',
placeholder: '',
propertyName: 'legacyUrl',
required: true,
secure: false,
showWhen: { field: '', is: '' },
validationRule: '',
dependsOn: '',
},
];
const webhookWithVersions: NotifierDTO = {
...grafanaAlertNotifiers.webhook,
versions: [
{
version: 'v0mimir1',
label: 'Webhook (Legacy)',
description: 'Legacy webhook from Mimir',
canCreate: false,
options: legacyOptions,
},
{
version: 'v0mimir2',
label: 'Webhook (Legacy v2)',
description: 'Legacy webhook v2 from Mimir',
canCreate: false,
options: legacyOptions,
},
{
version: 'v1',
label: 'Webhook',
description: 'Sends HTTP POST request',
canCreate: true,
options: grafanaAlertNotifiers.webhook.options,
},
],
};
const versionedNotifiers: Notifier[] = [
{ dto: webhookWithVersions, meta: { enabled: true, order: 1 } },
{ dto: grafanaAlertNotifiers.slack, meta: { enabled: true, order: 2 } },
];
function VersionedTestFormWrapper({
defaults,
initial,
}: {
defaults: TestChannelValues;
initial?: TestChannelValues;
}) {
const form = useForm<TestReceiverFormValues>({
defaultValues: {
name: 'test-contact-point',
items: [defaults],
},
});
return (
<AlertmanagerProvider accessType="notification">
<FormProvider {...form}>
<ChannelSubForm
defaultValues={defaults}
initialValues={initial}
pathPrefix={`items.0.`}
integrationIndex={0}
notifiers={versionedNotifiers}
onDuplicate={jest.fn()}
commonSettingsComponent={GrafanaCommonChannelSettings}
isEditable={true}
isTestable={false}
canEditProtectedFields={true}
/>
</FormProvider>
</AlertmanagerProvider>
);
}
function renderVersionedForm(defaults: TestChannelValues, initial?: TestChannelValues) {
return render(<VersionedTestFormWrapper defaults={defaults} initial={initial} />);
}
it('should display v1 options when integration has v1 version', () => {
const webhookV1: TestChannelValues = {
__id: 'id-0',
type: 'webhook',
version: 'v1',
settings: { url: 'https://example.com' },
secureFields: {},
};
renderVersionedForm(webhookV1, webhookV1);
// Should show v1 URL field (from default options)
expect(ui.settings.webhook.url.get()).toBeInTheDocument();
// Should NOT show legacy URL field
expect(screen.queryByRole('textbox', { name: /Legacy URL/i })).not.toBeInTheDocument();
});
it('should display v0 options when integration has legacy version', () => {
const webhookV0: TestChannelValues = {
__id: 'id-0',
type: 'webhook',
version: 'v0mimir1',
settings: { legacyUrl: 'https://legacy.example.com' },
secureFields: {},
};
renderVersionedForm(webhookV0, webhookV0);
// Should show legacy URL field (from v0 options)
expect(screen.getByRole('textbox', { name: /Legacy URL/i })).toBeInTheDocument();
// Should NOT show v1 URL field
expect(ui.settings.webhook.url.query()).not.toBeInTheDocument();
});
it('should display "Legacy" badge for v0mimir1 integration', () => {
const webhookV0: TestChannelValues = {
__id: 'id-0',
type: 'webhook',
version: 'v0mimir1',
settings: { legacyUrl: 'https://legacy.example.com' },
secureFields: {},
};
renderVersionedForm(webhookV0, webhookV0);
// Should show "Legacy" badge for v0mimir1 integrations
expect(screen.getByText('Legacy')).toBeInTheDocument();
});
it('should display "Legacy v2" badge for v0mimir2 integration', () => {
const webhookV0v2: TestChannelValues = {
__id: 'id-0',
type: 'webhook',
version: 'v0mimir2',
settings: { legacyUrl: 'https://legacy.example.com' },
secureFields: {},
};
renderVersionedForm(webhookV0v2, webhookV0v2);
// Should show "Legacy v2" badge for v0mimir2 integrations
expect(screen.getByText('Legacy v2')).toBeInTheDocument();
});
it('should NOT display version badge for v1 integration', () => {
const webhookV1: TestChannelValues = {
__id: 'id-0',
type: 'webhook',
version: 'v1',
settings: { url: 'https://example.com' },
secureFields: {},
};
renderVersionedForm(webhookV1, webhookV1);
// Should NOT show version badge for non-legacy v1 integrations
expect(screen.queryByText('v1')).not.toBeInTheDocument();
});
it('should filter out notifiers with canCreate: false from dropdown', () => {
// Create a notifier that only has v0 versions (cannot be created)
const legacyOnlyNotifier: NotifierDTO = {
type: 'wechat',
name: 'WeChat',
heading: 'WeChat settings',
description: 'Sends notifications to WeChat',
options: [],
versions: [
{
version: 'v0mimir1',
label: 'WeChat (Legacy)',
description: 'Legacy WeChat',
canCreate: false,
options: [],
},
],
};
const notifiersWithLegacyOnly: Notifier[] = [
{ dto: webhookWithVersions, meta: { enabled: true, order: 1 } },
{ dto: legacyOnlyNotifier, meta: { enabled: true, order: 2 } },
];
function LegacyOnlyTestWrapper({ defaults }: { defaults: TestChannelValues }) {
const form = useForm<TestReceiverFormValues>({
defaultValues: {
name: 'test-contact-point',
items: [defaults],
},
});
return (
<AlertmanagerProvider accessType="notification">
<FormProvider {...form}>
<ChannelSubForm
defaultValues={defaults}
pathPrefix={`items.0.`}
integrationIndex={0}
notifiers={notifiersWithLegacyOnly}
onDuplicate={jest.fn()}
commonSettingsComponent={GrafanaCommonChannelSettings}
isEditable={true}
isTestable={false}
canEditProtectedFields={true}
/>
</FormProvider>
</AlertmanagerProvider>
);
}
render(
<LegacyOnlyTestWrapper
defaults={{
__id: 'id-0',
type: 'webhook',
settings: {},
secureFields: {},
}}
/>
);
// Webhook should be in dropdown (has v1 with canCreate: true)
expect(ui.typeSelector.get()).toHaveTextContent('Webhook');
// WeChat should NOT be in the options (only has v0 with canCreate: false)
// We can't easily check dropdown options without opening it, but the filter should work
});
});
});

View File

@@ -6,7 +6,7 @@ import { Controller, FieldErrors, useFormContext } from 'react-hook-form';
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
import { Trans, t } from '@grafana/i18n';
import { Alert, Button, Field, Select, Stack, Text, useStyles2 } from '@grafana/ui';
import { Alert, Badge, Button, Field, Select, Stack, Text, useStyles2 } from '@grafana/ui';
import { NotificationChannelOption } from 'app/features/alerting/unified/types/alerting';
import {
@@ -16,6 +16,12 @@ import {
GrafanaChannelValues,
ReceiverFormValues,
} from '../../../types/receiver-form';
import {
canCreateNotifier,
getLegacyVersionLabel,
getOptionsForVersion,
isLegacyVersion,
} from '../../../utils/notifier-versions';
import { OnCallIntegrationType } from '../grafanaAppReceivers/onCall/useOnCallIntegration';
import { ChannelOptions } from './ChannelOptions';
@@ -62,6 +68,7 @@ export function ChannelSubForm<R extends ChannelValues>({
const channelFieldPath = `items.${integrationIndex}` as const;
const typeFieldPath = `${channelFieldPath}.type` as const;
const versionFieldPath = `${channelFieldPath}.version` as const;
const settingsFieldPath = `${channelFieldPath}.settings` as const;
const secureFieldsPath = `${channelFieldPath}.secureFields` as const;
@@ -104,6 +111,9 @@ export function ChannelSubForm<R extends ChannelValues>({
setValue(settingsFieldPath, defaultNotifierSettings);
setValue(secureFieldsPath, {});
// Reset version when changing type - backend will use its default
setValue(versionFieldPath, undefined);
}
// Restore initial value of an existing oncall integration
@@ -123,6 +133,7 @@ export function ChannelSubForm<R extends ChannelValues>({
setValue,
settingsFieldPath,
typeFieldPath,
versionFieldPath,
secureFieldsPath,
getValues,
watch,
@@ -164,24 +175,30 @@ export function ChannelSubForm<R extends ChannelValues>({
setValue(`${settingsFieldPath}.${fieldPath}`, undefined);
};
const typeOptions = useMemo(
(): SelectableValue[] =>
sortBy(notifiers, ({ dto, meta }) => [meta?.order ?? 0, dto.name]).map<SelectableValue>(
({ dto: { name, type }, meta }) => ({
// @ts-expect-error ReactNode is supported
const typeOptions = useMemo((): SelectableValue[] => {
// Filter out notifiers that can't be created (e.g., v0-only integrations like WeChat)
// These are legacy integrations that only exist in Mimir and can't be created in Grafana
const creatableNotifiers = notifiers.filter(({ dto }) => canCreateNotifier(dto));
return sortBy(creatableNotifiers, ({ dto, meta }) => [meta?.order ?? 0, dto.name]).map<SelectableValue>(
({ dto: { name, type }, meta }) => {
return {
// ReactNode is supported in Select label, but types don't reflect it
/* eslint-disable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any */
label: (
<Stack alignItems="center" gap={1}>
{name}
{meta?.badge}
</Stack>
),
) as any,
/* eslint-enable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any */
value: type,
description: meta?.description,
isDisabled: meta ? !meta.enabled : false,
})
),
[notifiers]
);
};
}
);
}, [notifiers]);
const handleTest = async () => {
await trigger();
@@ -198,10 +215,21 @@ export function ChannelSubForm<R extends ChannelValues>({
// Cloud AM takes no value at all
const isParseModeNone = parse_mode === 'None' || !parse_mode;
const showTelegramWarning = isTelegram && !isParseModeNone;
// Check if current integration is a legacy version (canCreate: false)
// Legacy integrations are read-only and cannot be edited
// Read version from existing integration data (stored in receiver config)
const integrationVersion = initialValues?.version || defaultValues.version;
const isLegacy = notifier ? isLegacyVersion(notifier.dto, integrationVersion) : false;
// Get the correct options based on the integration's version
// This ensures legacy (v0) integrations display the correct schema
const versionedOptions = notifier ? getOptionsForVersion(notifier.dto, integrationVersion) : [];
// if there are mandatory options defined, optional options will be hidden by a collapse
// if there aren't mandatory options, all options will be shown without collapse
const mandatoryOptions = notifier?.dto.options.filter((o) => o.required) ?? [];
const optionalOptions = notifier?.dto.options.filter((o) => !o.required) ?? [];
const mandatoryOptions = versionedOptions.filter((o) => o.required);
const optionalOptions = versionedOptions.filter((o) => !o.required);
const contactPointTypeInputId = `contact-point-type-${pathPrefix}`;
return (
@@ -214,21 +242,35 @@ export function ChannelSubForm<R extends ChannelValues>({
data-testid={`${pathPrefix}type`}
noMargin
>
<Controller
name={typeFieldPath}
control={control}
defaultValue={defaultValues.type}
render={({ field: { ref, onChange, ...field } }) => (
<Select
disabled={!isEditable}
inputId={contactPointTypeInputId}
{...field}
width={37}
options={typeOptions}
onChange={(value) => onChange(value?.value)}
<Stack direction="row" alignItems="center" gap={1}>
<Controller
name={typeFieldPath}
control={control}
defaultValue={defaultValues.type}
render={({ field: { ref, onChange, ...field } }) => (
<Select
disabled={!isEditable}
inputId={contactPointTypeInputId}
{...field}
width={37}
options={typeOptions}
onChange={(value) => onChange(value?.value)}
/>
)}
/>
{isLegacy && integrationVersion && (
<Badge
text={getLegacyVersionLabel(integrationVersion)}
color="orange"
icon="exclamation-triangle"
tooltip={t(
'alerting.channel-sub-form.tooltip-legacy-version',
'This is a legacy integration (version: {{version}}). It cannot be modified.',
{ version: integrationVersion }
)}
/>
)}
/>
</Stack>
</Field>
</div>
<div className={styles.buttons}>
@@ -292,7 +334,7 @@ export function ChannelSubForm<R extends ChannelValues>({
name: notifier.dto.name,
})}
>
{notifier.dto.info !== '' && (
{notifier.dto.info && (
<Alert title="" severity="info">
{notifier.dto.info}
</Alert>

View File

@@ -18,12 +18,13 @@ import {
import { alertmanagerApi } from '../../../api/alertmanagerApi';
import { GrafanaChannelValues, ReceiverFormValues } from '../../../types/receiver-form';
import { hasLegacyIntegrations } from '../../../utils/notifier-versions';
import {
formChannelValuesToGrafanaChannelConfig,
formValuesToGrafanaReceiver,
grafanaReceiverToFormValues,
} from '../../../utils/receiver-form';
import { ProvisionedResource, ProvisioningAlert } from '../../Provisioning';
import { ImportedContactPointAlert, ProvisionedResource, ProvisioningAlert } from '../../Provisioning';
import { ReceiverTypes } from '../grafanaAppReceivers/onCall/onCall';
import { useOnCallIntegration } from '../grafanaAppReceivers/onCall/useOnCallIntegration';
@@ -39,6 +40,8 @@ const defaultChannelValues: GrafanaChannelValues = Object.freeze({
secureFields: {},
disableResolveMessage: false,
type: 'email',
// version is intentionally not set here - it will be determined by the notifier's currentVersion
// when the integration is created/type is changed. The backend will use its default if not provided.
});
interface Props {
@@ -67,7 +70,6 @@ export const GrafanaReceiverForm = ({ contactPoint, readOnly = false, editMode }
} = useOnCallIntegration();
const { data: grafanaNotifiers = [], isLoading: isLoadingNotifiers } = useGrafanaNotifiersQuery();
const [testReceivers, setTestReceivers] = useState<Receiver[]>();
// transform receiver DTO to form values
@@ -135,15 +137,20 @@ export const GrafanaReceiverForm = ({ contactPoint, readOnly = false, editMode }
);
}
// Map notifiers to Notifier[] format for ReceiverForm
// The grafanaNotifiers include version-specific options via the versions array from the backend
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
const notifiers: Notifier[] = grafanaNotifiers.map((n) => {
if (n.type === ReceiverTypes.OnCall) {
return {
dto: extendOnCallNotifierFeatures(n),
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
dto: extendOnCallNotifierFeatures(n as any) as any,
meta: onCallNotifierMeta,
};
}
return { dto: n };
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
return { dto: n as any };
});
return (
@@ -163,7 +170,12 @@ export const GrafanaReceiverForm = ({ contactPoint, readOnly = false, editMode }
</Alert>
)}
{contactPoint?.provisioned && <ProvisioningAlert resource={ProvisionedResource.ContactPoint} />}
{contactPoint?.provisioned && hasLegacyIntegrations(contactPoint, grafanaNotifiers) && (
<ImportedContactPointAlert />
)}
{contactPoint?.provisioned && !hasLegacyIntegrations(contactPoint, grafanaNotifiers) && (
<ProvisioningAlert resource={ProvisionedResource.ContactPoint} />
)}
<ReceiverForm<GrafanaChannelValues>
contactPointId={contactPoint?.id}

View File

@@ -6,12 +6,12 @@ import { t } from '@grafana/i18n';
import { isFetchError } from '@grafana/runtime';
import { Badge } from '@grafana/ui';
import { NotifierDTO } from 'app/features/alerting/unified/types/alerting';
import { getIrmIfPresentOrOnCallPluginId } from 'app/features/alerting/unified/utils/config';
import { useAppNotification } from '../../../../../../../core/copy/appNotification';
import { Receiver } from '../../../../../../../plugins/datasource/alertmanager/types';
import { ONCALL_INTEGRATION_V2_FEATURE, onCallApi } from '../../../../api/onCallApi';
import { usePluginBridge } from '../../../../hooks/usePluginBridge';
import { useIrmPlugin } from '../../../../hooks/usePluginBridge';
import { SupportedPlugin } from '../../../../types/pluginBridges';
import { option } from '../../../../utils/notifier-types';
import { GRAFANA_ONCALL_INTEGRATION_TYPE, ReceiverTypes } from './onCall';
@@ -39,16 +39,17 @@ enum OnCallIntegrationStatus {
function useOnCallPluginStatus() {
const {
pluginId,
installed: isOnCallEnabled,
loading: isPluginBridgeLoading,
error: pluginError,
} = usePluginBridge(getIrmIfPresentOrOnCallPluginId());
} = useIrmPlugin(SupportedPlugin.OnCall);
const {
data: onCallFeatures = [],
error: onCallFeaturesError,
isLoading: isOnCallFeaturesLoading,
} = onCallApi.endpoints.features.useQuery(undefined, { skip: !isOnCallEnabled });
} = onCallApi.endpoints.features.useQuery({ pluginId }, { skip: !isOnCallEnabled });
const integrationStatus = useMemo((): OnCallIntegrationStatus => {
if (!isOnCallEnabled) {
@@ -67,6 +68,7 @@ function useOnCallPluginStatus() {
);
return {
pluginId,
isOnCallEnabled,
integrationStatus,
isAlertingV2IntegrationEnabled,
@@ -78,8 +80,14 @@ function useOnCallPluginStatus() {
export function useOnCallIntegration() {
const notifyApp = useAppNotification();
const { isOnCallEnabled, integrationStatus, isAlertingV2IntegrationEnabled, isOnCallStatusLoading, onCallError } =
useOnCallPluginStatus();
const {
pluginId,
isOnCallEnabled,
integrationStatus,
isAlertingV2IntegrationEnabled,
isOnCallStatusLoading,
onCallError,
} = useOnCallPluginStatus();
const { useCreateIntegrationMutation, useGrafanaOnCallIntegrationsQuery, useLazyValidateIntegrationNameQuery } =
onCallApi;
@@ -91,13 +99,13 @@ export function useOnCallIntegration() {
data: grafanaOnCallIntegrations = [],
isLoading: isLoadingOnCallIntegrations,
isError: isIntegrationsQueryError,
} = useGrafanaOnCallIntegrationsQuery(undefined, { skip: !isAlertingV2IntegrationEnabled });
} = useGrafanaOnCallIntegrationsQuery({ pluginId }, { skip: !isAlertingV2IntegrationEnabled });
const onCallFormValidators = useMemo(() => {
return {
integration_name: async (value: string) => {
try {
await validateIntegrationNameQuery(value).unwrap();
await validateIntegrationNameQuery({ name: value, pluginId }).unwrap();
return true;
} catch (error) {
if (isFetchError(error) && error.status === 409) {
@@ -126,7 +134,7 @@ export function useOnCallIntegration() {
: t('alerting.irm-integration.integration-required', 'Selection of existing IRM integration is required');
},
};
}, [grafanaOnCallIntegrations, validateIntegrationNameQuery, isAlertingV2IntegrationEnabled, notifyApp]);
}, [grafanaOnCallIntegrations, validateIntegrationNameQuery, isAlertingV2IntegrationEnabled, notifyApp, pluginId]);
const extendOnCallReceivers = useCallback(
(receiver: Receiver): Receiver => {
@@ -159,6 +167,7 @@ export function useOnCallIntegration() {
const createNewOnCallIntegrationJobs = newOnCallIntegrations.map(async (c) => {
const newIntegration = await createIntegrationMutation({
pluginId,
integration: GRAFANA_ONCALL_INTEGRATION_TYPE,
verbal_name: c.settings[OnCallIntegrationSetting.IntegrationName],
}).unwrap();
@@ -180,7 +189,7 @@ export function useOnCallIntegration() {
});
});
},
[isAlertingV2IntegrationEnabled, createIntegrationMutation]
[isAlertingV2IntegrationEnabled, createIntegrationMutation, pluginId]
);
const extendOnCallNotifierFeatures = useCallback(

View File

@@ -1,6 +1,9 @@
import { useMemo } from 'react';
import { GrafanaManagedReceiverConfig } from '../../../../../../plugins/datasource/alertmanager/types';
import { OnCallIntegrationDTO } from '../../../api/onCallApi';
import { getIrmIfPresentOrOnCallPluginId, getIsIrmPluginPresent } from '../../../utils/config';
import { useIrmPlugin } from '../../../hooks/usePluginBridge';
import { SupportedPlugin } from '../../../types/pluginBridges';
import { createBridgeURL } from '../../PluginBridge';
import { GRAFANA_APP_RECEIVERS_SOURCE_IMAGE } from './types';
@@ -13,20 +16,34 @@ export interface ReceiverPluginMetadata {
warning?: string;
}
const onCallReceiverICon = GRAFANA_APP_RECEIVERS_SOURCE_IMAGE[getIrmIfPresentOrOnCallPluginId()];
const onCallReceiverTitle = 'Grafana OnCall';
export const onCallReceiverMeta: ReceiverPluginMetadata = {
title: onCallReceiverTitle,
icon: onCallReceiverICon,
};
export function getOnCallMetadata(
export function useOnCallMetadata(
onCallIntegrations: OnCallIntegrationDTO[] | undefined | null,
receiver: GrafanaManagedReceiverConfig,
hasAlertManagerConfigData = true
): ReceiverPluginMetadata {
const pluginName = getIsIrmPluginPresent() ? 'IRM' : 'OnCall';
const { pluginId } = useIrmPlugin(SupportedPlugin.OnCall);
return useMemo(
() => getOnCallMetadata(onCallIntegrations, receiver, hasAlertManagerConfigData, pluginId),
[onCallIntegrations, receiver, hasAlertManagerConfigData, pluginId]
);
}
export function getOnCallMetadata(
onCallIntegrations: OnCallIntegrationDTO[] | undefined | null,
receiver: GrafanaManagedReceiverConfig,
hasAlertManagerConfigData = true,
onCallPluginId?: SupportedPlugin
): ReceiverPluginMetadata {
const pluginId = onCallPluginId || SupportedPlugin.OnCall;
const pluginName = pluginId === SupportedPlugin.Irm ? 'IRM' : 'OnCall';
const onCallReceiverIcon = GRAFANA_APP_RECEIVERS_SOURCE_IMAGE[pluginId];
const onCallReceiverTitle = pluginId === SupportedPlugin.Irm ? 'Grafana IRM' : 'Grafana OnCall';
const onCallReceiverMeta: ReceiverPluginMetadata = {
title: onCallReceiverTitle,
icon: onCallReceiverIcon,
};
if (!hasAlertManagerConfigData) {
return onCallReceiverMeta;
@@ -57,7 +74,7 @@ export function getOnCallMetadata(
...onCallReceiverMeta,
description: matchingOnCallIntegration?.display_name,
externalUrl: matchingOnCallIntegration
? createBridgeURL(getIrmIfPresentOrOnCallPluginId(), `/integrations/${matchingOnCallIntegration.value}`)
? createBridgeURL(pluginId, `/integrations/${matchingOnCallIntegration.value}`)
: undefined,
warning: matchingOnCallIntegration ? undefined : `${pluginName} Integration no longer exists`,
};

View File

@@ -0,0 +1,146 @@
import { renderHook, waitFor } from '@testing-library/react';
import { getPluginSettings } from 'app/features/plugins/pluginSettings';
import { pluginMeta } from '../testSetup/plugins';
import { SupportedPlugin } from '../types/pluginBridges';
import { useIrmPlugin } from './usePluginBridge';
jest.mock('app/features/plugins/pluginSettings');
const mockedGetPluginSettings = jest.mocked(getPluginSettings);
describe('useIrmPlugin', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should return IRM plugin ID when IRM plugin is installed', async () => {
mockedGetPluginSettings.mockImplementation((pluginId) => {
if (pluginId === SupportedPlugin.Irm) {
return Promise.resolve(pluginMeta[SupportedPlugin.Irm]);
}
if (pluginId === SupportedPlugin.OnCall) {
return Promise.resolve({ ...pluginMeta[SupportedPlugin.OnCall], enabled: false });
}
return Promise.reject(new Error('Plugin not found'));
});
const { result } = renderHook(() => useIrmPlugin(SupportedPlugin.OnCall));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.pluginId).toBe(SupportedPlugin.Irm);
expect(result.current.installed).toBe(true);
expect(result.current.settings).toBeDefined();
});
it('should return OnCall plugin ID when IRM plugin is not installed', async () => {
mockedGetPluginSettings.mockImplementation((pluginId) => {
if (pluginId === SupportedPlugin.OnCall) {
return Promise.resolve(pluginMeta[SupportedPlugin.OnCall]);
}
return Promise.reject(new Error('Plugin not found'));
});
const { result } = renderHook(() => useIrmPlugin(SupportedPlugin.OnCall));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.pluginId).toBe(SupportedPlugin.OnCall);
expect(result.current.installed).toBe(true);
expect(result.current.settings).toBeDefined();
});
it('should return Incident plugin ID when IRM plugin is not installed', async () => {
mockedGetPluginSettings.mockImplementation((pluginId) => {
if (pluginId === SupportedPlugin.Incident) {
return Promise.resolve(pluginMeta[SupportedPlugin.Incident]);
}
return Promise.reject(new Error('Plugin not found'));
});
const { result } = renderHook(() => useIrmPlugin(SupportedPlugin.Incident));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.pluginId).toBe(SupportedPlugin.Incident);
expect(result.current.installed).toBe(true);
expect(result.current.settings).toBeDefined();
});
it('should return loading state while fetching plugins', () => {
mockedGetPluginSettings.mockImplementation(
() => new Promise((resolve) => setTimeout(() => resolve(pluginMeta[SupportedPlugin.Irm]), 100))
);
const { result } = renderHook(() => useIrmPlugin(SupportedPlugin.OnCall));
expect(result.current.loading).toBe(true);
expect(result.current.installed).toBeUndefined();
});
it('should return installed undefined when neither plugin is installed', async () => {
mockedGetPluginSettings.mockRejectedValue(new Error('Plugin not found'));
const { result } = renderHook(() => useIrmPlugin(SupportedPlugin.OnCall));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.pluginId).toBe(SupportedPlugin.OnCall);
expect(result.current.installed).toBeUndefined();
});
it('should return IRM plugin ID when both IRM and OnCall are installed', async () => {
mockedGetPluginSettings.mockImplementation((pluginId) => {
if (pluginId === SupportedPlugin.Irm) {
return Promise.resolve(pluginMeta[SupportedPlugin.Irm]);
}
if (pluginId === SupportedPlugin.OnCall) {
return Promise.resolve(pluginMeta[SupportedPlugin.OnCall]);
}
return Promise.reject(new Error('Plugin not found'));
});
const { result } = renderHook(() => useIrmPlugin(SupportedPlugin.OnCall));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.pluginId).toBe(SupportedPlugin.Irm);
expect(result.current.installed).toBe(true);
expect(result.current.settings).toEqual(pluginMeta[SupportedPlugin.Irm]);
});
it('should return IRM plugin ID when both IRM and Incident are installed', async () => {
mockedGetPluginSettings.mockImplementation((pluginId) => {
if (pluginId === SupportedPlugin.Irm) {
return Promise.resolve(pluginMeta[SupportedPlugin.Irm]);
}
if (pluginId === SupportedPlugin.Incident) {
return Promise.resolve(pluginMeta[SupportedPlugin.Incident]);
}
return Promise.reject(new Error('Plugin not found'));
});
const { result } = renderHook(() => useIrmPlugin(SupportedPlugin.Incident));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.pluginId).toBe(SupportedPlugin.Irm);
expect(result.current.installed).toBe(true);
expect(result.current.settings).toEqual(pluginMeta[SupportedPlugin.Irm]);
});
});

View File

@@ -4,6 +4,8 @@ import { PluginMeta } from '@grafana/data';
import { getPluginSettings } from 'app/features/plugins/pluginSettings';
import { PluginID } from '../components/PluginBridge';
import { SupportedPlugin } from '../types/pluginBridges';
interface PluginBridgeHookResponse {
loading: boolean;
installed?: boolean;
@@ -14,17 +16,54 @@ interface PluginBridgeHookResponse {
export function usePluginBridge(plugin: PluginID): PluginBridgeHookResponse {
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false }));
const installed = value && !error && !loading;
const enabled = value?.enabled;
const isLoading = loading && !value;
if (isLoading) {
if (loading) {
return { loading: true };
}
if (!installed || !enabled) {
return { loading: false, installed: false };
if (error) {
return { loading, error };
}
return { loading, installed: true, settings: value };
if (value) {
return { loading, installed: value.enabled ?? false, settings: value };
}
return { loading, installed: false };
}
type FallbackPlugin = SupportedPlugin.OnCall | SupportedPlugin.Incident;
type IrmWithFallback = SupportedPlugin.Irm | FallbackPlugin;
export interface PluginBridgeResult {
pluginId: IrmWithFallback;
loading: boolean;
installed?: boolean;
error?: Error;
settings?: PluginMeta<{}>;
}
/**
* Hook that checks for IRM plugin first, falls back to specified plugin.
* IRM replaced both OnCall and Incident - this provides backward compatibility.
*
* @param fallback - The plugin to use if IRM is not installed (OnCall or Incident)
* @returns Bridge result with the active plugin data
*
* @example
* const { pluginId, loading, installed, settings } = useIrmPlugin(SupportedPlugin.OnCall);
*/
export function useIrmPlugin(fallback: FallbackPlugin): PluginBridgeResult {
const irmBridge = usePluginBridge(SupportedPlugin.Irm);
const fallbackBridge = usePluginBridge(fallback);
const loading = irmBridge.loading || fallbackBridge.loading;
const pluginId = irmBridge.installed ? SupportedPlugin.Irm : fallback;
const activeBridge = irmBridge.installed ? irmBridge : fallbackBridge;
return {
pluginId,
loading,
installed: activeBridge.installed,
error: activeBridge.error,
settings: activeBridge.settings,
};
}

View File

@@ -1,6 +1,5 @@
import { type DefaultBodyType, HttpResponse, HttpResponseResolver, PathParams, http } from 'msw';
import { config } from '@grafana/runtime';
import server from '@grafana/test-utils/server';
import { mockDataSource, mockFolder } from 'app/features/alerting/unified/mocks';
import {
@@ -10,10 +9,7 @@ import {
} from 'app/features/alerting/unified/mocks/server/handlers/alertmanagers';
import { getFolderHandler } from 'app/features/alerting/unified/mocks/server/handlers/folders';
import { listNamespacedTimeIntervalHandler } from 'app/features/alerting/unified/mocks/server/handlers/k8s/timeIntervals.k8s';
import {
getDisabledPluginHandler,
getPluginMissingHandler,
} from 'app/features/alerting/unified/mocks/server/handlers/plugins';
import { getDisabledPluginHandler } from 'app/features/alerting/unified/mocks/server/handlers/plugins';
import {
ALERTING_API_SERVER_BASE_URL,
getK8sResponse,
@@ -212,12 +208,6 @@ export function setGrafanaPromRules(groups: GrafanaPromRuleGroupDTO[]) {
server.use(http.get(`/api/prometheus/grafana/api/v1/rules`, paginatedHandlerFor(groups)));
}
/** Make a given plugin ID respond with a 404, as if it isn't installed at all */
export const removePlugin = (pluginId: string) => {
delete config.apps[pluginId];
server.use(getPluginMissingHandler(pluginId));
};
/** Make a plugin respond with `enabled: false`, as if its installed but disabled */
export const disablePlugin = (pluginId: SupportedPlugin) => {
clearPluginSettingsCache(pluginId);

View File

@@ -455,6 +455,25 @@ describe('grafana-managed rules', () => {
expect(frontendFilter.ruleMatches(regularRule)).toBe(true);
expect(frontendFilter.ruleMatches(pluginRule)).toBe(true);
});
it('should include searchFolder in backend filter when namespace is provided', () => {
const { backendFilter } = getGrafanaFilter(getFilter({ namespace: 'my-folder' }));
expect(backendFilter.searchFolder).toBe('my-folder');
});
it('should skip namespace filtering on frontend when backend filtering is enabled', () => {
const group: PromRuleGroupDTO = {
name: 'Test Group',
file: 'production/alerts',
rules: [],
interval: 60,
};
const { frontendFilter } = getGrafanaFilter(getFilter({ namespace: 'staging' }));
// Should return true because namespace filter is null (handled by backend)
expect(frontendFilter.groupMatches(group)).toBe(true);
});
});
describe('when alertingUIUseBackendFilters is disabled', () => {
@@ -537,6 +556,12 @@ describe('grafana-managed rules', () => {
expect(backendFilter.searchGroupName).toBeUndefined();
});
it('should not include searchFolder in backend filter', () => {
const { backendFilter } = getGrafanaFilter(getFilter({ namespace: 'my-folder' }));
expect(backendFilter.searchFolder).toBeUndefined();
});
it('should perform groupName filtering on frontend', () => {
const group: PromRuleGroupDTO = {
name: 'CPU Usage Alerts',
@@ -706,8 +731,8 @@ describe('grafana-managed rules', () => {
expect(frontendFilter.groupMatches(group)).toBe(true);
});
it('should still apply always-frontend filters (namespace)', () => {
// Namespace filter should still work
it('should skip namespace filtering on frontend', () => {
// Namespace filter should be handled by backend
const group: PromRuleGroupDTO = {
name: 'Test Group',
file: 'production/alerts',
@@ -719,7 +744,7 @@ describe('grafana-managed rules', () => {
expect(nsFilter.groupMatches(group)).toBe(true);
const { frontendFilter: nsFilter2 } = getGrafanaFilter(getFilter({ namespace: 'staging' }));
expect(nsFilter2.groupMatches(group)).toBe(false);
expect(nsFilter2.groupMatches(group)).toBe(true);
});
it('should skip dataSourceNames filtering on frontend (handled by backend)', () => {
@@ -807,8 +832,8 @@ describe('grafana-managed rules', () => {
expect(hasGrafanaClientSideFilters(getFilter({ labels: ['severity=critical'] }))).toBe(false);
});
it('should return true for client-side only filters', () => {
expect(hasGrafanaClientSideFilters(getFilter({ namespace: 'production' }))).toBe(true);
it('should return false for namespace filter (handled by backend)', () => {
expect(hasGrafanaClientSideFilters(getFilter({ namespace: 'production' }))).toBe(false);
});
it('should return false for plugins filter (handled by backend when feature toggle is enabled)', () => {
@@ -862,8 +887,8 @@ describe('grafana-managed rules', () => {
expect(hasGrafanaClientSideFilters(getFilter({ ruleHealth: RuleHealth.Ok }))).toBe(false);
expect(hasGrafanaClientSideFilters(getFilter({ contactPoint: 'my-contact-point' }))).toBe(false);
// Should return true for: always-frontend filters only (namespace)
expect(hasGrafanaClientSideFilters(getFilter({ namespace: 'production' }))).toBe(true);
// Should return false for: namespace (handled by backend)
expect(hasGrafanaClientSideFilters(getFilter({ namespace: 'production' }))).toBe(false);
// plugins is backend-handled when both feature toggles are enabled
expect(hasGrafanaClientSideFilters(getFilter({ plugins: 'hide' }))).toBe(false);

View File

@@ -96,6 +96,7 @@ export function getGrafanaFilter(filterState: Partial<RulesFilter>) {
datasources: ruleFilterConfig.dataSourceNames ? undefined : datasourceUids,
ruleMatchers: ruleMatchersBackendFilter,
plugins: ruleFilterConfig.plugins ? undefined : normalizedFilterState.plugins,
searchFolder: groupFilterConfig.namespace ? undefined : normalizedFilterState.namespace,
};
return {
@@ -134,7 +135,7 @@ function buildGrafanaFilterConfigs() {
};
const groupFilterConfig: GroupFilterConfig = {
namespace: namespaceFilter,
namespace: useBackendFilters ? null : namespaceFilter,
groupName: useBackendFilters ? null : groupNameFilter,
};

View File

@@ -45,6 +45,7 @@ interface GrafanaPromApiFilter {
contactPoint?: string;
title?: string;
searchGroupName?: string;
searchFolder?: string;
type?: 'alerting' | 'recording';
dashboardUid?: string;
}

View File

@@ -75,6 +75,7 @@ describe('paginationLimits', () => {
{ contactPoint: 'slack' },
{ dataSourceNames: ['prometheus'] },
{ labels: ['severity=critical'] },
{ namespace: 'production' },
])(
'should return rule limit for grafana + large limit for datasource when only backend filters are used: %p',
(filterState) => {
@@ -84,16 +85,6 @@ describe('paginationLimits', () => {
expect(datasourceManagedLimit).toEqual({ groupLimit: FILTERED_GROUPS_LARGE_API_PAGE_SIZE });
}
);
it.each<Partial<RulesFilter>>([
{ namespace: 'production' },
{ ruleState: PromAlertingRuleState.Firing, namespace: 'production' },
])('should return large limits for both when frontend filters are used: %p', (filterState) => {
const { grafanaManagedLimit, datasourceManagedLimit } = getFilteredRulesLimits(getFilter(filterState));
expect(grafanaManagedLimit).toEqual({ groupLimit: FILTERED_GROUPS_LARGE_API_PAGE_SIZE });
expect(datasourceManagedLimit).toEqual({ groupLimit: FILTERED_GROUPS_LARGE_API_PAGE_SIZE });
});
});
describe('when alertingUIUseFullyCompatBackendFilters is enabled', () => {
@@ -158,6 +149,7 @@ describe('paginationLimits', () => {
{ contactPoint: 'slack' },
{ dataSourceNames: ['prometheus'] },
{ labels: ['severity=critical'] },
{ namespace: 'production' },
])(
'should return rule limit for grafana + large limit for datasource when only backend filters are used: %p',
(filterState) => {
@@ -167,16 +159,6 @@ describe('paginationLimits', () => {
expect(datasourceManagedLimit).toEqual({ groupLimit: FILTERED_GROUPS_LARGE_API_PAGE_SIZE });
}
);
it.each<Partial<RulesFilter>>([{ namespace: 'production' }])(
'should return large limits for both when frontend filters are used: %p',
(filterState) => {
const { grafanaManagedLimit, datasourceManagedLimit } = getFilteredRulesLimits(getFilter(filterState));
expect(grafanaManagedLimit).toEqual({ groupLimit: FILTERED_GROUPS_LARGE_API_PAGE_SIZE });
expect(datasourceManagedLimit).toEqual({ groupLimit: FILTERED_GROUPS_LARGE_API_PAGE_SIZE });
}
);
});
});
});

View File

@@ -80,6 +80,20 @@ export type CloudNotifierType =
| 'jira';
export type NotifierType = GrafanaNotifierType | CloudNotifierType;
/**
* Represents a specific version of a notifier integration
* Used for integration versioning during Single Alert Manager migration
*/
export interface NotifierVersion {
version: string;
label: string;
description: string;
options: NotificationChannelOption[];
/** Whether this version can be used to create new integrations */
canCreate?: boolean;
}
export interface NotifierDTO<T = NotifierType> {
name: string;
description: string;
@@ -88,6 +102,23 @@ export interface NotifierDTO<T = NotifierType> {
options: NotificationChannelOption[];
info?: string;
secure?: boolean;
/**
* Available versions for this notifier from the backend
* Each version contains version-specific options and metadata
*/
versions?: NotifierVersion[];
/**
* The default version that the backend will use when creating new integrations.
* Returned by the backend from /api/alert-notifiers?version=2
*
* - "v1" for most notifiers (modern Grafana version)
* - "v0mimir1" for legacy-only notifiers (e.g., WeChat)
*
* Note: Currently not used in the frontend. The backend handles version
* selection automatically. Could be used in the future to display
* version information or validate notifier capabilities.
*/
currentVersion?: string;
}
export interface NotificationChannelType {

View File

@@ -8,6 +8,7 @@ import { ControlledField } from '../hooks/useControlledFieldArray';
export interface ChannelValues {
__id: string; // used to correlate form values to original DTOs
type: string;
version?: string; // Integration version (e.g. "v0" for Mimir legacy, "v1" for Grafana)
settings: Record<string, any>;
secureFields: Record<string, boolean | ''>;
}

View File

@@ -1,14 +1,6 @@
import { config } from '@grafana/runtime';
import { pluginMeta, pluginMetaToPluginConfig } from '../testSetup/plugins';
import { SupportedPlugin } from '../types/pluginBridges';
import {
checkEvaluationIntervalGlobalLimit,
getIrmIfPresentOrIncidentPluginId,
getIrmIfPresentOrOnCallPluginId,
getIsIrmPluginPresent,
} from './config';
import { checkEvaluationIntervalGlobalLimit } from './config';
describe('checkEvaluationIntervalGlobalLimit', () => {
it('should NOT exceed limit if evaluate every is not valid duration', () => {
@@ -59,48 +51,3 @@ describe('checkEvaluationIntervalGlobalLimit', () => {
expect(exceedsLimit).toBe(false);
});
});
describe('getIsIrmPluginPresent', () => {
it('should return true when IRM plugin is present in config.apps', () => {
config.apps = { [SupportedPlugin.Irm]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Irm]) };
expect(getIsIrmPluginPresent()).toBe(true);
});
it('should return false when IRM plugin is not present in config.apps', () => {
config.apps = {
[SupportedPlugin.OnCall]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.OnCall]),
[SupportedPlugin.Incident]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Incident]),
};
expect(getIsIrmPluginPresent()).toBe(false);
});
});
describe('getIrmIfPresentOrIncidentPluginId', () => {
it('should return IRM plugin ID when IRM plugin is present', () => {
config.apps = { [SupportedPlugin.Irm]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Irm]) };
expect(getIrmIfPresentOrIncidentPluginId()).toBe(SupportedPlugin.Irm);
});
it('should return Incident plugin ID when IRM plugin is not present', () => {
config.apps = {
[SupportedPlugin.OnCall]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.OnCall]),
[SupportedPlugin.Incident]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Incident]),
};
expect(getIrmIfPresentOrIncidentPluginId()).toBe(SupportedPlugin.Incident);
});
});
describe('getIrmIfPresentOrOnCallPluginId', () => {
it('should return IRM plugin ID when IRM plugin is present', () => {
config.apps = { [SupportedPlugin.Irm]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Irm]) };
expect(getIrmIfPresentOrOnCallPluginId()).toBe(SupportedPlugin.Irm);
});
it('should return OnCall plugin ID when IRM plugin is not present', () => {
config.apps = {
[SupportedPlugin.OnCall]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.OnCall]),
[SupportedPlugin.Incident]: pluginMetaToPluginConfig(pluginMeta[SupportedPlugin.Incident]),
};
expect(getIrmIfPresentOrOnCallPluginId()).toBe(SupportedPlugin.OnCall);
});
});

View File

@@ -1,8 +1,6 @@
import { DataSourceInstanceSettings, DataSourceJsonData } from '@grafana/data';
import { config } from '@grafana/runtime';
import { SupportedPlugin } from '../types/pluginBridges';
import { isValidPrometheusDuration, safeParsePrometheusDuration } from './time';
export function getAllDataSources(): Array<DataSourceInstanceSettings<DataSourceJsonData>> {
@@ -28,15 +26,3 @@ export function checkEvaluationIntervalGlobalLimit(alertGroupEvaluateEvery?: str
return { globalLimit: evaluateEveryGlobalLimitMs, exceedsLimit };
}
export function getIsIrmPluginPresent() {
return SupportedPlugin.Irm in config.apps;
}
export function getIrmIfPresentOrIncidentPluginId() {
return getIsIrmPluginPresent() ? SupportedPlugin.Irm : SupportedPlugin.Incident;
}
export function getIrmIfPresentOrOnCallPluginId() {
return getIsIrmPluginPresent() ? SupportedPlugin.Irm : SupportedPlugin.OnCall;
}

View File

@@ -0,0 +1,429 @@
import { GrafanaManagedContactPoint } from 'app/plugins/datasource/alertmanager/types';
import { NotificationChannelOption, NotifierDTO, NotifierVersion } from '../types/alerting';
import {
canCreateNotifier,
getLegacyVersionLabel,
getOptionsForVersion,
hasLegacyIntegrations,
isLegacyVersion,
} from './notifier-versions';
// Helper to create a minimal NotifierDTO for testing
function createNotifier(overrides: Partial<NotifierDTO> = {}): NotifierDTO {
return {
name: 'Test Notifier',
description: 'Test description',
type: 'webhook',
heading: 'Test heading',
options: [
{
element: 'input',
inputType: 'text',
label: 'Default Option',
description: 'Default option description',
placeholder: '',
propertyName: 'defaultOption',
required: true,
secure: false,
showWhen: { field: '', is: '' },
validationRule: '',
dependsOn: '',
},
],
...overrides,
};
}
// Helper to create a NotifierVersion for testing
function createVersion(overrides: Partial<NotifierVersion> = {}): NotifierVersion {
return {
version: 'v1',
label: 'Test Version',
description: 'Test version description',
options: [
{
element: 'input',
inputType: 'text',
label: 'Version Option',
description: 'Version option description',
placeholder: '',
propertyName: 'versionOption',
required: true,
secure: false,
showWhen: { field: '', is: '' },
validationRule: '',
dependsOn: '',
},
],
...overrides,
};
}
describe('notifier-versions utilities', () => {
describe('canCreateNotifier', () => {
it('should return true if notifier has no versions array', () => {
const notifier = createNotifier({ versions: undefined });
expect(canCreateNotifier(notifier)).toBe(true);
});
it('should return true if notifier has empty versions array', () => {
const notifier = createNotifier({ versions: [] });
expect(canCreateNotifier(notifier)).toBe(true);
});
it('should return true if at least one version has canCreate: true', () => {
const notifier = createNotifier({
versions: [
createVersion({ version: 'v0mimir1', canCreate: false }),
createVersion({ version: 'v1', canCreate: true }),
],
});
expect(canCreateNotifier(notifier)).toBe(true);
});
it('should return true if at least one version has canCreate: undefined (defaults to true)', () => {
const notifier = createNotifier({
versions: [
createVersion({ version: 'v0mimir1', canCreate: false }),
createVersion({ version: 'v1', canCreate: undefined }),
],
});
expect(canCreateNotifier(notifier)).toBe(true);
});
it('should return false if all versions have canCreate: false', () => {
const notifier = createNotifier({
versions: [
createVersion({ version: 'v0mimir1', canCreate: false }),
createVersion({ version: 'v0mimir2', canCreate: false }),
],
});
expect(canCreateNotifier(notifier)).toBe(false);
});
it('should return false for notifiers like WeChat that only have legacy versions', () => {
const wechatNotifier = createNotifier({
name: 'WeChat',
type: 'wechat',
versions: [createVersion({ version: 'v0mimir1', canCreate: false })],
});
expect(canCreateNotifier(wechatNotifier)).toBe(false);
});
});
describe('isLegacyVersion', () => {
it('should return false if no version is specified', () => {
const notifier = createNotifier({
versions: [createVersion({ version: 'v0mimir1', canCreate: false })],
});
expect(isLegacyVersion(notifier, undefined)).toBe(false);
expect(isLegacyVersion(notifier, '')).toBe(false);
});
it('should return false if notifier has no versions array', () => {
const notifier = createNotifier({ versions: undefined });
expect(isLegacyVersion(notifier, 'v0mimir1')).toBe(false);
});
it('should return false if notifier has empty versions array', () => {
const notifier = createNotifier({ versions: [] });
expect(isLegacyVersion(notifier, 'v0mimir1')).toBe(false);
});
it('should return false if version is not found in versions array', () => {
const notifier = createNotifier({
versions: [createVersion({ version: 'v1', canCreate: true })],
});
expect(isLegacyVersion(notifier, 'v0mimir1')).toBe(false);
});
it('should return false if version has canCreate: true', () => {
const notifier = createNotifier({
versions: [createVersion({ version: 'v1', canCreate: true })],
});
expect(isLegacyVersion(notifier, 'v1')).toBe(false);
});
it('should return false if version has canCreate: undefined', () => {
const notifier = createNotifier({
versions: [createVersion({ version: 'v1', canCreate: undefined })],
});
expect(isLegacyVersion(notifier, 'v1')).toBe(false);
});
it('should return true if version has canCreate: false', () => {
const notifier = createNotifier({
versions: [
createVersion({ version: 'v0mimir1', canCreate: false }),
createVersion({ version: 'v1', canCreate: true }),
],
});
expect(isLegacyVersion(notifier, 'v0mimir1')).toBe(true);
});
it('should correctly identify legacy versions in a mixed notifier', () => {
const notifier = createNotifier({
versions: [
createVersion({ version: 'v0mimir1', canCreate: false }),
createVersion({ version: 'v0mimir2', canCreate: false }),
createVersion({ version: 'v1', canCreate: true }),
],
});
expect(isLegacyVersion(notifier, 'v0mimir1')).toBe(true);
expect(isLegacyVersion(notifier, 'v0mimir2')).toBe(true);
expect(isLegacyVersion(notifier, 'v1')).toBe(false);
});
});
describe('getOptionsForVersion', () => {
const defaultOptions: NotificationChannelOption[] = [
{
element: 'input',
inputType: 'text',
label: 'Default URL',
description: 'Default URL description',
placeholder: '',
propertyName: 'url',
required: true,
secure: false,
showWhen: { field: '', is: '' },
validationRule: '',
dependsOn: '',
},
];
const v0Options: NotificationChannelOption[] = [
{
element: 'input',
inputType: 'text',
label: 'Legacy URL',
description: 'Legacy URL description',
placeholder: '',
propertyName: 'legacyUrl',
required: true,
secure: false,
showWhen: { field: '', is: '' },
validationRule: '',
dependsOn: '',
},
];
const v1Options: NotificationChannelOption[] = [
{
element: 'input',
inputType: 'text',
label: 'Modern URL',
description: 'Modern URL description',
placeholder: '',
propertyName: 'modernUrl',
required: true,
secure: false,
showWhen: { field: '', is: '' },
validationRule: '',
dependsOn: '',
},
];
it('should return options from default creatable version if no version is specified', () => {
const notifier = createNotifier({
options: defaultOptions,
versions: [createVersion({ version: 'v1', options: v1Options, canCreate: true })],
});
// When no version specified, should use options from the default creatable version
expect(getOptionsForVersion(notifier, undefined)).toBe(v1Options);
});
it('should return default options if no version is specified and empty string is passed', () => {
const notifier = createNotifier({
options: defaultOptions,
versions: [createVersion({ version: 'v1', options: v1Options, canCreate: true })],
});
// Empty string is still a falsy version, so should use default creatable version
expect(getOptionsForVersion(notifier, '')).toBe(v1Options);
});
it('should return default options if notifier has no versions array', () => {
const notifier = createNotifier({
options: defaultOptions,
versions: undefined,
});
expect(getOptionsForVersion(notifier, 'v1')).toBe(defaultOptions);
});
it('should return default options if notifier has empty versions array', () => {
const notifier = createNotifier({
options: defaultOptions,
versions: [],
});
expect(getOptionsForVersion(notifier, 'v1')).toBe(defaultOptions);
});
it('should return default options if version is not found', () => {
const notifier = createNotifier({
options: defaultOptions,
versions: [createVersion({ version: 'v1', options: v1Options })],
});
expect(getOptionsForVersion(notifier, 'v0mimir1')).toBe(defaultOptions);
});
it('should return version-specific options when version is found', () => {
const notifier = createNotifier({
options: defaultOptions,
versions: [
createVersion({ version: 'v0mimir1', options: v0Options }),
createVersion({ version: 'v1', options: v1Options }),
],
});
expect(getOptionsForVersion(notifier, 'v0mimir1')).toBe(v0Options);
expect(getOptionsForVersion(notifier, 'v1')).toBe(v1Options);
});
it('should return default options if version found but has no options', () => {
const notifier = createNotifier({
options: defaultOptions,
versions: [
{
version: 'v1',
label: 'V1',
description: 'V1 description',
options: undefined as unknown as NotificationChannelOption[],
},
],
});
expect(getOptionsForVersion(notifier, 'v1')).toBe(defaultOptions);
});
});
describe('hasLegacyIntegrations', () => {
// Helper to create a minimal contact point for testing
function createContactPoint(overrides: Partial<GrafanaManagedContactPoint> = {}): GrafanaManagedContactPoint {
return {
name: 'Test Contact Point',
...overrides,
};
}
// Create notifiers with version info for testing
const notifiersWithVersions: NotifierDTO[] = [
createNotifier({
type: 'slack',
versions: [
createVersion({ version: 'v0mimir1', canCreate: false }),
createVersion({ version: 'v1', canCreate: true }),
],
}),
createNotifier({
type: 'webhook',
versions: [
createVersion({ version: 'v0mimir1', canCreate: false }),
createVersion({ version: 'v0mimir2', canCreate: false }),
createVersion({ version: 'v1', canCreate: true }),
],
}),
];
it('should return false if contact point is undefined', () => {
expect(hasLegacyIntegrations(undefined, notifiersWithVersions)).toBe(false);
});
it('should return false if notifiers is undefined', () => {
const contactPoint = createContactPoint({
grafana_managed_receiver_configs: [{ type: 'slack', settings: {}, version: 'v0mimir1' }],
});
expect(hasLegacyIntegrations(contactPoint, undefined)).toBe(false);
});
it('should return false if contact point has no integrations', () => {
const contactPoint = createContactPoint({ grafana_managed_receiver_configs: undefined });
expect(hasLegacyIntegrations(contactPoint, notifiersWithVersions)).toBe(false);
});
it('should return false if contact point has empty integrations array', () => {
const contactPoint = createContactPoint({ grafana_managed_receiver_configs: [] });
expect(hasLegacyIntegrations(contactPoint, notifiersWithVersions)).toBe(false);
});
it('should return false if all integrations have v1 version (canCreate: true)', () => {
const contactPoint = createContactPoint({
grafana_managed_receiver_configs: [
{ type: 'slack', settings: {}, version: 'v1' },
{ type: 'webhook', settings: {}, version: 'v1' },
],
});
expect(hasLegacyIntegrations(contactPoint, notifiersWithVersions)).toBe(false);
});
it('should return false if all integrations have no version', () => {
const contactPoint = createContactPoint({
grafana_managed_receiver_configs: [
{ type: 'slack', settings: {} },
{ type: 'webhook', settings: {} },
],
});
expect(hasLegacyIntegrations(contactPoint, notifiersWithVersions)).toBe(false);
});
it('should return true if any integration has a legacy version (canCreate: false)', () => {
const contactPoint = createContactPoint({
grafana_managed_receiver_configs: [
{ type: 'slack', settings: {}, version: 'v0mimir1' },
{ type: 'webhook', settings: {}, version: 'v1' },
],
});
expect(hasLegacyIntegrations(contactPoint, notifiersWithVersions)).toBe(true);
});
it('should return true if all integrations have legacy versions', () => {
const contactPoint = createContactPoint({
grafana_managed_receiver_configs: [
{ type: 'slack', settings: {}, version: 'v0mimir1' },
{ type: 'webhook', settings: {}, version: 'v0mimir2' },
],
});
expect(hasLegacyIntegrations(contactPoint, notifiersWithVersions)).toBe(true);
});
it('should return false if notifier type is not found in notifiers array', () => {
const contactPoint = createContactPoint({
grafana_managed_receiver_configs: [{ type: 'unknown', settings: {}, version: 'v0mimir1' }],
});
expect(hasLegacyIntegrations(contactPoint, notifiersWithVersions)).toBe(false);
});
});
describe('getLegacyVersionLabel', () => {
it('should return "Legacy" for undefined version', () => {
expect(getLegacyVersionLabel(undefined)).toBe('Legacy');
});
it('should return "Legacy" for empty string version', () => {
expect(getLegacyVersionLabel('')).toBe('Legacy');
});
it('should return "Legacy" for v0mimir1', () => {
expect(getLegacyVersionLabel('v0mimir1')).toBe('Legacy');
});
it('should return "Legacy v2" for v0mimir2', () => {
expect(getLegacyVersionLabel('v0mimir2')).toBe('Legacy v2');
});
it('should return "Legacy v3" for v0mimir3', () => {
expect(getLegacyVersionLabel('v0mimir3')).toBe('Legacy v3');
});
it('should return "Legacy" for v1 (trailing 1)', () => {
expect(getLegacyVersionLabel('v1')).toBe('Legacy');
});
it('should return "Legacy v2" for v2 (trailing 2)', () => {
expect(getLegacyVersionLabel('v2')).toBe('Legacy v2');
});
it('should return "Legacy" for version strings without trailing number', () => {
expect(getLegacyVersionLabel('legacy')).toBe('Legacy');
});
});
});

View File

@@ -0,0 +1,126 @@
/**
* Utilities for integration versioning
*
* These utilities help get version-specific options from the backend response
* (via /api/alert-notifiers?version=2)
*/
import { GrafanaManagedContactPoint } from 'app/plugins/datasource/alertmanager/types';
import { NotificationChannelOption, NotifierDTO } from '../types/alerting';
/**
* Checks if a notifier can be used to create new integrations.
* A notifier can be created if it has at least one version with canCreate: true,
* or if it has no versions array (legacy behavior).
*
* @param notifier - The notifier DTO to check
* @returns True if the notifier can be used to create new integrations
*/
export function canCreateNotifier(notifier: NotifierDTO): boolean {
// If no versions array, assume it can be created (legacy behavior)
if (!notifier.versions || notifier.versions.length === 0) {
return true;
}
// Check if any version has canCreate: true (or undefined, which defaults to true)
return notifier.versions.some((v) => v.canCreate !== false);
}
/**
* Checks if a specific version is legacy (cannot be created).
* A version is legacy if it has canCreate: false in the notifier's versions array.
*
* @param notifier - The notifier DTO containing versions array
* @param version - The version string to check (e.g., 'v0mimir1', 'v1')
* @returns True if the version is legacy (canCreate: false)
*/
export function isLegacyVersion(notifier: NotifierDTO, version?: string): boolean {
// If no version specified or no versions array, it's not legacy
if (!version || !notifier.versions || notifier.versions.length === 0) {
return false;
}
// Find the matching version and check its canCreate property
const versionData = notifier.versions.find((v) => v.version === version);
// A version is legacy if canCreate is explicitly false
return versionData?.canCreate === false;
}
/**
* Gets the options for a specific version of a notifier.
* Used to display the correct form fields based on integration version.
*
* @param notifier - The notifier DTO containing versions array
* @param version - The version to get options for (e.g., 'v0', 'v1')
* @returns The options for the specified version, or default options if version not found
*/
export function getOptionsForVersion(notifier: NotifierDTO, version?: string): NotificationChannelOption[] {
// If no versions array, use default options
if (!notifier.versions || notifier.versions.length === 0) {
return notifier.options;
}
// If version is specified, find the matching version
if (version) {
const versionData = notifier.versions.find((v) => v.version === version);
// Return version-specific options if found, otherwise fall back to default
return versionData?.options ?? notifier.options;
}
// If no version specified, find the default creatable version (canCreate !== false)
const defaultVersion = notifier.versions.find((v) => v.canCreate !== false);
return defaultVersion?.options ?? notifier.options;
}
/**
* Checks if a contact point has any legacy (imported) integrations.
* A contact point has legacy integrations if any of its integrations uses a version
* with canCreate: false in the corresponding notifier's versions array.
*
* @param contactPoint - The contact point to check
* @param notifiers - Array of notifier DTOs to look up version info
* @returns True if the contact point has at least one legacy/imported integration
*/
export function hasLegacyIntegrations(contactPoint?: GrafanaManagedContactPoint, notifiers?: NotifierDTO[]): boolean {
if (!contactPoint?.grafana_managed_receiver_configs || !notifiers) {
return false;
}
return contactPoint.grafana_managed_receiver_configs.some((config) => {
const notifier = notifiers.find((n) => n.type === config.type);
return notifier ? isLegacyVersion(notifier, config.version) : false;
});
}
/**
* Gets a user-friendly label for a legacy version.
* Extracts the version number from the version string and formats it as:
* - "Legacy" for version 1 (e.g., v0mimir1)
* - "Legacy v2" for version 2 (e.g., v0mimir2)
* - etc.
*
* Precondition: This function assumes the version is already known to be legacy
* (i.e., canCreate: false). Use isLegacyVersion() to check before calling this.
*
* @param version - The version string (e.g., 'v0mimir1', 'v0mimir2')
* @returns A user-friendly label like "Legacy" or "Legacy v2"
*/
export function getLegacyVersionLabel(version?: string): string {
if (!version) {
return 'Legacy';
}
// Extract trailing number from version string (e.g., v0mimir1 → 1, v0mimir2 → 2)
const match = version.match(/(\d+)$/);
if (match) {
const num = parseInt(match[1], 10);
if (num === 1) {
return 'Legacy';
}
return `Legacy v${num}`;
}
return 'Legacy';
}

View File

@@ -185,6 +185,7 @@ function grafanaChannelConfigToFormChannelValues(
const values: GrafanaChannelValues = {
__id: id,
type: channel.type as NotifierType,
version: channel.version,
provenance: channel.provenance,
settings: { ...channel.settings },
secureFields: { ...channel.secureFields },
@@ -239,6 +240,7 @@ export function formChannelValuesToGrafanaChannelConfig(
}),
secureFields: secureFieldsFromValues,
type: values.type,
version: values.version ?? existing?.version,
name,
disableResolveMessage:
values.disableResolveMessage ?? existing?.disableResolveMessage ?? defaults.disableResolveMessage,

View File

@@ -1,6 +1,6 @@
import { incidentsApi } from 'app/features/alerting/unified/api/incidentsApi';
import { usePluginBridge } from 'app/features/alerting/unified/hooks/usePluginBridge';
import { getIrmIfPresentOrIncidentPluginId } from 'app/features/alerting/unified/utils/config';
import { useIrmPlugin } from 'app/features/alerting/unified/hooks/usePluginBridge';
import { SupportedPlugin } from 'app/features/alerting/unified/types/pluginBridges';
interface IncidentsPluginConfig {
isInstalled: boolean;
@@ -10,11 +10,13 @@ interface IncidentsPluginConfig {
}
export function useGetIncidentPluginConfig(): IncidentsPluginConfig {
const { installed: incidentPluginInstalled, loading: loadingPluginSettings } = usePluginBridge(
getIrmIfPresentOrIncidentPluginId()
);
const {
pluginId,
installed: incidentPluginInstalled,
loading: loadingPluginSettings,
} = useIrmPlugin(SupportedPlugin.Incident);
const { data: incidentsConfig, isLoading: loadingPluginConfig } =
incidentsApi.endpoints.getIncidentsPluginConfig.useQuery();
incidentsApi.endpoints.getIncidentsPluginConfig.useQuery({ pluginId });
return {
isInstalled: incidentPluginInstalled ?? false,

View File

@@ -1,26 +1,34 @@
import { onCallApi } from 'app/features/alerting/unified/api/onCallApi';
import { usePluginBridge } from 'app/features/alerting/unified/hooks/usePluginBridge';
import { getIrmIfPresentOrOnCallPluginId } from 'app/features/alerting/unified/utils/config';
import { useIrmPlugin } from 'app/features/alerting/unified/hooks/usePluginBridge';
import { SupportedPlugin } from 'app/features/alerting/unified/types/pluginBridges';
export function useGetOnCallIntegrations() {
const { installed: onCallPluginInstalled } = usePluginBridge(getIrmIfPresentOrOnCallPluginId());
const { pluginId, installed: onCallPluginInstalled } = useIrmPlugin(SupportedPlugin.OnCall);
const { data: onCallIntegrations } = onCallApi.endpoints.grafanaOnCallIntegrations.useQuery(undefined, {
skip: !onCallPluginInstalled,
refetchOnFocus: true,
refetchOnReconnect: true,
refetchOnMountOrArgChange: true,
});
const { data: onCallIntegrations } = onCallApi.endpoints.grafanaOnCallIntegrations.useQuery(
{ pluginId },
{
skip: !onCallPluginInstalled,
refetchOnFocus: true,
refetchOnReconnect: true,
refetchOnMountOrArgChange: true,
}
);
return onCallIntegrations ?? [];
}
function useGetOnCallConfigurationChecks() {
const { data: onCallConfigChecks, isLoading } = onCallApi.endpoints.onCallConfigChecks.useQuery(undefined, {
refetchOnFocus: true,
refetchOnReconnect: true,
refetchOnMountOrArgChange: true,
});
const { pluginId } = useIrmPlugin(SupportedPlugin.OnCall);
const { data: onCallConfigChecks, isLoading } = onCallApi.endpoints.onCallConfigChecks.useQuery(
{ pluginId },
{
refetchOnFocus: true,
refetchOnReconnect: true,
refetchOnMountOrArgChange: true,
}
);
return {
isLoading,

View File

@@ -2,7 +2,7 @@ import { FeatureToggles } from '@grafana/data';
import { config } from '@grafana/runtime';
import { RepositoryViewList } from 'app/api/clients/provisioning/v0alpha1';
export const requiredFeatureToggles: Array<keyof FeatureToggles> = ['provisioning', 'kubernetesDashboards'];
export const requiredFeatureToggles: Array<keyof FeatureToggles> = ['kubernetesDashboards'];
/**
* Checks if all required feature toggles are enabled

View File

@@ -1,3 +1,4 @@
import { config } from '@grafana/runtime';
import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
import { RouteDescriptor } from 'app/core/navigation/types';
import { DashboardRoutes } from 'app/types/dashboard';
@@ -6,6 +7,11 @@ import { checkRequiredFeatures } from '../GettingStarted/features';
import { CONNECTIONS_URL, CONNECT_URL, GETTING_STARTED_URL, PROVISIONING_URL } from '../constants';
export function getProvisioningRoutes(): RouteDescriptor[] {
const featureToggles = config.featureToggles || {};
if (!featureToggles.provisioning) {
return [];
}
if (!checkRequiredFeatures()) {
return [
{

View File

@@ -85,6 +85,10 @@ export type GrafanaManagedReceiverConfig = {
// SecureSettings?: GrafanaManagedReceiverConfigSettings<boolean>;
settings: GrafanaManagedReceiverConfigSettings;
type: string;
/**
* Version of the integration (e.g. "v0" for Mimir legacy, "v1" for Grafana)
*/
version?: string;
/**
* Name of the _receiver_, which in most cases will be the
* same as the contact point's name. This should not be used, and is optional because the

View File

@@ -807,7 +807,8 @@
"label-integration": "Integration",
"label-notification-settings": "Notification settings",
"label-section": "Optional {{name}} settings",
"test": "Test"
"test": "Test",
"tooltip-legacy-version": "This is a legacy integration (version: {{version}}). It cannot be modified."
},
"classic-condition-viewer": {
"of": "OF",
@@ -2176,7 +2177,9 @@
"provisioning": {
"badge-tooltip-provenance": "This resource has been provisioned via {{provenance}} and cannot be edited through the UI",
"badge-tooltip-standard": "This resource has been provisioned and cannot be edited through the UI",
"body-imported": "This contact point contains integrations that were imported from an external Alertmanager and is currently read-only. The integrations will become editable after the migration process is complete.",
"body-provisioned": "This {{resource}} has been provisioned, that means it was created by config. Please contact your server admin to update this {{resource}}.",
"title-imported": "This contact point was imported and cannot be edited through the UI",
"title-provisioned": "This {{resource}} cannot be edited through the UI"
},
"provisioning-badge": {