Skip to content

Commit

Permalink
console: add an option for homepage graph time range
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentbernat committed May 9, 2024
1 parent 64acf78 commit 1037d66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
11 changes: 7 additions & 4 deletions console/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Configuration struct {
HomepageTopWidgets []string `validate:"dive,oneof=src-as dst-as src-country dst-country exporter protocol etype src-port dst-port"`
// HomepageGraphFilter defines the filtering string to use for the homepage graph
HomepageGraphFilter string
// HomepageGraphTimeRange defines the time range to use for the homepage graph
HomepageGraphTimeRange time.Duration `validate:"min=1m"`
// DimensionsLimit put an upper limit to the number of dimensions to return.
DimensionsLimit int `validate:"min=10"`
// CacheTTL tells how long to keep the most costly requests in cache.
Expand Down Expand Up @@ -57,10 +59,11 @@ func DefaultConfiguration() Configuration {
Dimensions: []query.Column{query.NewColumn("SrcAS")},
Limit: 10,
},
HomepageTopWidgets: []string{"src-as", "src-port", "protocol", "src-country", "etype"},
DimensionsLimit: 50,
CacheTTL: 3 * time.Hour,
HomepageGraphFilter: "InIfBoundary = 'external'",
HomepageTopWidgets: []string{"src-as", "src-port", "protocol", "src-country", "etype"},
DimensionsLimit: 50,
CacheTTL: 3 * time.Hour,
HomepageGraphFilter: "InIfBoundary = 'external'",
HomepageGraphTimeRange: 24 * time.Hour,
}
}

Expand Down
10 changes: 6 additions & 4 deletions console/data/docs/02-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,12 @@ The console itself accepts the following keys:
- `homepage-top-widgets` to define the widgets to display on the home page
- `dimensions-limit` to set the upper limit of the number of returned dimensions
- `cache-ttl` sets the time costly requests are kept in cache
- `homepage-graph-filter` sets the filter for the graph on the
homepage (default: `InIfBoundary = 'external'`).
This is a SQL expression, passed into the clickhouse query directly.
It can also be empty, in which case the sum of all flows captured will be displayed.
- `homepage-graph-filter` sets the filter for the graph on the homepage
(default: `InIfBoundary = 'external'`). This is a SQL expression, passed
into the clickhouse query directly. It can also be empty, in which case the
sum of all flows captured will be displayed.
- `homepage-graph-timerange` sets the time range to use for the graph on the
homepage. It defaults to 24 hours.

Here is an example:

Expand Down
1 change: 1 addition & 0 deletions console/data/docs/99-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ identified with a specific icon:
- 💥 *console*: persist metadata cache on the default `docker compose` setup
- 🩹 *clickhouse*: disable experimental analyzer on recent versions of ClickHouse
- 🌱 *console*: add support for PostgreSQL and MySQL to store filters
- 🌱 *console*: add `console``homepage-graph-timerange` to define the time range for the homepage graph
- 🌱 *docker*: update to Traefik 3.0 (not mandatory)
- 🌱 *docker*: build IPinfo update image to make it available for non-x86 architectures

Expand Down
3 changes: 1 addition & 2 deletions console/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ LIMIT 5
}

func (c *Component) widgetGraphHandlerFunc(gc *gin.Context) {
// first step: define which filter to use
filter := c.config.HomepageGraphFilter
if filter != "" {
filter = fmt.Sprintf("AND %s", filter)
Expand All @@ -232,7 +231,7 @@ ORDER BY Time WITH FILL
STEP {{ .Interval }}
{{ end }}`,
templateContext(inputContext{
Start: now.Add(-24 * time.Hour),
Start: now.Add(-c.config.HomepageGraphTimeRange),
End: now,
MainTableRequired: false,
Points: 200,
Expand Down

0 comments on commit 1037d66

Please sign in to comment.