/
metrics.go
1491 lines (1193 loc) · 55.6 KB
/
metrics.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2017-2019 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package metrics holds prometheus metrics objects and related utility functions. It
// does not abstract away the prometheus client but the caller rarely needs to
// refer to prometheus directly.
package metrics
// Adding a metric
// - Add a metric object of the appropriate type as an exported variable
// - Register the new object in the init function
import (
"net/http"
"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/version"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
dto "github.com/prometheus/client_model/go"
"golang.org/x/sys/unix"
)
const (
// ErrorTimeout is the value used to notify timeout errors.
ErrorTimeout = "timeout"
// ErrorProxy is the value used to notify errors on Proxy.
ErrorProxy = "proxy"
//L7DNS is the value used to report DNS label on metrics
L7DNS = "dns"
// SubsystemBPF is the subsystem to scope metrics related to the bpf syscalls.
SubsystemBPF = "bpf"
// SubsystemDatapath is the subsystem to scope metrics related to management of
// the datapath. It is prepended to metric names and separated with a '_'.
SubsystemDatapath = "datapath"
// SubsystemAgent is the subsystem to scope metrics related to the cilium agent itself.
SubsystemAgent = "agent"
// SubsystemK8s is the subsystem to scope metrics related to Kubernetes
SubsystemK8s = "k8s"
// SubsystemK8sClient is the subsystem to scope metrics related to the kubernetes client.
SubsystemK8sClient = "k8s_client"
// SubsystemKVStore is the subsystem to scope metrics related to the kvstore.
SubsystemKVStore = "kvstore"
// SubsystemNodes is the subsystem to scope metrics related to the node manager.
SubsystemNodes = "nodes"
// SubsystemTriggers is the subsystem to scope metrics related to the trigger package.
SubsystemTriggers = "triggers"
// SubsystemAPILimiter is the subsystem to scope metrics related to the API limiter package.
SubsystemAPILimiter = "api_limiter"
// Namespace is used to scope metrics from cilium. It is prepended to metric
// names and separated with a '_'
Namespace = "cilium"
// LabelError indicates the type of error (string)
LabelError = "error"
// LabelOutcome indicates whether the outcome of the operation was successful or not
LabelOutcome = "outcome"
// LabelAttempts is the number of attempts it took to complete the operation
LabelAttempts = "attempts"
// Labels
// LabelValueOutcomeSuccess is used as a successful outcome of an operation
LabelValueOutcomeSuccess = "success"
// LabelValueOutcomeFail is used as an unsuccessful outcome of an operation
LabelValueOutcomeFail = "fail"
// LabelEventSourceAPI marks event-related metrics that come from the API
LabelEventSourceAPI = "api"
// LabelEventSourceK8s marks event-related metrics that come from k8s
LabelEventSourceK8s = "k8s"
// LabelEventSourceFQDN marks event-related metrics that come from pkg/fqdn
LabelEventSourceFQDN = "fqdn"
// LabelEventSourceContainerd marks event-related metrics that come from docker
LabelEventSourceContainerd = "docker"
// LabelDatapathArea marks which area the metrics are related to (eg, which BPF map)
LabelDatapathArea = "area"
// LabelDatapathName marks a unique identifier for this metric.
// The name should be defined once for a given type of error.
LabelDatapathName = "name"
// LabelDatapathFamily marks which protocol family (IPv4, IPV6) the metric is related to.
LabelDatapathFamily = "family"
// LabelProtocol marks the L4 protocol (TCP, ANY) for the metric.
LabelProtocol = "protocol"
// LabelSignalType marks the signal name
LabelSignalType = "signal"
// LabelSignalData marks the signal data
LabelSignalData = "data"
// LabelStatus the label from completed task
LabelStatus = "status"
// LabelPolicyEnforcement is the label used to see the enforcement status
LabelPolicyEnforcement = "enforcement"
// LabelPolicySource is the label used to see the enforcement status
LabelPolicySource = "source"
// LabelScope is the label used to defined multiples scopes in the same
// metric. For example, one counter may measure a metric over the scope of
// the entire event (scope=global), or just part of an event
// (scope=slow_path)
LabelScope = "scope"
// LabelProtocolL7 is the label used when working with layer 7 protocols.
LabelProtocolL7 = "protocol_l7"
// LabelBuildState is the state a build queue entry is in
LabelBuildState = "state"
// LabelBuildQueueName is the name of the build queue
LabelBuildQueueName = "name"
// LabelAction is the label used to defined what kind of action was performed in a metric
LabelAction = "action"
// LabelSubsystem is the label used to refer to any of the child process
// started by cilium (Envoy, monitor, etc..)
LabelSubsystem = "subsystem"
// LabelKind is the kind a label
LabelKind = "kind"
// LabelPath is the label for the API path
LabelPath = "path"
// LabelMethod is the label for the HTTP method
LabelMethod = "method"
// LabelAPIReturnCode is the HTTP code returned for that API path
LabelAPIReturnCode = "return_code"
// LabelOperation is the label for BPF maps operations
LabelOperation = "operation"
// TODO(sayboras): Remove deprecated metric in 1.10
// LabelMapNameDeprecated is the label for the BPF map name
// Deprecated: in favor of LabelMapName
LabelMapNameDeprecated = "mapName"
// LabelMapName is the label for the BPF map name
LabelMapName = "map_name"
// LabelVersion is the label for the version number
LabelVersion = "version"
// LabelDirection is the label for traffic direction
LabelDirection = "direction"
)
var (
registry = prometheus.NewPedanticRegistry()
// APIInteractions is the total time taken to process an API call made
// to the cilium-agent
APIInteractions = NoOpObserverVec
// Endpoint
// Endpoint is a function used to collect this metric.
// It must be thread-safe.
Endpoint prometheus.GaugeFunc
// TODO(sayboras): Remove deprecated metric in 1.10
// EndpointCount is a function used to collect this metric.
// It must be thread-safe.
// Deprecated: in favor of Endpoint
EndpointCount prometheus.GaugeFunc
// TODO(sayboras): Remove deprecated metric in 1.10
// EndpointRegenerationCount is a count of the number of times any endpoint
// has been regenerated and success/fail outcome
// Deprecated: in favor of EndpointRegenerationTotal
EndpointRegenerationCount = NoOpCounterVec
// EndpointRegenerationTotal is a count of the number of times any endpoint
// has been regenerated and success/fail outcome
EndpointRegenerationTotal = NoOpCounterVec
// EndpointStateCount is the total count of the endpoints in various states.
EndpointStateCount = NoOpGaugeVec
// EndpointRegenerationTimeStats is the total time taken to regenerate
// endpoints, labeled by span name and status ("success" or "failure")
EndpointRegenerationTimeStats = NoOpObserverVec
// Policy
// Policy is the number of policies loaded into the agent
Policy = NoOpGauge
// TODO(sayboras): Remove deprecated metric in 1.10
// PolicyCount is the number of policies loaded into the agent
// Deprecated: in favor of Policy
PolicyCount = NoOpGauge
// PolicyRegenerationCount is the total number of successful policy
// regenerations.
PolicyRegenerationCount = NoOpCounter
// PolicyRegenerationTimeStats is the total time taken to generate policies
PolicyRegenerationTimeStats = NoOpObserverVec
// PolicyRevision is the current policy revision number for this agent
PolicyRevision = NoOpGauge
// TODO(sayboras): Remove deprecated metric in 1.10
// PolicyImportErrors is a count of failed policy imports
// Deprecated: in favor of PolicyImportErrorsTotal
PolicyImportErrors = NoOpCounter
// PolicyImportErrorsTotal is a count of failed policy imports
PolicyImportErrorsTotal = NoOpCounter
// PolicyEndpointStatus is the number of endpoints with policy labeled by enforcement type
PolicyEndpointStatus = NoOpGaugeVec
// PolicyImplementationDelay is a distribution of times taken from adding a
// policy (and incrementing the policy revision) to seeing it in the datapath
// per Endpoint. This reflects the actual delay perceived by traffic flowing
// through the datapath. The longest times will roughly correlate with the
// time taken to fully deploy an endpoint.
PolicyImplementationDelay = NoOpObserverVec
// Identity
// Identity is the number of identities currently in use on the node
Identity = NoOpGauge
// TODO(sayboras): Remove deprecated metric in 1.10
// IdentityCount is the number of identities currently in use on the node
// Deprecated: in favor of Identity
IdentityCount = NoOpGauge
// Events
// EventTS*is the time in seconds since epoch that we last received an
// event that we will handle
// source is one of k8s, docker or apia
// EventTSK8s is the timestamp of k8s events
EventTSK8s = NoOpGauge
// EventLagK8s is the lag calculation for k8s Pod events.
EventLagK8s = NoOpGauge
// EventTSContainerd is the timestamp of docker events
EventTSContainerd = NoOpGauge
// EventTSAPI is the timestamp of docker events
EventTSAPI = NoOpGauge
// L7 statistics
// ProxyRedirects is the number of redirects labeled by protocol
ProxyRedirects = NoOpGaugeVec
// ProxyPolicyL7Total is a count of all l7 requests handled by proxy
ProxyPolicyL7Total = NoOpCounterVec
// ProxyParseErrors is a count of failed parse errors on proxy
// Deprecated: in favor of ProxyPolicyL7Total
ProxyParseErrors = NoOpCounter
// ProxyForwarded is a count of all forwarded requests by proxy
// Deprecated: in favor of ProxyPolicyL7Total
ProxyForwarded = NoOpCounter
// ProxyDenied is a count of all denied requests by policy by the proxy
// Deprecated: in favor of ProxyPolicyL7Total
ProxyDenied = NoOpCounter
// ProxyReceived is a count of all received requests by the proxy
// Deprecated: in favor of ProxyPolicyL7Total
ProxyReceived = NoOpCounter
// ProxyUpstreamTime is how long the upstream server took to reply labeled
// by error, protocol and span time
ProxyUpstreamTime = NoOpObserverVec
// L3-L4 statistics
// DropCount is the total drop requests,
// tagged by drop reason and direction(ingress/egress)
DropCount = NoOpCounterVec
// DropBytes is the total dropped bytes,
// tagged by drop reason and direction(ingress/egress)
DropBytes = NoOpCounterVec
// ForwardCount is the total forwarded packets,
// tagged by ingress/egress direction
ForwardCount = NoOpCounterVec
// ForwardBytes is the total forwarded bytes,
// tagged by ingress/egress direction
ForwardBytes = NoOpCounterVec
// Datapath statistics
// DatapathErrors is the number of errors managing datapath components
// such as BPF maps.
DatapathErrors = NoOpCounterVec
// ConntrackGCRuns is the number of times that the conntrack GC
// process was run.
ConntrackGCRuns = NoOpCounterVec
// ConntrackGCKeyFallbacks number of times that the conntrack key fallback was invalid.
ConntrackGCKeyFallbacks = NoOpCounterVec
// ConntrackGCSize the number of entries in the conntrack table
ConntrackGCSize = NoOpGaugeVec
// NatGCSize the number of entries in the nat table
NatGCSize = NoOpGaugeVec
// ConntrackGCDuration the duration of the conntrack GC process in milliseconds.
ConntrackGCDuration = NoOpObserverVec
// Signals
// SignalsHandled is the number of signals received.
SignalsHandled = NoOpCounterVec
// Services
// ServicesCount number of services
ServicesCount = NoOpCounterVec
// Errors and warnings
// ErrorsWarnings is the number of errors and warnings in cilium-agent instances
ErrorsWarnings = NoOpCounterVec
// ControllerRuns is the number of times that a controller process runs.
ControllerRuns = NoOpCounterVec
// ControllerRunsDuration the duration of the controller process in seconds
ControllerRunsDuration = NoOpObserverVec
// subprocess, labeled by Subsystem
SubprocessStart = NoOpCounterVec
// Kubernetes Events
// KubernetesEventProcessed is the number of Kubernetes events
// processed labeled by scope, action and execution result
KubernetesEventProcessed = NoOpCounterVec
// KubernetesEventReceived is the number of Kubernetes events received
// labeled by scope, action, valid data and equalness.
KubernetesEventReceived = NoOpCounterVec
// Kubernetes interactions
// KubernetesAPIInteractions is the total time taken to process an API call made
// to the kube-apiserver
KubernetesAPIInteractions = NoOpObserverVec
// TODO(sayboras): Remove deprecated metric in 1.10
// KubernetesAPICalls is the counter for all API calls made to
// kube-apiserver.
// Deprecated: Use KubernetesAPICallsTotal instead
KubernetesAPICalls = NoOpCounterVec
// KubernetesAPICallsTotal is the counter for all API calls made to
// kube-apiserver.
KubernetesAPICallsTotal = NoOpCounterVec
// KubernetesCNPStatusCompletion is the number of seconds it takes to
// complete a CNP status update
KubernetesCNPStatusCompletion = NoOpObserverVec
// IPAM events
// IpamEvent is the number of IPAM events received labeled by action and
// datapath family type
IpamEvent = NoOpCounterVec
// KVstore events
// KVStoreOperationsDuration records the duration of kvstore operations
KVStoreOperationsDuration = NoOpObserverVec
// KVStoreEventsQueueDuration records the duration in seconds of time
// received event was blocked before it could be queued
KVStoreEventsQueueDuration = NoOpObserverVec
// KVStoreQuorumErrors records the number of kvstore quorum errors
KVStoreQuorumErrors = NoOpCounterVec
// FQDNGarbageCollectorCleanedTotal is the number of domains cleaned by the
// GC job.
FQDNGarbageCollectorCleanedTotal = NoOpCounter
// BPFSyscallDuration is the metric for bpf syscalls duration.
BPFSyscallDuration = NoOpObserverVec
// BPFMapOps is the metric to measure the number of operations done to a
// bpf map.
BPFMapOps = NoOpCounterVec
// TriggerPolicyUpdateTotal is the metric to count total number of
// policy update triggers
TriggerPolicyUpdateTotal = NoOpCounterVec
// TriggerPolicyUpdateFolds is the current level folding that is
// happening when running policy update triggers
TriggerPolicyUpdateFolds = NoOpGauge
// TriggerPolicyUpdateCallDuration measures the latency and call
// duration of policy update triggers
TriggerPolicyUpdateCallDuration = NoOpObserverVec
// VersionMetric labelled by Cilium version
VersionMetric = NoOpGaugeVec
// APILimiterWaitHistoryDuration is a histogram that measures the
// individual wait durations of API limiters
APILimiterWaitHistoryDuration = NoOpObserverVec
// APILimiterWaitDuration is the gauge of the current mean, min, and
// max wait duration
APILimiterWaitDuration = NoOpGaugeVec
// APILimiterProcessingDuration is the gauge of the mean and estimated
// processing duration
APILimiterProcessingDuration = NoOpGaugeVec
// APILimiterRequestsInFlight is the gauge of the current and max
// requests in flight
APILimiterRequestsInFlight = NoOpGaugeVec
// APILimiterRateLimit is the gauge of the current rate limiting
// configuration including limit and burst
APILimiterRateLimit = NoOpGaugeVec
// APILimiterAdjustmentFactor is the gauge representing the latest
// adjustment factor that was applied
APILimiterAdjustmentFactor = NoOpGaugeVec
// APILimiterProcessedRequests is the counter of the number of
// processed (successful and failed) requests
APILimiterProcessedRequests = NoOpCounterVec
)
type Configuration struct {
APIInteractionsEnabled bool
EndpointRegenerationCountEnabled bool
EndpointStateCountEnabled bool
EndpointRegenerationTimeStatsEnabled bool
PolicyCountEnabled bool
PolicyRegenerationCountEnabled bool
PolicyRegenerationTimeStatsEnabled bool
PolicyRevisionEnabled bool
PolicyImportErrorsEnabled bool
PolicyEndpointStatusEnabled bool
PolicyImplementationDelayEnabled bool
IdentityCountEnabled bool
EventTSK8sEnabled bool
EventLagK8sEnabled bool
EventTSContainerdEnabled bool
EventTSAPIEnabled bool
ProxyRedirectsEnabled bool
ProxyPolicyL7Enabled bool
ProxyParseErrorsEnabled bool
ProxyForwardedEnabled bool
ProxyDeniedEnabled bool
ProxyReceivedEnabled bool
NoOpObserverVecEnabled bool
DropCountEnabled bool
DropBytesEnabled bool
NoOpCounterVecEnabled bool
ForwardBytesEnabled bool
DatapathErrorsEnabled bool
ConntrackGCRunsEnabled bool
ConntrackGCKeyFallbacksEnabled bool
ConntrackGCSizeEnabled bool
ConntrackGCDurationEnabled bool
SignalsHandledEnabled bool
ServicesCountEnabled bool
ErrorsWarningsEnabled bool
ControllerRunsEnabled bool
ControllerRunsDurationEnabled bool
SubprocessStartEnabled bool
KubernetesEventProcessedEnabled bool
KubernetesEventReceivedEnabled bool
KubernetesAPIInteractionsEnabled bool
KubernetesAPICallsEnabled bool
KubernetesCNPStatusCompletionEnabled bool
IpamEventEnabled bool
KVStoreOperationsDurationEnabled bool
KVStoreEventsQueueDurationEnabled bool
KVStoreQuorumErrorsEnabled bool
FQDNGarbageCollectorCleanedTotalEnabled bool
BPFSyscallDurationEnabled bool
BPFMapOps bool
TriggerPolicyUpdateTotal bool
TriggerPolicyUpdateFolds bool
TriggerPolicyUpdateCallDuration bool
VersionMetric bool
APILimiterWaitHistoryDuration bool
APILimiterWaitDuration bool
APILimiterProcessingDuration bool
APILimiterRequestsInFlight bool
APILimiterRateLimit bool
APILimiterAdjustmentFactor bool
APILimiterProcessedRequests bool
}
func DefaultMetrics() map[string]struct{} {
return map[string]struct{}{
Namespace + "_" + SubsystemAgent + "_api_process_time_seconds": {},
Namespace + "_endpoint_regenerations": {}, //TODO(sayboras): Remove deprecated metric in 1.10
Namespace + "_endpoint_regenerations_total": {},
Namespace + "_endpoint_state": {},
Namespace + "_endpoint_regeneration_time_stats_seconds": {},
Namespace + "_policy": {},
Namespace + "_policy_count": {}, //TODO(sayboras): Remove deprecated metric in 1.10
Namespace + "_policy_regeneration_total": {},
Namespace + "_policy_regeneration_time_stats_seconds": {},
Namespace + "_policy_max_revision": {},
Namespace + "_policy_import_errors": {}, //TODO(sayboras): Remove deprecated metric in 1.10
Namespace + "_policy_import_errors_total": {},
Namespace + "_policy_endpoint_enforcement_status": {},
Namespace + "_policy_implementation_delay": {},
Namespace + "_identity": {},
Namespace + "_identity_count": {}, //TODO(sayboras): Remove deprecated metric in 1.10
Namespace + "_event_ts": {},
Namespace + "_proxy_redirects": {},
Namespace + "_policy_l7_total": {},
Namespace + "_policy_l7_parse_errors_total": {},
Namespace + "_policy_l7_forwarded_total": {},
Namespace + "_policy_l7_denied_total": {},
Namespace + "_policy_l7_received_total": {},
Namespace + "_proxy_upstream_reply_seconds": {},
Namespace + "_drop_count_total": {},
Namespace + "_drop_bytes_total": {},
Namespace + "_forward_count_total": {},
Namespace + "_forward_bytes_total": {},
Namespace + "_" + SubsystemDatapath + "_errors_total": {},
Namespace + "_" + SubsystemDatapath + "_conntrack_gc_runs_total": {},
Namespace + "_" + SubsystemDatapath + "_conntrack_gc_key_fallbacks_total": {},
Namespace + "_" + SubsystemDatapath + "_conntrack_gc_entries": {},
Namespace + "_" + SubsystemDatapath + "_conntrack_gc_duration_seconds": {},
Namespace + "_" + SubsystemDatapath + "_signals_handled_total": {},
Namespace + "_services_events_total": {},
Namespace + "_errors_warnings_total": {},
Namespace + "_controllers_runs_total": {},
Namespace + "_controllers_runs_duration_seconds": {},
Namespace + "_subprocess_start_total": {},
Namespace + "_kubernetes_events_total": {},
Namespace + "_kubernetes_events_received_total": {},
Namespace + "_" + SubsystemK8sClient + "_api_latency_time_seconds": {},
Namespace + "_" + SubsystemK8sClient + "_api_calls_counter": {}, //TODO(sayboras): Remove deprecated metric in 1.10
Namespace + "_" + SubsystemK8sClient + "_api_calls_total": {},
Namespace + "_" + SubsystemK8s + "_cnp_status_completion_seconds": {},
Namespace + "_ipam_events_total": {},
Namespace + "_" + SubsystemKVStore + "_operations_duration_seconds": {},
Namespace + "_" + SubsystemKVStore + "_events_queue_seconds": {},
Namespace + "_" + SubsystemKVStore + "_quorum_errors_total": {},
Namespace + "_fqdn_gc_deletions_total": {},
Namespace + "_" + SubsystemBPF + "_map_ops_total": {},
Namespace + "_" + SubsystemTriggers + "_policy_update_total": {},
Namespace + "_" + SubsystemTriggers + "_policy_update_folds": {},
Namespace + "_" + SubsystemTriggers + "_policy_update_call_duration_seconds": {},
Namespace + "_version": {},
Namespace + "_" + SubsystemAPILimiter + "_wait_duration_seconds": {},
Namespace + "_" + SubsystemAPILimiter + "_processing_duration_seconds": {},
Namespace + "_" + SubsystemAPILimiter + "_requests_in_flight": {},
Namespace + "_" + SubsystemAPILimiter + "_rate_limit": {},
Namespace + "_" + SubsystemAPILimiter + "_adjustment_factor": {},
Namespace + "_" + SubsystemAPILimiter + "_processed_requests_total": {},
}
}
// CreateConfiguration returns a Configuration with all metrics that are
// considered enabled from the given slice of metricsEnabled as well as a slice
// of prometheus.Collectors that must be registered in the prometheus default
// register.
func CreateConfiguration(metricsEnabled []string) (Configuration, []prometheus.Collector) {
var collectors []prometheus.Collector
c := Configuration{}
for _, metricName := range metricsEnabled {
switch metricName {
case Namespace + "_" + SubsystemAgent + "_api_process_time_seconds":
APIInteractions = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: Namespace,
Subsystem: SubsystemAgent,
Name: "api_process_time_seconds",
Help: "Duration of processed API calls labeled by path, method and return code.",
}, []string{LabelPath, LabelMethod, LabelAPIReturnCode})
collectors = append(collectors, APIInteractions)
c.APIInteractionsEnabled = true
case Namespace + "_endpoint_regenerations":
EndpointRegenerationCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "endpoint_regenerations",
Help: "Count of all endpoint regenerations that have completed, tagged by outcome" +
"(deprecated, use endpoint_regenerations_total instead)",
}, []string{"outcome"})
collectors = append(collectors, EndpointRegenerationCount)
c.EndpointRegenerationCountEnabled = true
case Namespace + "_endpoint_regenerations_total":
EndpointRegenerationTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "endpoint_regenerations_total",
Help: "Count of all endpoint regenerations that have completed, tagged by outcome",
}, []string{"outcome"})
collectors = append(collectors, EndpointRegenerationTotal)
c.EndpointRegenerationCountEnabled = true
case Namespace + "_endpoint_state":
EndpointStateCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Name: "endpoint_state",
Help: "Count of all endpoints, tagged by different endpoint states",
},
[]string{"endpoint_state"},
)
collectors = append(collectors, EndpointStateCount)
c.EndpointStateCountEnabled = true
case Namespace + "_endpoint_regeneration_time_stats_seconds":
EndpointRegenerationTimeStats = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: Namespace,
Name: "endpoint_regeneration_time_stats_seconds",
Help: "Endpoint regeneration time stats labeled by the scope",
}, []string{LabelScope, LabelStatus})
collectors = append(collectors, EndpointRegenerationTimeStats)
c.EndpointRegenerationTimeStatsEnabled = true
case Namespace + "_policy":
Policy = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "policy",
Help: "Number of policies currently loaded",
})
collectors = append(collectors, Policy)
c.PolicyCountEnabled = true
case Namespace + "_policy_count":
PolicyCount = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "policy_count",
Help: "Number of policies currently loaded (deprecated, use policy instead)",
})
collectors = append(collectors, PolicyCount)
c.PolicyCountEnabled = true
case Namespace + "_policy_regeneration_total":
PolicyRegenerationCount = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_regeneration_total",
Help: "Total number of successful policy regenerations",
})
collectors = append(collectors, PolicyRegenerationCount)
c.PolicyRegenerationCountEnabled = true
case Namespace + "_policy_regeneration_time_stats_seconds":
PolicyRegenerationTimeStats = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: Namespace,
Name: "policy_regeneration_time_stats_seconds",
Help: "Policy regeneration time stats labeled by the scope",
}, []string{LabelScope, LabelStatus})
collectors = append(collectors, PolicyRegenerationTimeStats)
c.PolicyRegenerationTimeStatsEnabled = true
case Namespace + "_policy_max_revision":
PolicyRevision = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "policy_max_revision",
Help: "Highest policy revision number in the agent",
})
collectors = append(collectors, PolicyRevision)
c.PolicyRegenerationTimeStatsEnabled = true
case Namespace + "_policy_import_errors":
PolicyImportErrors = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_import_errors",
Help: "Number of times a policy import has failed" +
"(deprecated, use policy_import_errors_total instead)",
})
collectors = append(collectors, PolicyImportErrors)
c.PolicyImportErrorsEnabled = true
case Namespace + "_policy_import_errors_total":
PolicyImportErrorsTotal = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_import_errors_total",
Help: "Number of times a policy import has failed",
})
collectors = append(collectors, PolicyImportErrorsTotal)
c.PolicyImportErrorsEnabled = true
case Namespace + "_policy_endpoint_enforcement_status":
PolicyEndpointStatus = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "policy_endpoint_enforcement_status",
Help: "Number of endpoints labeled by policy enforcement status",
}, []string{LabelPolicyEnforcement})
collectors = append(collectors, PolicyEndpointStatus)
c.PolicyEndpointStatusEnabled = true
case Namespace + "_policy_implementation_delay":
PolicyImplementationDelay = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: Namespace,
Name: "policy_implementation_delay",
Help: "Time between a policy change and it being fully deployed into the datapath",
}, []string{LabelPolicySource})
collectors = append(collectors, PolicyImplementationDelay)
c.PolicyImplementationDelayEnabled = true
case Namespace + "_identity":
Identity = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "identity",
Help: "Number of identities currently allocated",
})
collectors = append(collectors, Identity)
c.IdentityCountEnabled = true
case Namespace + "_identity_count":
IdentityCount = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "identity_count",
Help: "Number of identities currently allocated (deprecated, use identity instead)",
})
collectors = append(collectors, IdentityCount)
c.IdentityCountEnabled = true
case Namespace + "_event_ts":
EventTSK8s = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "event_ts",
Help: "Last timestamp when we received an event",
ConstLabels: prometheus.Labels{"source": LabelEventSourceK8s},
})
collectors = append(collectors, EventTSK8s)
c.EventTSK8sEnabled = true
EventLagK8s = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "k8s_event_lag_seconds",
Help: "Lag for Kubernetes events - computed value between receiving a CNI ADD event from kubelet and a Pod event received from kube-api-server",
ConstLabels: prometheus.Labels{"source": LabelEventSourceK8s},
})
collectors = append(collectors, EventLagK8s)
c.EventLagK8sEnabled = true
EventTSContainerd = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "event_ts",
Help: "Last timestamp when we received an event",
ConstLabels: prometheus.Labels{"source": LabelEventSourceContainerd},
})
collectors = append(collectors, EventTSContainerd)
c.EventTSContainerdEnabled = true
EventTSAPI = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "event_ts",
Help: "Last timestamp when we received an event",
ConstLabels: prometheus.Labels{"source": LabelEventSourceAPI},
})
collectors = append(collectors, EventTSAPI)
c.EventTSAPIEnabled = true
case Namespace + "_proxy_redirects":
ProxyRedirects = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "proxy_redirects",
Help: "Number of redirects installed for endpoints, labeled by protocol",
}, []string{LabelProtocolL7})
collectors = append(collectors, ProxyRedirects)
c.ProxyRedirectsEnabled = true
case Namespace + "_policy_l7_total":
ProxyPolicyL7Total = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_l7_total",
Help: "Number of total proxy requests handled",
}, []string{"rule"})
collectors = append(collectors, ProxyPolicyL7Total)
c.ProxyPolicyL7Enabled = true
case Namespace + "_policy_l7_parse_errors_total":
ProxyParseErrors = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_l7_parse_errors_total",
Help: "Number of total L7 parse errors",
})
collectors = append(collectors, ProxyParseErrors)
c.ProxyParseErrorsEnabled = true
case Namespace + "_policy_l7_forwarded_total":
ProxyForwarded = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_l7_forwarded_total",
Help: "Number of total L7 forwarded requests/responses",
})
collectors = append(collectors, ProxyForwarded)
c.ProxyForwardedEnabled = true
case Namespace + "_policy_l7_denied_total":
ProxyDenied = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_l7_denied_total",
Help: "Number of total L7 denied requests/responses due to policy",
})
collectors = append(collectors, ProxyDenied)
c.ProxyDeniedEnabled = true
case Namespace + "_policy_l7_received_total":
ProxyReceived = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "policy_l7_received_total",
Help: "Number of total L7 received requests/responses",
})
collectors = append(collectors, ProxyReceived)
c.ProxyReceivedEnabled = true
case Namespace + "_proxy_upstream_reply_seconds":
ProxyUpstreamTime = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: Namespace,
Name: "proxy_upstream_reply_seconds",
Help: "Seconds waited to get a reply from a upstream server",
}, []string{"error", LabelProtocolL7, LabelScope})
collectors = append(collectors, ProxyUpstreamTime)
c.NoOpObserverVecEnabled = true
case Namespace + "_drop_count_total":
DropCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "drop_count_total",
Help: "Total dropped packets, tagged by drop reason and ingress/egress direction",
},
[]string{"reason", LabelDirection})
collectors = append(collectors, DropCount)
c.DropCountEnabled = true
case Namespace + "_drop_bytes_total":
DropBytes = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "drop_bytes_total",
Help: "Total dropped bytes, tagged by drop reason and ingress/egress direction",
},
[]string{"reason", LabelDirection})
collectors = append(collectors, DropBytes)
c.DropBytesEnabled = true
case Namespace + "_forward_count_total":
ForwardCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "forward_count_total",
Help: "Total forwarded packets, tagged by ingress/egress direction",
},
[]string{LabelDirection})
collectors = append(collectors, ForwardCount)
c.NoOpCounterVecEnabled = true
case Namespace + "_forward_bytes_total":
ForwardBytes = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "forward_bytes_total",
Help: "Total forwarded bytes, tagged by ingress/egress direction",
},
[]string{LabelDirection})
collectors = append(collectors, ForwardBytes)
c.ForwardBytesEnabled = true
case Namespace + "_" + SubsystemDatapath + "_errors_total":
DatapathErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: SubsystemDatapath,
Name: "errors_total",
Help: "Number of errors that occurred in the datapath or datapath management",
}, []string{LabelDatapathArea, LabelDatapathName, LabelDatapathFamily})
collectors = append(collectors, DatapathErrors)
c.DatapathErrorsEnabled = true
case Namespace + "_" + SubsystemDatapath + "_conntrack_gc_runs_total":
ConntrackGCRuns = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: SubsystemDatapath,
Name: "conntrack_gc_runs_total",
Help: "Number of times that the conntrack garbage collector process was run " +
"labeled by completion status",
}, []string{LabelDatapathFamily, LabelProtocol, LabelStatus})
collectors = append(collectors, ConntrackGCRuns)
c.ConntrackGCRunsEnabled = true
case Namespace + "_" + SubsystemDatapath + "_conntrack_gc_key_fallbacks_total":
ConntrackGCKeyFallbacks = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: SubsystemDatapath,
Name: "conntrack_gc_key_fallbacks_total",
Help: "Number of times a key fallback was needed when iterating over the BPF map",
}, []string{LabelDatapathFamily, LabelProtocol})
collectors = append(collectors, ConntrackGCKeyFallbacks)
c.ConntrackGCKeyFallbacksEnabled = true
case Namespace + "_" + SubsystemDatapath + "_conntrack_gc_entries":
ConntrackGCSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: SubsystemDatapath,
Name: "conntrack_gc_entries",
Help: "The number of alive and deleted conntrack entries at the end " +
"of a garbage collector run labeled by datapath family.",
}, []string{LabelDatapathFamily, LabelProtocol, LabelStatus})
collectors = append(collectors, ConntrackGCSize)
c.ConntrackGCSizeEnabled = true
NatGCSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: SubsystemDatapath,
Name: "nat_gc_entries",
Help: "The number of alive and deleted nat entries at the end " +
"of a garbage collector run labeled by datapath family.",
}, []string{LabelDatapathFamily, LabelDirection, LabelStatus})
collectors = append(collectors, NatGCSize)
case Namespace + "_" + SubsystemDatapath + "_conntrack_gc_duration_seconds":