-
Notifications
You must be signed in to change notification settings - Fork 140
/
monitoring.go
105 lines (90 loc) · 2.91 KB
/
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
// Copyright Aeraki Authors
//
// 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 server
import (
"strconv"
"istio.io/istio/pkg/kube"
"istio.io/pkg/monitoring"
)
const (
group = "group"
version = "version"
resourceTag = "resource"
reason = "reason"
status = "status"
)
var (
// GroupTag holds the resource group for the context.
GroupTag = monitoring.MustCreateLabel(group)
// VersionTag holds the resource version for the context.
VersionTag = monitoring.MustCreateLabel(version)
// ResourceTag holds the resource name for the context.
ResourceTag = monitoring.MustCreateLabel(resourceTag)
// ReasonTag holds the error reason for the context.
ReasonTag = monitoring.MustCreateLabel(reason)
// StatusTag holds the error code for the context.
StatusTag = monitoring.MustCreateLabel(status)
)
var (
metricValidationPassed = monitoring.NewSum(
"galley/validation/passed",
"Resource is valid",
monitoring.WithLabels(GroupTag, VersionTag, ResourceTag),
)
metricValidationFailed = monitoring.NewSum(
"galley/validation/failed",
"Resource validation failed",
monitoring.WithLabels(GroupTag, VersionTag, ResourceTag, ReasonTag),
)
metricValidationHTTPError = monitoring.NewSum(
"galley/validation/http_error",
"Resource validation http serve errors",
monitoring.WithLabels(StatusTag),
)
)
// nolint: gochecknoinits
func init() {
monitoring.MustRegister(
metricValidationPassed,
metricValidationFailed,
metricValidationHTTPError,
)
}
func reportValidationFailed(request *kube.AdmissionRequest, reason string) {
metricValidationFailed.
With(GroupTag.Value(request.Resource.Group)).
With(VersionTag.Value(request.Resource.Version)).
With(ResourceTag.Value(request.Resource.Resource)).
With(ReasonTag.Value(reason)).
Increment()
}
func reportValidationPass(request *kube.AdmissionRequest) {
metricValidationPassed.
With(GroupTag.Value(request.Resource.Group)).
With(VersionTag.Value(request.Resource.Version)).
With(ResourceTag.Value(request.Resource.Resource)).
Increment()
}
func reportValidationHTTPError(status int) {
metricValidationHTTPError.
With(StatusTag.Value(strconv.Itoa(status))).
Increment()
}
const (
reasonUnsupportedOperation = "unsupported_operation"
reasonYamlDecodeError = "yaml_decode_error"
reasonUnknownType = "unknown_type"
reasonCRDConversionError = "crd_conversion_error"
reasonInvalidConfig = "invalid_resource"
)