|
1 | 1 | local g = import './g.libsonnet'; |
2 | 2 | local commonlib = import 'common-lib/common/main.libsonnet'; |
| 3 | +local logslib = import 'logs-lib/logs/main.libsonnet'; |
3 | 4 |
|
4 | 5 | { |
5 | 6 | local root = self, |
6 | 7 | new(this): |
7 | 8 | local prefix = this.config.dashboardNamePrefix; |
8 | 9 | local links = this.grafana.links; |
9 | 10 | local tags = this.config.dashboardTags; |
10 | | - local uid = this.config.uid; |
11 | | - local vars = commonlib.variables.new( |
12 | | - filteringSelector=this.config.filteringSelector, |
13 | | - groupLabels=this.config.groupLabels, |
14 | | - instanceLabels=this.config.instanceLabels, |
15 | | - varMetric='squid_server_http_requests_total', |
16 | | - customAllValue='.+', |
17 | | - enableLokiLogs=this.config.enableLokiLogs, |
18 | | - ); |
19 | | - local annotations = {}; |
| 11 | + local uid = g.util.string.slugify(this.config.uid); |
| 12 | + local vars = this.grafana.variables; |
| 13 | + local annotations = this.grafana.annotations; |
20 | 14 | local refresh = this.config.dashboardRefresh; |
21 | 15 | local period = this.config.dashboardPeriod; |
22 | 16 | local timezone = this.config.dashboardTimezone; |
23 | | - |
| 17 | + local extraLogLabels = this.config.extraLogLabels; |
24 | 18 | { |
25 | 19 | 'squid-overview.json': |
26 | 20 | g.dashboard.new(prefix + ' overview') |
27 | 21 | + g.dashboard.withDescription('') |
28 | 22 | + g.dashboard.withPanels( |
29 | 23 | g.util.panel.resolveCollapsedFlagOnRows( |
30 | | - g.util.grid.wrapPanels( |
31 | | - [ |
| 24 | + g.util.grid.wrapPanels([ |
32 | 25 | this.grafana.rows.clientRow, |
33 | 26 | this.grafana.rows.serverRow, |
34 | | - ] |
35 | | - + |
36 | | - if this.config.enableLokiLogs then |
37 | | - [this.grafana.rows.logsRow] |
38 | | - else |
39 | | - [] |
40 | | - ) |
| 27 | + ]) |
41 | 28 | ) |
42 | 29 | ) |
43 | 30 | + root.applyCommon( |
44 | 31 | vars.multiInstance, |
45 | 32 | uid + '-overview', |
46 | 33 | tags, |
47 | | - links, |
| 34 | + links {squidOverview+:: {} }, |
48 | 35 | annotations, |
49 | 36 | timezone, |
50 | 37 | refresh, |
51 | 38 | period |
52 | 39 | ), |
53 | | - }, |
| 40 | + } + if this.config.enableLokiLogs then { |
| 41 | + 'squid-logs.json': |
| 42 | + logslib.new( |
| 43 | + this.config.dashboardNamePrefix + ' logs', |
| 44 | + datasourceName=this.grafana.variables.datasources.loki.name, |
| 45 | + datasourceRegex=this.grafana.variables.datasources.loki.regex, |
| 46 | + filterSelector=this.config.filteringSelector, |
| 47 | + labels=this.config.groupLabels + this.config.extraLogLabels, |
| 48 | + formatParser=null, |
| 49 | + showLogsVolume=this.config.showLogsVolume, |
| 50 | + ) |
| 51 | + { |
| 52 | + dashboards+: |
| 53 | + { |
| 54 | + logs+: |
| 55 | + root.applyCommon(super.logs.templating.list, uid=uid + '-logs', tags=tags, links=links { logs+:: {} }, annotations=annotations, timezone=timezone, refresh=refresh, period=period), |
| 56 | + }, |
| 57 | + panels+: |
| 58 | + { |
| 59 | + logs+: |
| 60 | + g.panel.logs.options.withEnableLogDetails(true) |
| 61 | + + g.panel.logs.options.withShowTime(false) |
| 62 | + + g.panel.logs.options.withWrapLogMessage(false), |
| 63 | + }, |
| 64 | + variables+: { |
| 65 | + toArray+: [ |
| 66 | + this.grafana.variables.datasources.prometheus { hide: 2 }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + }.dashboards.logs, |
| 70 | + } else {}, |
54 | 71 |
|
55 | 72 | applyCommon(vars, uid, tags, links, annotations, timezone, refresh, period): |
56 | 73 | g.dashboard.withTags(tags) |
57 | 74 | + g.dashboard.withUid(uid) |
58 | | - + g.dashboard.withLinks([links[key].asDashboardLink() for key in std.objectFields(links)]) |
| 75 | + + g.dashboard.withLinks(std.objectValues(links)) |
59 | 76 | + g.dashboard.withTimezone(timezone) |
60 | 77 | + g.dashboard.withRefresh(refresh) |
61 | 78 | + g.dashboard.time.withFrom(period) |
|
0 commit comments