From e55b438f14df1751c58a760dde8d86b4eaa8a6f5 Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Fri, 2 Aug 2024 10:46:41 +0100 Subject: [PATCH] E2C: Reduce UI poll interval and make configurable (#91386) * E2C: Reduce UI poll interval and make configurable * fix default --- conf/defaults.ini | 2 ++ conf/sample.ini | 2 ++ packages/grafana-runtime/src/config.ts | 1 + pkg/api/dtos/frontend_settings.go | 5 +++-- pkg/api/frontendsettings.go | 1 + pkg/setting/setting_cloud_migration.go | 2 ++ public/app/features/migrate-to-cloud/onprem/Page.tsx | 5 ++--- 7 files changed, 13 insertions(+), 5 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 70053cf6526..33cc2bdc9cd 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1969,4 +1969,6 @@ domain = grafana.net snapshot_folder = "" # Link to form to give feedback on the feature feedback_url = https://docs.google.com/forms/d/e/1FAIpQLSeEE33vhbSpR8A8S1A1ocZ1ByVRRwiRl1GZr2FSrEer_tSa8w/viewform?usp=sf_link +# How frequently should the frontend UI poll for changes while resources are migrating +frontend_poll_interval = 2s diff --git a/conf/sample.ini b/conf/sample.ini index a23a17e1b14..780a2031fbc 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -1900,3 +1900,5 @@ timeout = 30s ;snapshot_folder = "" # Link to form to give feedback on the feature ;feedback_url = "" +# How frequently should the frontend UI poll for changes while resources are migrating +;frontend_poll_interval = 2s diff --git a/packages/grafana-runtime/src/config.ts b/packages/grafana-runtime/src/config.ts index 868a3d8a8fb..b2bc145eacf 100644 --- a/packages/grafana-runtime/src/config.ts +++ b/packages/grafana-runtime/src/config.ts @@ -182,6 +182,7 @@ export class GrafanaBootConfig implements GrafanaConfig { localFileSystemAvailable: boolean | undefined; cloudMigrationIsTarget: boolean | undefined; cloudMigrationFeedbackURL = ''; + cloudMigrationPollIntervalMs = 2000; reportingStaticContext?: Record; exploreDefaultTimeOffset = '1h'; diff --git a/pkg/api/dtos/frontend_settings.go b/pkg/api/dtos/frontend_settings.go index a07a5e4358c..92ce60699b6 100644 --- a/pkg/api/dtos/frontend_settings.go +++ b/pkg/api/dtos/frontend_settings.go @@ -257,8 +257,9 @@ type FrontendSettingsDTO struct { PublicDashboardAccessToken string `json:"publicDashboardAccessToken"` PublicDashboardsEnabled bool `json:"publicDashboardsEnabled"` - CloudMigrationIsTarget bool `json:"cloudMigrationIsTarget"` - CloudMigrationFeedbackURL string `json:"cloudMigrationFeedbackURL"` + CloudMigrationIsTarget bool `json:"cloudMigrationIsTarget"` + CloudMigrationFeedbackURL string `json:"cloudMigrationFeedbackURL"` + CloudMigrationPollIntervalMs int `json:"cloudMigrationPollIntervalMs"` DateFormats setting.DateFormats `json:"dateFormats,omitempty"` diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index 90b3e5317e1..148f916c4ac 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -224,6 +224,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro PublicDashboardsEnabled: hs.Cfg.PublicDashboardsEnabled, CloudMigrationIsTarget: isCloudMigrationTarget, CloudMigrationFeedbackURL: hs.Cfg.CloudMigration.FeedbackURL, + CloudMigrationPollIntervalMs: int(hs.Cfg.CloudMigration.FrontendPollInterval.Milliseconds()), SharedWithMeFolderUID: folder.SharedWithMeFolderUID, RootFolderUID: accesscontrol.GeneralFolderUID, LocalFileSystemAvailable: hs.Cfg.LocalFileSystemAvailable, diff --git a/pkg/setting/setting_cloud_migration.go b/pkg/setting/setting_cloud_migration.go index 1efc88089dd..e05eb3b7f42 100644 --- a/pkg/setting/setting_cloud_migration.go +++ b/pkg/setting/setting_cloud_migration.go @@ -24,6 +24,7 @@ type CloudMigrationSettings struct { DeleteTokenTimeout time.Duration TokenExpiresAfter time.Duration FeedbackURL string + FrontendPollInterval time.Duration IsDeveloperMode bool } @@ -49,6 +50,7 @@ func (cfg *Cfg) readCloudMigrationSettings() { cfg.CloudMigration.TokenExpiresAfter = cloudMigration.Key("token_expires_after").MustDuration(7 * 24 * time.Hour) cfg.CloudMigration.IsDeveloperMode = cloudMigration.Key("developer_mode").MustBool(false) cfg.CloudMigration.FeedbackURL = cloudMigration.Key("feedback_url").MustString("") + cfg.CloudMigration.FrontendPollInterval = cloudMigration.Key("frontend_poll_interval").MustDuration(2 * time.Second) if cfg.CloudMigration.SnapshotFolder == "" { cfg.CloudMigration.SnapshotFolder = filepath.Join(cfg.DataPath, "cloud_migration") diff --git a/public/app/features/migrate-to-cloud/onprem/Page.tsx b/public/app/features/migrate-to-cloud/onprem/Page.tsx index 4da9ea67aa7..213a9ef6449 100644 --- a/public/app/features/migrate-to-cloud/onprem/Page.tsx +++ b/public/app/features/migrate-to-cloud/onprem/Page.tsx @@ -1,6 +1,7 @@ import { skipToken } from '@reduxjs/toolkit/query/react'; import { useCallback, useEffect, useState } from 'react'; +import { config } from '@grafana/runtime'; import { AlertVariant, Box, Stack, Text } from '@grafana/ui'; import { Trans, t } from 'app/core/internationalization'; @@ -62,8 +63,6 @@ const SNAPSHOT_REBUILD_STATUSES: Array = ['PENDING_UPLOAD const SNAPSHOT_BUILDING_STATUSES: Array = ['INITIALIZING', 'CREATING']; const SNAPSHOT_UPLOADING_STATUSES: Array = ['UPLOADING', 'PENDING_PROCESSING', 'PROCESSING']; -const STATUS_POLL_INTERVAL = 5 * 1000; - const PAGE_SIZE = 50; function useGetLatestSnapshot(sessionUid?: string, page = 1) { @@ -78,7 +77,7 @@ function useGetLatestSnapshot(sessionUid?: string, page = 1) { : skipToken; const snapshotResult = useGetSnapshotQuery(getSnapshotQueryArgs, { - pollingInterval: shouldPoll ? STATUS_POLL_INTERVAL : 0, + pollingInterval: shouldPoll ? config.cloudMigrationPollIntervalMs : 0, skipPollingIfUnfocused: true, });