-
Notifications
You must be signed in to change notification settings - Fork 94
/
apicast_monitoring.go
199 lines (184 loc) · 7.02 KB
/
apicast_monitoring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package component
import (
"fmt"
"github.com/coreos/prometheus-operator/pkg/apis/monitoring"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
grafanav1alpha1 "github.com/integr8ly/grafana-operator/v3/pkg/apis/integreatly/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"github.com/3scale/3scale-operator/pkg/assets"
"github.com/3scale/3scale-operator/pkg/common"
)
func (apicast *Apicast) ApicastProductionPodMonitor() *monitoringv1.PodMonitor {
return &monitoringv1.PodMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-production",
Labels: apicast.Options.CommonProductionLabels,
},
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{{
Port: "metrics",
Path: "/metrics",
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: apicast.Options.CommonProductionLabels,
},
},
}
}
func (apicast *Apicast) ApicastStagingPodMonitor() *monitoringv1.PodMonitor {
return &monitoringv1.PodMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-staging",
Labels: apicast.Options.CommonStagingLabels,
},
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{{
Port: "metrics",
Path: "/metrics",
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: apicast.Options.CommonStagingLabels,
},
},
}
}
func (apicast *Apicast) ApicastMainAppGrafanaDashboard(sumRate string) *grafanav1alpha1.GrafanaDashboard {
data := &struct {
Namespace, SumRate string
}{
apicast.Options.Namespace, sumRate,
}
return &grafanav1alpha1.GrafanaDashboard{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-mainapp",
Labels: apicast.monitoringLabels(),
},
Spec: grafanav1alpha1.GrafanaDashboardSpec{
Json: assets.TemplateAsset("monitoring/apicast-grafana-dashboard-1.json.tpl", data),
Name: fmt.Sprintf("%s/apicast-grafana-dashboard-1.json", apicast.Options.Namespace),
},
}
}
func (apicast *Apicast) ApicastServicesGrafanaDashboard(sumRate string) *grafanav1alpha1.GrafanaDashboard {
data := &struct {
Namespace, SumRate string
}{
apicast.Options.Namespace, sumRate,
}
return &grafanav1alpha1.GrafanaDashboard{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-services",
Labels: apicast.monitoringLabels(),
},
Spec: grafanav1alpha1.GrafanaDashboardSpec{
Json: assets.TemplateAsset("monitoring/apicast-grafana-dashboard-2.json.tpl", data),
Name: fmt.Sprintf("%s/apicast-grafana-dashboard-2.json", apicast.Options.Namespace),
},
}
}
func (apicast *Apicast) ApicastPrometheusRules() *monitoringv1.PrometheusRule {
return &monitoringv1.PrometheusRule{
TypeMeta: metav1.TypeMeta{
Kind: monitoringv1.PrometheusRuleKind,
APIVersion: fmt.Sprintf("%s/%s", monitoring.GroupName, monitoringv1.Version),
},
ObjectMeta: metav1.ObjectMeta{
Name: "apicast",
Labels: apicast.prometheusRulesMonitoringLabels(),
},
Spec: monitoringv1.PrometheusRuleSpec{
Groups: []monitoringv1.RuleGroup{
{
Name: fmt.Sprintf("%s/apicast.rules", apicast.Options.Namespace),
Rules: []monitoringv1.Rule{
{
Alert: "ThreescaleApicastJobDown",
Annotations: map[string]string{
"sop_url": ThreescalePrometheusJobDownURL,
"summary": "Job {{ $labels.job }} on {{ $labels.namespace }} is DOWN",
"description": "Job {{ $labels.job }} on {{ $labels.namespace }} is DOWN",
},
Expr: intstr.FromString(fmt.Sprintf(`up{job=~".*/apicast-production|.*/apicast-staging",namespace="%s"} == 0`, apicast.Options.Namespace)),
For: "1m",
Labels: map[string]string{
"severity": "critical",
},
},
{
Alert: "ThreescaleApicastRequestTime",
Annotations: map[string]string{
"sop_url": ThreescaleApicastRequestTimeURL,
"summary": "Request on instance {{ $labels.instance }} is taking more than one second to process the requests",
"description": "High number of request taking more than a second to be processed",
},
Expr: intstr.FromString(fmt.Sprintf(`sum(rate(total_response_time_seconds_bucket{namespace='%s', pod=~'apicast-production.*'}[1m])) - sum(rate(upstream_response_time_seconds_bucket{namespace='%s', pod=~'apicast-production.*'}[1m])) > 1`, apicast.Options.Namespace, apicast.Options.Namespace)),
For: "2m",
Labels: map[string]string{
"severity": "warning",
},
},
{
Alert: "ThreescaleApicastHttp4xxErrorRate",
Annotations: map[string]string{
"sop_url": ThreescaleApicastHttp4xxErrorRateURL,
"summary": "APICast high HTTP 4XX error rate (instance {{ $labels.instance }})",
"description": "The number of request with 4XX is bigger than the 5% of total request.",
},
Expr: intstr.FromString(fmt.Sprintf(`sum(rate(apicast_status{namespace='%s', status=~"^4.."}[1m])) / sum(rate(apicast_status{namespace='%s'}[1m])) * 100 > 5`, apicast.Options.Namespace, apicast.Options.Namespace)),
For: "5m",
Labels: map[string]string{
"severity": "warning",
},
},
{
Alert: "ThreescaleApicastLatencyHigh",
Annotations: map[string]string{
"sop_url": ThreescaleApicastLatencyHighURL,
"summary": "APICast latency high (instance {{ $labels.instance }})",
"description": "APIcast p99 latency is higher than 5 seconds\n VALUE = {{ $value }}\n LABELS: {{ $labels }}",
},
Expr: intstr.FromString(fmt.Sprintf(`histogram_quantile(0.99, sum(rate(total_response_time_seconds_bucket{namespace='%s',}[30m])) by (le)) > 5`, apicast.Options.Namespace)),
For: "5m",
Labels: map[string]string{
"severity": "warning",
},
},
{
Alert: "ThreescaleApicastWorkerRestart",
Annotations: map[string]string{
"sop_url": ThreescaleApicastWorkerRestartURL,
"summary": "A new worker process in Nginx has been started",
"description": "A new thread has been started. This could indicate that a worker process has died due to the memory limits being exceeded. Please investigate the memory pressure on pod (instance {{ $labels.instance }})",
},
Expr: intstr.FromString(fmt.Sprintf(`changes(worker_process{namespace='%s', pod=~'apicast-production.*'}[5m]) > 0`, apicast.Options.Namespace)),
For: "5m",
Labels: map[string]string{
"severity": "warning",
},
},
},
},
},
},
}
}
func (apicast *Apicast) monitoringLabels() map[string]string {
labels := make(map[string]string)
for key, value := range apicast.Options.CommonLabels {
labels[key] = value
}
labels["monitoring-key"] = common.MonitoringKey
return labels
}
func (apicast *Apicast) prometheusRulesMonitoringLabels() map[string]string {
labels := make(map[string]string)
for key, value := range apicast.Options.CommonLabels {
labels[key] = value
}
labels["prometheus"] = "application-monitoring"
labels["role"] = "alert-rules"
return labels
}