console: add configuration for default options of the visualize tab

This commit is contained in:
Vincent Bernat
2022-07-21 13:15:22 +02:00
parent 927a9f3cfd
commit 049513be5c
5 changed files with 63 additions and 11 deletions

View File

@@ -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,
})
}

View File

@@ -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"},
},
},
},
})

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}
}