CMS: Create local implementation of cloud migration for dev use (#86637)
* add developer mode property to config * create cms stub * cleanup * implement and wire up gcom stub * fix errors * don't document the flag
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package cmsclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
type Client interface {
|
||||
ValidateKey(context.Context, cloudmigration.CloudMigration) error
|
||||
MigrateData(context.Context, cloudmigration.CloudMigration, cloudmigration.MigrateDataRequestDTO) (*cloudmigration.MigrateDataResponseDTO, error)
|
||||
}
|
||||
|
||||
const logPrefix = "cloudmigration.cmsclient"
|
||||
|
||||
var ErrMigrationNotDeleted = errutil.Internal("cloudmigrations.developerModeEnabled", errutil.WithPublicMessage("Developer mode enabled"))
|
||||
+5
-11
@@ -11,26 +11,20 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||
)
|
||||
|
||||
type Client interface {
|
||||
ValidateKey(context.Context, cloudmigration.CloudMigration) error
|
||||
MigrateData(context.Context, cloudmigration.CloudMigration, cloudmigration.MigrateDataRequestDTO) (*cloudmigration.MigrateDataResponseDTO, error)
|
||||
}
|
||||
|
||||
const logPrefix = "cloudmigration.cmsclient"
|
||||
|
||||
// NewCMSClient returns an implementation of Client that queries CloudMigrationService
|
||||
func NewCMSClient(domain string) Client {
|
||||
return &clientImpl{
|
||||
return &cmsClientImpl{
|
||||
domain: domain,
|
||||
log: log.New(logPrefix),
|
||||
}
|
||||
}
|
||||
|
||||
type clientImpl struct {
|
||||
type cmsClientImpl struct {
|
||||
domain string
|
||||
log *log.ConcreteLogger
|
||||
}
|
||||
|
||||
func (c *clientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigration) error {
|
||||
func (c *cmsClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigration) error {
|
||||
logger := c.log.FromContext(ctx)
|
||||
|
||||
path := fmt.Sprintf("https://cms-%s.%s/cloud-migrations/api/v1/validate-key", cm.ClusterSlug, c.domain)
|
||||
@@ -69,7 +63,7 @@ func (c *clientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMig
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *clientImpl) MigrateData(ctx context.Context, cm cloudmigration.CloudMigration, request cloudmigration.MigrateDataRequestDTO) (*cloudmigration.MigrateDataResponseDTO, error) {
|
||||
func (c *cmsClientImpl) MigrateData(ctx context.Context, cm cloudmigration.CloudMigration, request cloudmigration.MigrateDataRequestDTO) (*cloudmigration.MigrateDataResponseDTO, error) {
|
||||
logger := c.log.FromContext(ctx)
|
||||
|
||||
path := fmt.Sprintf("https://cms-%s.%s/cloud-migrations/api/v1/migrate-data", cm.ClusterSlug, c.domain)
|
||||
@@ -0,0 +1,48 @@
|
||||
package cmsclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||
)
|
||||
|
||||
// NewInMemoryClient returns an implementation of Client that returns canned responses
|
||||
func NewInMemoryClient() Client {
|
||||
return &memoryClientImpl{}
|
||||
}
|
||||
|
||||
type memoryClientImpl struct{}
|
||||
|
||||
func (c *memoryClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigration) error {
|
||||
// return ErrMigrationNotDeleted
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *memoryClientImpl) MigrateData(
|
||||
ctx context.Context,
|
||||
cm cloudmigration.CloudMigration,
|
||||
request cloudmigration.MigrateDataRequestDTO,
|
||||
) (*cloudmigration.MigrateDataResponseDTO, error) {
|
||||
//return nil, ErrMigrationNotDeleted
|
||||
|
||||
result := cloudmigration.MigrateDataResponseDTO{
|
||||
Items: make([]cloudmigration.MigrateDataResponseItemDTO, len(request.Items)),
|
||||
}
|
||||
|
||||
for i, v := range request.Items {
|
||||
result.Items[i] = cloudmigration.MigrateDataResponseItemDTO{
|
||||
Type: v.Type,
|
||||
RefID: v.RefID,
|
||||
Status: cloudmigration.ItemStatusOK,
|
||||
}
|
||||
}
|
||||
|
||||
// simulate flakiness on one random item
|
||||
i := rand.Intn(len(result.Items))
|
||||
failedItem := result.Items[i]
|
||||
failedItem.Status, failedItem.Error = cloudmigration.ItemStatusError, "simulated random error"
|
||||
result.Items[i] = failedItem
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user