Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
vendor
jsonnetfile.lock.json
*.zip
.worktrees
2 changes: 2 additions & 0 deletions discourse-mixin/.lint
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ exclusions:
- panel: "Sidekiq Workers"
template-instance-rule:
reason: "Based on new convention we are using variable names prometheus_datasource and loki_datasource where as linter expects 'datasource'"
panel-datasource-rule:
reason: "Modern mixins use signal-based architecture where datasource references are handled by the framework"
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
prometheusAlerts+:: {
groups+: [
new(this): {
groups: [
{
name: 'DiscourseAlerts',
name: this.config.uid + '-alerts',
rules: [
{
alert: 'DiscourseRequestsHigh5xxErrors',
alert: 'DiscourseHigh5xxErrors',
expr: |||
100 * rate(discourse_http_requests{status="500"}[5m]) / on() group_left() (sum(rate(discourse_http_requests[5m])) by (instance)) > %(alertsCritical5xxResponses)s
||| % $._config,
||| % this.config,
'for': '5m',
labels: {
severity: 'critical',
},
annotations: {
summary: 'More than %(alertsCritical5xxResponses)s%% of all requests result in a 5XX.' % $._config,
summary: 'More than %(alertsCritical5xxResponses)s%% of all requests result in a 5XX.' % this.config,
description:
('{{ printf "%%.2f" $value }}%% of all requests are resulting in 500 status codes, ' +
'which is above the threshold %(alertsCritical5xxResponses)s%%, ' +
'indicating a potentially larger issue for {{$labels.instance}}') % $._config,
'indicating a potentially larger issue for {{$labels.instance}}') % this.config,
},
},
{
alert: 'DiscourseRequestsHigh4xxErrors',
alert: 'DiscourseHigh4xxErrors',
expr: |||
100 * rate(discourse_http_requests{status=~"^4.*"}[5m]) / on() group_left() (sum(rate(discourse_http_requests[5m])) by (instance)) > %(alertsWarning4xxResponses)s
||| % $._config,
||| % this.config,
'for': '5m',
labels: {
severity: 'warning',
},
annotations: {
summary: 'More than %(alertsWarning4xxResponses)s%% of all requests result in a 4XX.' % $._config,
summary: 'More than %(alertsWarning4xxResponses)s%% of all requests result in a 4XX.' % this.config,
description:
('{{ printf "%%.2f" $value }}%% of all requests are resulting in 400 status code, ' +
'which is above the threshold %(alertsWarning4xxResponses)s%%, ' +
'indicating a potentially larger issue for {{$labels.instance}}') % $._config,
'indicating a potentially larger issue for {{$labels.instance}}') % this.config,
},
},
],
Expand Down
40 changes: 31 additions & 9 deletions discourse-mixin/config.libsonnet
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
{
_config+:: {
dashboardTags: ['discourse-mixin'],
dashboardPeriod: 'now-1h',
dashboardTimezone: 'default',
dashboardRefresh: '1m',

// for alerts
alertsCritical5xxResponses: '10', // %
alertsWarning4xxResponses: '30', // %
local this = self,

// Filtering
filteringSelector: 'job=~"$job", instance=~"$instance"',
groupLabels: ['job'],
instanceLabels: ['instance'],

// Dashboard settings
dashboardTags: ['discourse-mixin'],
dashboardPeriod: 'now-1h',
dashboardTimezone: 'default',
dashboardRefresh: '1m',
dashboardNamePrefix: 'Discourse',
uid: 'discourse',

// Logs configuration
enableLokiLogs: false,

// Alert thresholds
alertsCritical5xxResponses: 10, // %
alertsWarning4xxResponses: 30, // %

// Metrics source
metricsSource: 'prometheus',

// Signal categories
signals: {
http: (import './signals/http.libsonnet')(this),
requests: (import './signals/requests.libsonnet')(this),
jobs: (import './signals/jobs.libsonnet')(this),
memory: (import './signals/memory.libsonnet')(this),
},
}
86 changes: 86 additions & 0 deletions discourse-mixin/dashboards.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
local g = import './g.libsonnet';
local commonlib = import 'common-lib/common/main.libsonnet';

{
local root = self,
new(this):
local prefix = this.config.dashboardNamePrefix;
local links = this.grafana.links;
local tags = this.config.dashboardTags;
local uid = this.config.uid;
local vars = commonlib.variables.new(
filteringSelector=this.config.filteringSelector,
groupLabels=this.config.groupLabels,
instanceLabels=this.config.instanceLabels,
varMetric='discourse_page_views',
customAllValue='.+',
enableLokiLogs=this.config.enableLokiLogs,
);
local annotations = {};
local refresh = this.config.dashboardRefresh;
local period = this.config.dashboardPeriod;
local timezone = this.config.dashboardTimezone;

{
'discourse-overview.json':
g.dashboard.new(prefix + ' overview')
+ g.dashboard.withDescription('Overview of Discourse application performance and traffic.')
+ g.dashboard.withPanels(
g.util.panel.resolveCollapsedFlagOnRows(
g.util.grid.wrapPanels(
[
this.grafana.rows.overviewRow,
this.grafana.rows.latencyRow,
]
)
)
)
+ root.applyCommon(
vars.multiInstance,
uid + '-overview',
tags,
links { overview+:: {} },
annotations,
timezone,
refresh,
period
),

'discourse-jobs.json':
g.dashboard.new(prefix + ' jobs processing')
+ g.dashboard.withDescription('Discourse job processing, workers, and memory usage.')
+ g.dashboard.withPanels(
g.util.panel.resolveCollapsedFlagOnRows(
g.util.grid.wrapPanels(
[
this.grafana.rows.jobStatsRow,
this.grafana.rows.jobCountsRow,
this.grafana.rows.jobDurationRow,
this.grafana.rows.memoryRow,
]
)
)
)
+ root.applyCommon(
vars.multiInstance,
uid + '-jobs',
tags,
links { jobs+:: {} },
annotations,
timezone,
refresh,
period
),
},

applyCommon(vars, uid, tags, links, annotations, timezone, refresh, period):
g.dashboard.withTags(tags)
+ g.dashboard.withUid(uid)
+ g.dashboard.withLinks(std.objectValues(links))
+ g.dashboard.withTimezone(timezone)
+ g.dashboard.withRefresh(refresh)
+ g.dashboard.time.withFrom(period)
+ g.dashboard.withVariables(vars)
+ g.dashboard.withAnnotations(std.objectValues(annotations))
+ g.dashboard.graphTooltip.withSharedCrosshair(),
}
2 changes: 0 additions & 2 deletions discourse-mixin/dashboards/dashboards.libsonnet

This file was deleted.

Loading
Loading