Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3c3c1b11
Unverified
Commit
3c3c1b11
authored
May 28, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 28, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70715 from immutableT/kube-apiserver-metrics
Add transformation_success_total and transformation_last_status metrics.
parents
ec89794c
90c94214
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
138 additions
and
12 deletions
+138
-12
BUILD
staging/src/k8s.io/apiserver/pkg/storage/value/BUILD
+14
-2
metrics.go
staging/src/k8s.io/apiserver/pkg/storage/value/metrics.go
+27
-10
metrics_test.go
...ng/src/k8s.io/apiserver/pkg/storage/value/metrics_test.go
+97
-0
No files found.
staging/src/k8s.io/apiserver/pkg/storage/value/BUILD
View file @
3c3c1b11
...
...
@@ -8,8 +8,17 @@ load(
go_test(
name = "go_default_test",
srcs = ["transformer_test.go"],
srcs = [
"metrics_test.go",
"transformer_test.go",
],
embed = [":go_default_library"],
deps = [
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus/testutil:go_default_library",
"//vendor/google.golang.org/grpc/codes:go_default_library",
"//vendor/google.golang.org/grpc/status:go_default_library",
],
)
go_library(
...
...
@@ -20,7 +29,10 @@ go_library(
],
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/storage/value",
importpath = "k8s.io/apiserver/pkg/storage/value",
deps = ["//vendor/github.com/prometheus/client_golang/prometheus:go_default_library"],
deps = [
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/google.golang.org/grpc/status:go_default_library",
],
)
filegroup(
...
...
staging/src/k8s.io/apiserver/pkg/storage/value/metrics.go
View file @
3c3c1b11
/*
Copyright 201
7
The Kubernetes Authors.
Copyright 201
9
The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
...
...
@@ -20,6 +20,8 @@ import (
"sync"
"time"
"google.golang.org/grpc/status"
"github.com/prometheus/client_golang/prometheus"
)
...
...
@@ -53,12 +55,23 @@ var (
},
[]
string
{
"transformation_type"
},
)
transformerFailuresTotal
=
prometheus
.
NewCounterVec
(
transformerOperationsTotal
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
namespace
,
Subsystem
:
subsystem
,
Name
:
"transformation_operations_total"
,
Help
:
"Total number of transformations."
,
},
[]
string
{
"transformation_type"
,
"status"
},
)
deprecatedTransformerFailuresTotal
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
namespace
,
Subsystem
:
subsystem
,
Name
:
"transformation_failures_total"
,
Help
:
"Total number of failed transformation operations."
,
Help
:
"
(Deprecated)
Total number of failed transformation operations."
,
},
[]
string
{
"transformation_type"
},
)
...
...
@@ -106,7 +119,8 @@ func RegisterMetrics() {
registerMetrics
.
Do
(
func
()
{
prometheus
.
MustRegister
(
transformerLatencies
)
prometheus
.
MustRegister
(
deprecatedTransformerLatencies
)
prometheus
.
MustRegister
(
transformerFailuresTotal
)
prometheus
.
MustRegister
(
transformerOperationsTotal
)
prometheus
.
MustRegister
(
deprecatedTransformerFailuresTotal
)
prometheus
.
MustRegister
(
envelopeTransformationCacheMissTotal
)
prometheus
.
MustRegister
(
dataKeyGenerationLatencies
)
prometheus
.
MustRegister
(
deprecatedDataKeyGenerationLatencies
)
...
...
@@ -115,14 +129,17 @@ func RegisterMetrics() {
}
// RecordTransformation records latencies and count of TransformFromStorage and TransformToStorage operations.
// Note that transformation_failures_total metric is deprecated, use transformation_operations_total instead.
func
RecordTransformation
(
transformationType
string
,
start
time
.
Time
,
err
error
)
{
if
err
!=
nil
{
transformerFailuresTotal
.
WithLabelValues
(
transformationType
)
.
Inc
()
return
transformerOperationsTotal
.
WithLabelValues
(
transformationType
,
status
.
Code
(
err
)
.
String
())
.
Inc
()
switch
{
case
err
==
nil
:
transformerLatencies
.
WithLabelValues
(
transformationType
)
.
Observe
(
sinceInSeconds
(
start
))
deprecatedTransformerLatencies
.
WithLabelValues
(
transformationType
)
.
Observe
(
sinceInMicroseconds
(
start
))
default
:
deprecatedTransformerFailuresTotal
.
WithLabelValues
(
transformationType
)
.
Inc
()
}
transformerLatencies
.
WithLabelValues
(
transformationType
)
.
Observe
(
sinceInSeconds
(
start
))
deprecatedTransformerLatencies
.
WithLabelValues
(
transformationType
)
.
Observe
(
sinceInMicroseconds
(
start
))
}
// RecordCacheMiss records a miss on Key Encryption Key(KEK) - call to KMS was required to decrypt KEK.
...
...
staging/src/k8s.io/apiserver/pkg/storage/value/metrics_test.go
0 → 100644
View file @
3c3c1b11
/*
Copyright 2017 The Kubernetes 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
value
import
(
"errors"
"strings"
"testing"
"time"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)
func
TestTotals
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
desc
string
metrics
[]
string
error
error
want
string
}{
{
desc
:
"non-status error"
,
metrics
:
[]
string
{
"apiserver_storage_transformation_operations_total"
,
"apiserver_storage_transformation_failures_total"
,
},
error
:
errors
.
New
(
"foo"
),
want
:
`
# HELP apiserver_storage_transformation_failures_total (Deprecated) Total number of failed transformation operations.
# TYPE apiserver_storage_transformation_failures_total counter
apiserver_storage_transformation_failures_total{transformation_type="encrypt"} 1
# HELP apiserver_storage_transformation_operations_total Total number of transformations.
# TYPE apiserver_storage_transformation_operations_total counter
apiserver_storage_transformation_operations_total{status="Unknown",transformation_type="encrypt"} 1
`
,
},
{
desc
:
"error is nil"
,
metrics
:
[]
string
{
"apiserver_storage_transformation_operations_total"
,
"apiserver_storage_transformation_failures_total"
,
},
want
:
`
# HELP apiserver_storage_transformation_operations_total Total number of transformations.
# TYPE apiserver_storage_transformation_operations_total counter
apiserver_storage_transformation_operations_total{status="OK",transformation_type="encrypt"} 1
`
,
},
{
desc
:
"status error from kms-plugin"
,
metrics
:
[]
string
{
"apiserver_storage_transformation_operations_total"
,
"apiserver_storage_transformation_failures_total"
,
},
error
:
status
.
Error
(
codes
.
FailedPrecondition
,
"foo"
),
want
:
`
# HELP apiserver_storage_transformation_failures_total (Deprecated) Total number of failed transformation operations.
# TYPE apiserver_storage_transformation_failures_total counter
apiserver_storage_transformation_failures_total{transformation_type="encrypt"} 1
# HELP apiserver_storage_transformation_operations_total Total number of transformations.
# TYPE apiserver_storage_transformation_operations_total counter
apiserver_storage_transformation_operations_total{status="FailedPrecondition",transformation_type="encrypt"} 1
`
,
},
}
RegisterMetrics
()
for
_
,
tt
:=
range
testCases
{
t
.
Run
(
tt
.
desc
,
func
(
t
*
testing
.
T
)
{
RecordTransformation
(
"encrypt"
,
time
.
Now
(),
tt
.
error
)
defer
transformerOperationsTotal
.
Reset
()
defer
deprecatedTransformerFailuresTotal
.
Reset
()
if
err
:=
testutil
.
GatherAndCompare
(
prometheus
.
DefaultGatherer
,
strings
.
NewReader
(
tt
.
want
),
tt
.
metrics
...
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment