diff --git a/console/config.go b/console/config.go index cd0686f1..f98d0ed9 100644 --- a/console/config.go +++ b/console/config.go @@ -15,13 +15,37 @@ type Configuration struct { ServeLiveFS bool `yaml:"-"` // Version is the version to display to the user. Version string `yaml:"-"` + // DefaultVisualizeOptions define some defaults for the "visualize" tab. + DefaultVisualizeOptions VisualizeOptionsConfiguration +} + +// VisualizeOptionsConfiguration defines options for the "visualize" tab. +type VisualizeOptionsConfiguration struct { + // Start is the start time (as a string) + Start string `json:"start"` + // End is the end time (as string) + End string `json:"end"` + // Filter is the the filter string + Filter string `json:"filter"` + // Dimensions is the array of dimensions to use + Dimensions []queryColumn `json:"dimensions"` } // DefaultConfiguration represents the default configuration for the console component. func DefaultConfiguration() Configuration { - return Configuration{} + return Configuration{ + DefaultVisualizeOptions: VisualizeOptionsConfiguration{ + Start: "6 hours ago", + End: "now", + Filter: "InIfBoundary = external", + Dimensions: []queryColumn{queryColumnSrcAS}, + }, + } } func (c *Component) configHandlerFunc(gc *gin.Context) { - gc.JSON(http.StatusOK, gin.H{"version": c.config.Version}) + gc.JSON(http.StatusOK, gin.H{ + "version": c.config.Version, + "defaultVisualizeOptions": c.config.DefaultVisualizeOptions, + }) } diff --git a/console/config_test.go b/console/config_test.go index b16ec236..dccb28d8 100644 --- a/console/config_test.go +++ b/console/config_test.go @@ -20,6 +20,12 @@ func TestConfigHandler(t *testing.T) { URL: "/api/v0/console/configuration", JSONOutput: gin.H{ "version": "1.2.3", + "defaultVisualizeOptions": gin.H{ + "start": "6 hours ago", + "end": "now", + "filter": "InIfBoundary = external", + "dimensions": []string{"SrcAS"}, + }, }, }, }) diff --git a/console/data/docs/02-configuration.md b/console/data/docs/02-configuration.md index f781fafc..afe6b8ca 100644 --- a/console/data/docs/02-configuration.md +++ b/console/data/docs/02-configuration.md @@ -376,6 +376,19 @@ The main components of the console service are `http`, `console`, `authentication` and `database`. `http` accepts the [same configuration](#http) as for the inlet service. +The console itself accepts the `default-visualize-options` key. Here +is an example: + +```yaml +console: + default-visualize-options: + start: 1 day ago + end: now + filter: InIfBoundary = external + dimensions: + - ExporterName +``` + ### Authentication The console does not store user identities and is unable to diff --git a/console/data/docs/99-changelog.md b/console/data/docs/99-changelog.md index 2a3dfd71..34370bc4 100644 --- a/console/data/docs/99-changelog.md +++ b/console/data/docs/99-changelog.md @@ -11,6 +11,10 @@ identified with a specific icon: - 🩹: bug fix - 🌱: miscellaneous change +## Unreleased + +- 🌱 *console*: add configuration for default options of the visualize tab + ## 1.5.0 - 2022-07-20 This release introduce a new protobuf schema. When using diff --git a/console/frontend/src/views/VisualizePage/OptionsPanel.vue b/console/frontend/src/views/VisualizePage/OptionsPanel.vue index e5f6faad..b87f6f8c 100644 --- a/console/frontend/src/views/VisualizePage/OptionsPanel.vue +++ b/console/frontend/src/views/VisualizePage/OptionsPanel.vue @@ -108,7 +108,7 @@ const props = defineProps({ }); const emit = defineEmits(["update:modelValue", "cancel"]); -import { ref, watch, computed } from "vue"; +import { ref, watch, computed, inject } from "vue"; import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/vue/solid"; import InputTimeRange from "@/components/InputTimeRange.vue"; import InputDimensions from "@/components/InputDimensions.vue"; @@ -155,17 +155,19 @@ const hasErrors = computed( !!(timeRange.value.errors || dimensions.value.errors || filter.value.errors) ); +const serverConfiguration = inject("server-configuration"); watch( - () => props.modelValue, - (modelValue) => { + () => [props.modelValue, serverConfiguration.value?.defaultVisualizeOptions], + ([modelValue, defaultOptions]) => { + if (defaultOptions === undefined) return; const { graphType: _graphType = graphTypes.stacked, - start = "6 hours ago", - end = "now", - dimensions: _dimensions = ["SrcAS"], + start = defaultOptions?.start, + end = defaultOptions?.end, + dimensions: _dimensions = defaultOptions?.dimensions, limit = 10, points /* eslint-disable-line no-unused-vars */, - filter: _filter = "InIfBoundary = external", + filter: _filter = defaultOptions?.filter, units: _units = "l3bps", } = modelValue; @@ -173,14 +175,17 @@ watch( graphType.value = graphTypeList.find(({ name }) => name === _graphType) || graphTypeList[0]; timeRange.value = { start, end }; - dimensions.value = { selected: [..._dimensions], limit }; + dimensions.value = { + selected: [..._dimensions], + limit, + }; filter.value = { expression: _filter }; units.value = _units; // A bit risky, but it seems to work. if (!isEqual(modelValue, options.value)) { open.value = true; - if (!hasErrors.value) { + if (!hasErrors.value && start) { emit("update:modelValue", options.value); } }