common/schema: turns into a component

This is a first step to make it accept configuration. Most of the
changes are quite trivial, but I also ran into some difficulties with
query columns and filters. They need the schema for parsing, but parsing
happens before dependencies are instantiated (and even if it was not the
case, parsing is stateless). Therefore, I have added a `Validate()`
method that must be called after instantiation. Various bits `panic()`
if not validated to ensure we catch all cases.

The alternative to make the component manages a global state would have
been simpler but it would break once we add the ability to add or
disable columns.
This commit is contained in:
Vincent Bernat
2023-01-18 12:14:23 +01:00
parent 3c55f90fdf
commit c6a9319b57
58 changed files with 1049 additions and 655 deletions

View File

@@ -7,7 +7,7 @@ import (
"net/http"
"time"
"akvorado/common/schema"
"akvorado/console/query"
"github.com/gin-gonic/gin"
)
@@ -39,7 +39,7 @@ type VisualizeOptionsConfiguration struct {
// Filter is the the filter string
Filter string `json:"filter"`
// Dimensions is the array of dimensions to use
Dimensions []queryColumn `json:"dimensions"`
Dimensions []query.Column `json:"dimensions"`
// Limit is the default limit to use
Limit int `json:"limit" validate:"min=5"`
}
@@ -52,7 +52,7 @@ func DefaultConfiguration() Configuration {
Start: "6 hours ago",
End: "now",
Filter: "InIfBoundary = external",
Dimensions: []queryColumn{queryColumn(schema.ColumnSrcAS)},
Dimensions: []query.Column{query.NewColumn("SrcAS")},
Limit: 10,
},
HomepageTopWidgets: []string{"src-as", "src-port", "protocol", "src-country", "etype"},
@@ -63,7 +63,7 @@ func DefaultConfiguration() Configuration {
func (c *Component) configHandlerFunc(gc *gin.Context) {
dimensions := []string{}
for _, column := range schema.Flows.Columns() {
for _, column := range c.d.Schema.Columns() {
if column.ConsoleNotDimension {
continue
}