mirror of
https://github.com/grafana/grafana.git
synced 2024-11-21 16:38:03 -06:00
Explore: Add setting for default time offset (#90401)
* Add setting for explore for a different time offset * fix linter * Add validation for duration value
This commit is contained in:
parent
1fc57d8fd5
commit
6eb695b258
@ -1497,6 +1497,9 @@ max_annotations_to_keep =
|
||||
# Enable the Explore section
|
||||
enabled = true
|
||||
|
||||
# set the default offset for the time picker
|
||||
defaultTimeOffset = 1h
|
||||
|
||||
#################################### Help #############################
|
||||
[help]
|
||||
# Enable the Help section
|
||||
|
@ -1783,6 +1783,11 @@ For more information about this feature, refer to [Explore]({{< relref "../../ex
|
||||
|
||||
Enable or disable the Explore section. Default is `enabled`.
|
||||
|
||||
### defaultTimeOffset
|
||||
|
||||
Set a default time offset from now on the time picker. Default is 1 hour.
|
||||
This setting should be expressed as a duration. Examples: 1h (hour), 1d (day), 1w (week), 1M (month).
|
||||
|
||||
## [help]
|
||||
|
||||
Configures the help section.
|
||||
|
@ -233,6 +233,7 @@ export interface GrafanaConfig {
|
||||
listDashboardScopesEndpoint?: string;
|
||||
listScopesEndpoint?: string;
|
||||
reportingStaticContext?: Record<string, string>;
|
||||
exploreDefaultTimeOffset?: string;
|
||||
|
||||
// The namespace to use for kubernetes apiserver requests
|
||||
namespace: string;
|
||||
|
@ -180,6 +180,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
||||
localFileSystemAvailable: boolean | undefined;
|
||||
cloudMigrationIsTarget: boolean | undefined;
|
||||
reportingStaticContext?: Record<string, string>;
|
||||
exploreDefaultTimeOffset = '1h';
|
||||
|
||||
/**
|
||||
* Language used in Grafana's UI. This is after the user's preference (or deteceted locale) is resolved to one of
|
||||
|
@ -204,6 +204,7 @@ type FrontendSettingsDTO struct {
|
||||
TrustedTypesDefaultPolicyEnabled bool `json:"trustedTypesDefaultPolicyEnabled"`
|
||||
CSPReportOnlyEnabled bool `json:"cspReportOnlyEnabled"`
|
||||
DisableFrontendSandboxForPlugins []string `json:"disableFrontendSandboxForPlugins"`
|
||||
ExploreDefaultTimeOffset string `json:"exploreDefaultTimeOffset"`
|
||||
|
||||
Auth FrontendSettingsAuthDTO `json:"auth"`
|
||||
|
||||
|
@ -227,6 +227,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
RootFolderUID: accesscontrol.GeneralFolderUID,
|
||||
LocalFileSystemAvailable: hs.Cfg.LocalFileSystemAvailable,
|
||||
ReportingStaticContext: hs.Cfg.ReportingStaticContext,
|
||||
ExploreDefaultTimeOffset: hs.Cfg.ExploreDefaultTimeOffset,
|
||||
|
||||
BuildInfo: dtos.FrontendSettingsBuildInfoDTO{
|
||||
HideVersion: hideVersion,
|
||||
|
@ -513,7 +513,8 @@ type Cfg struct {
|
||||
AlertingMinInterval int64
|
||||
|
||||
// Explore UI
|
||||
ExploreEnabled bool
|
||||
ExploreEnabled bool
|
||||
ExploreDefaultTimeOffset string
|
||||
|
||||
// Help UI
|
||||
HelpEnabled bool
|
||||
@ -1173,6 +1174,14 @@ func (cfg *Cfg) parseINIFile(iniFile *ini.File) error {
|
||||
explore := iniFile.Section("explore")
|
||||
cfg.ExploreEnabled = explore.Key("enabled").MustBool(true)
|
||||
|
||||
exploreDefaultTimeOffset := valueAsString(explore, "defaultTimeOffset", "1h")
|
||||
// we want to ensure the value parses as a duration, but we send it forward as a string to the frontend
|
||||
if _, err := gtime.ParseDuration(exploreDefaultTimeOffset); err != nil {
|
||||
return err
|
||||
} else {
|
||||
cfg.ExploreDefaultTimeOffset = exploreDefaultTimeOffset
|
||||
}
|
||||
|
||||
help := iniFile.Section("help")
|
||||
cfg.HelpEnabled = help.Key("enabled").MustBool(true)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import {
|
||||
URLRange,
|
||||
URLRangeValue,
|
||||
} from '@grafana/data';
|
||||
import { getDataSourceSrv } from '@grafana/runtime';
|
||||
import { config, getDataSourceSrv } from '@grafana/runtime';
|
||||
import { DataQuery, DataSourceJsonData, DataSourceRef, TimeZone } from '@grafana/schema';
|
||||
import { getLocalRichHistoryStorage } from 'app/core/history/richHistoryStorageProvider';
|
||||
import { SortOrder } from 'app/core/utils/richHistory';
|
||||
@ -36,7 +36,7 @@ import { loadSupplementaryQueries } from '../utils/supplementaryQueries';
|
||||
export const MAX_HISTORY_AUTOCOMPLETE_ITEMS = 100;
|
||||
|
||||
export const DEFAULT_RANGE = {
|
||||
from: 'now-1h',
|
||||
from: `now-${config.exploreDefaultTimeOffset}`,
|
||||
to: 'now',
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user