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
b62c8bca
Commit
b62c8bca
authored
Mar 07, 2019
by
Mehdy Bohlool
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latency metric for CR Webhook Conversion
parent
094eb614
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
1 deletion
+96
-1
converter.go
...xtensions-apiserver/pkg/apiserver/conversion/converter.go
+8
-1
metrics.go
...iextensions-apiserver/pkg/apiserver/conversion/metrics.go
+88
-0
No files found.
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/converter.go
View file @
b62c8bca
...
...
@@ -33,11 +33,14 @@ type CRConverterFactory struct {
// webhookConverterFactory is the factory for webhook converters.
// This field should not be used if CustomResourceWebhookConversion feature is disabled.
webhookConverterFactory
*
webhookConverterFactory
converterMetricFactory
*
converterMetricFactory
}
// NewCRConverterFactory creates a new CRConverterFactory
func
NewCRConverterFactory
(
serviceResolver
webhook
.
ServiceResolver
,
authResolverWrapper
webhook
.
AuthenticationInfoResolverWrapper
)
(
*
CRConverterFactory
,
error
)
{
converterFactory
:=
&
CRConverterFactory
{}
converterFactory
:=
&
CRConverterFactory
{
converterMetricFactory
:
newConverterMertricFactory
(),
}
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
apiextensionsfeatures
.
CustomResourceWebhookConversion
)
{
webhookConverterFactory
,
err
:=
newWebhookConverterFactory
(
serviceResolver
,
authResolverWrapper
)
if
err
!=
nil
{
...
...
@@ -67,6 +70,10 @@ func (m *CRConverterFactory) NewConverter(crd *apiextensions.CustomResourceDefin
if
err
!=
nil
{
return
nil
,
nil
,
err
}
converter
,
err
=
m
.
converterMetricFactory
.
addMetrics
(
"webhook"
,
crd
.
Name
,
converter
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
default
:
return
nil
,
nil
,
fmt
.
Errorf
(
"unknown conversion strategy %q for CRD %s"
,
crd
.
Spec
.
Conversion
.
Strategy
,
crd
.
Name
)
}
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/metrics.go
0 → 100644
View file @
b62c8bca
/*
Copyright 2019 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
conversion
import
(
"fmt"
"strconv"
"sync"
"time"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var
(
latencyBuckets
=
prometheus
.
ExponentialBuckets
(
0.001
,
2
,
15
)
)
// converterMetricFactory holds metrics for all CRD converters
type
converterMetricFactory
struct
{
// A map from a converter name to it's metric. Allows the converterMetric to be created
// again with the same metric for a specific converter (e.g. 'webhook').
durations
map
[
string
]
*
prometheus
.
HistogramVec
factoryLock
sync
.
Mutex
}
func
newConverterMertricFactory
()
*
converterMetricFactory
{
return
&
converterMetricFactory
{
durations
:
map
[
string
]
*
prometheus
.
HistogramVec
{},
factoryLock
:
sync
.
Mutex
{}}
}
var
_
crConverterInterface
=
&
converterMetric
{}
type
converterMetric
struct
{
delegate
crConverterInterface
latencies
*
prometheus
.
HistogramVec
crdName
string
}
func
(
c
*
converterMetricFactory
)
addMetrics
(
converterName
string
,
crdName
string
,
converter
crConverterInterface
)
(
crConverterInterface
,
error
)
{
c
.
factoryLock
.
Lock
()
defer
c
.
factoryLock
.
Unlock
()
metric
,
exists
:=
c
.
durations
[
converterName
]
if
!
exists
{
metric
=
prometheus
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Name
:
fmt
.
Sprintf
(
"apiserver_crd_%s_conversion_duration_seconds"
,
converterName
),
Help
:
fmt
.
Sprintf
(
"CRD %s conversion duration in seconds"
,
converterName
),
Buckets
:
latencyBuckets
,
},
[]
string
{
"crd_name"
,
"from_version"
,
"to_version"
,
"succeeded"
})
err
:=
prometheus
.
Register
(
metric
)
if
err
!=
nil
{
return
nil
,
err
}
c
.
durations
[
converterName
]
=
metric
}
return
&
converterMetric
{
latencies
:
metric
,
delegate
:
converter
,
crdName
:
crdName
},
nil
}
func
(
m
*
converterMetric
)
Convert
(
in
runtime
.
Object
,
targetGV
schema
.
GroupVersion
)
(
runtime
.
Object
,
error
)
{
start
:=
time
.
Now
()
obj
,
err
:=
m
.
delegate
.
Convert
(
in
,
targetGV
)
fromVersion
:=
in
.
GetObjectKind
()
.
GroupVersionKind
()
.
Version
toVersion
:=
targetGV
.
Version
// only record this observation if the version is different
if
fromVersion
!=
toVersion
{
m
.
latencies
.
WithLabelValues
(
m
.
crdName
,
fromVersion
,
toVersion
,
strconv
.
FormatBool
(
err
==
nil
))
.
Observe
(
time
.
Since
(
start
)
.
Seconds
())
}
return
obj
,
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