mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Add metrics for VMSS and VMSS clients
This commit is contained in:
parent
4a00e26175
commit
e787525d6e
@ -24,7 +24,6 @@ go_library(
|
||||
"azure_instances.go",
|
||||
"azure_loadbalancer.go",
|
||||
"azure_managedDiskController.go",
|
||||
"azure_metrics.go",
|
||||
"azure_ratelimit.go",
|
||||
"azure_routes.go",
|
||||
"azure_standard.go",
|
||||
@ -65,12 +64,11 @@ go_library(
|
||||
"//staging/src/k8s.io/cloud-provider/volume/errors:go_default_library",
|
||||
"//staging/src/k8s.io/cloud-provider/volume/helpers:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/featuregate:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/auth:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssclient:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/metrics:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/retry:go_default_library",
|
||||
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute:go_default_library",
|
||||
"//vendor/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network:go_default_library",
|
||||
@ -95,7 +93,6 @@ go_test(
|
||||
"azure_controller_standard_test.go",
|
||||
"azure_instances_test.go",
|
||||
"azure_loadbalancer_test.go",
|
||||
"azure_metrics_test.go",
|
||||
"azure_ratelimit_test.go",
|
||||
"azure_routes_test.go",
|
||||
"azure_standard_test.go",
|
||||
@ -145,6 +142,7 @@ filegroup(
|
||||
":package-srcs",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/auth:all-srcs",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients:all-srcs",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/metrics:all-srcs",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/retry:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
|
@ -14,6 +14,7 @@ go_library(
|
||||
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/armclient:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/metrics:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/retry:go_default_library",
|
||||
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute:go_default_library",
|
||||
"//vendor/github.com/Azure/go-autorest/autorest:go_default_library",
|
||||
|
@ -33,13 +33,13 @@ import (
|
||||
"k8s.io/klog"
|
||||
azclients "k8s.io/legacy-cloud-providers/azure/clients"
|
||||
"k8s.io/legacy-cloud-providers/azure/clients/armclient"
|
||||
"k8s.io/legacy-cloud-providers/azure/metrics"
|
||||
"k8s.io/legacy-cloud-providers/azure/retry"
|
||||
)
|
||||
|
||||
var _ Interface = &Client{}
|
||||
|
||||
// Client implements VMSS client Interface.
|
||||
// TODO(feiskyer): export prometheus metrics for each API call.
|
||||
type Client struct {
|
||||
armClient armclient.Interface
|
||||
subscriptionID string
|
||||
@ -79,18 +79,23 @@ func New(config *azclients.ClientConfig) *Client {
|
||||
|
||||
// Get gets a VirtualMachineScaleSet.
|
||||
func (c *Client) Get(ctx context.Context, resourceGroupName string, VMScaleSetName string) (compute.VirtualMachineScaleSet, *retry.Error) {
|
||||
mc := metrics.NewMetricContext("vmss", "get", resourceGroupName, c.subscriptionID, "")
|
||||
|
||||
// Report errors if the client is rate limited.
|
||||
if !c.rateLimiterReader.TryAccept() {
|
||||
mc.RateLimitedCount()
|
||||
return compute.VirtualMachineScaleSet{}, retry.GetRateLimitError(false, "VMSSGet")
|
||||
}
|
||||
|
||||
// Report errors if the client is throttled.
|
||||
if c.RetryAfterReader.After(time.Now()) {
|
||||
mc.ThrottledCount()
|
||||
rerr := retry.GetThrottlingError("VMSSGet", "client throttled", c.RetryAfterReader)
|
||||
return compute.VirtualMachineScaleSet{}, rerr
|
||||
}
|
||||
|
||||
result, rerr := c.getVMSS(ctx, resourceGroupName, VMScaleSetName)
|
||||
mc.Observe(rerr.Error())
|
||||
if rerr != nil {
|
||||
if rerr.IsThrottled() {
|
||||
// Update RetryAfterReader so that no more requests would be sent until RetryAfter expires.
|
||||
@ -135,18 +140,23 @@ func (c *Client) getVMSS(ctx context.Context, resourceGroupName string, VMScaleS
|
||||
|
||||
// List gets a list of VirtualMachineScaleSets in the resource group.
|
||||
func (c *Client) List(ctx context.Context, resourceGroupName string) ([]compute.VirtualMachineScaleSet, *retry.Error) {
|
||||
mc := metrics.NewMetricContext("vmss", "list", resourceGroupName, c.subscriptionID, "")
|
||||
|
||||
// Report errors if the client is rate limited.
|
||||
if !c.rateLimiterReader.TryAccept() {
|
||||
mc.RateLimitedCount()
|
||||
return nil, retry.GetRateLimitError(false, "VMSSList")
|
||||
}
|
||||
|
||||
// Report errors if the client is throttled.
|
||||
if c.RetryAfterReader.After(time.Now()) {
|
||||
mc.ThrottledCount()
|
||||
rerr := retry.GetThrottlingError("VMSSList", "client throttled", c.RetryAfterReader)
|
||||
return nil, rerr
|
||||
}
|
||||
|
||||
result, rerr := c.listVMSS(ctx, resourceGroupName)
|
||||
mc.Observe(rerr.Error())
|
||||
if rerr != nil {
|
||||
if rerr.IsThrottled() {
|
||||
// Update RetryAfterReader so that no more requests would be sent until RetryAfter expires.
|
||||
@ -195,18 +205,23 @@ func (c *Client) listVMSS(ctx context.Context, resourceGroupName string) ([]comp
|
||||
|
||||
// CreateOrUpdate creates or updates a VirtualMachineScaleSet.
|
||||
func (c *Client) CreateOrUpdate(ctx context.Context, resourceGroupName string, VMScaleSetName string, parameters compute.VirtualMachineScaleSet) *retry.Error {
|
||||
mc := metrics.NewMetricContext("vmss", "create_or_update", resourceGroupName, c.subscriptionID, "")
|
||||
|
||||
// Report errors if the client is rate limited.
|
||||
if !c.rateLimiterWriter.TryAccept() {
|
||||
mc.RateLimitedCount()
|
||||
return retry.GetRateLimitError(true, "VMSSCreateOrUpdate")
|
||||
}
|
||||
|
||||
// Report errors if the client is throttled.
|
||||
if c.RetryAfterWriter.After(time.Now()) {
|
||||
mc.ThrottledCount()
|
||||
rerr := retry.GetThrottlingError("VMSSCreateOrUpdate", "client throttled", c.RetryAfterWriter)
|
||||
return rerr
|
||||
}
|
||||
|
||||
rerr := c.createOrUpdateVMSS(ctx, resourceGroupName, VMScaleSetName, parameters)
|
||||
mc.Observe(rerr.Error())
|
||||
if rerr != nil {
|
||||
if rerr.IsThrottled() {
|
||||
// Update RetryAfterReader so that no more requests would be sent until RetryAfter expires.
|
||||
|
@ -14,6 +14,7 @@ go_library(
|
||||
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/armclient:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/metrics:go_default_library",
|
||||
"//staging/src/k8s.io/legacy-cloud-providers/azure/retry:go_default_library",
|
||||
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute:go_default_library",
|
||||
"//vendor/github.com/Azure/go-autorest/autorest:go_default_library",
|
||||
|
@ -33,13 +33,13 @@ import (
|
||||
"k8s.io/klog"
|
||||
azclients "k8s.io/legacy-cloud-providers/azure/clients"
|
||||
"k8s.io/legacy-cloud-providers/azure/clients/armclient"
|
||||
"k8s.io/legacy-cloud-providers/azure/metrics"
|
||||
"k8s.io/legacy-cloud-providers/azure/retry"
|
||||
)
|
||||
|
||||
var _ Interface = &Client{}
|
||||
|
||||
// Client implements VMSS client Interface.
|
||||
// TODO(feiskyer): export prometheus metrics for each API call.
|
||||
type Client struct {
|
||||
armClient armclient.Interface
|
||||
subscriptionID string
|
||||
@ -79,18 +79,23 @@ func New(config *azclients.ClientConfig) *Client {
|
||||
|
||||
// Get gets a VirtualMachineScaleSetVM.
|
||||
func (c *Client) Get(ctx context.Context, resourceGroupName string, VMScaleSetName string, instanceID string, expand compute.InstanceViewTypes) (compute.VirtualMachineScaleSetVM, *retry.Error) {
|
||||
mc := metrics.NewMetricContext("vmssvm", "get", resourceGroupName, c.subscriptionID, "")
|
||||
|
||||
// Report errors if the client is rate limited.
|
||||
if !c.rateLimiterReader.TryAccept() {
|
||||
mc.RateLimitedCount()
|
||||
return compute.VirtualMachineScaleSetVM{}, retry.GetRateLimitError(false, "VMSSVMGet")
|
||||
}
|
||||
|
||||
// Report errors if the client is throttled.
|
||||
if c.RetryAfterReader.After(time.Now()) {
|
||||
mc.ThrottledCount()
|
||||
rerr := retry.GetThrottlingError("VMSSVMGet", "client throttled", c.RetryAfterReader)
|
||||
return compute.VirtualMachineScaleSetVM{}, rerr
|
||||
}
|
||||
|
||||
result, rerr := c.getVMSSVM(ctx, resourceGroupName, VMScaleSetName, instanceID, expand)
|
||||
mc.Observe(rerr.Error())
|
||||
if rerr != nil {
|
||||
if rerr.IsThrottled() {
|
||||
// Update RetryAfterReader so that no more requests would be sent until RetryAfter expires.
|
||||
@ -137,18 +142,23 @@ func (c *Client) getVMSSVM(ctx context.Context, resourceGroupName string, VMScal
|
||||
|
||||
// List gets a list of VirtualMachineScaleSetVMs in the virtualMachineScaleSet.
|
||||
func (c *Client) List(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, expand string) ([]compute.VirtualMachineScaleSetVM, *retry.Error) {
|
||||
mc := metrics.NewMetricContext("vmssvm", "list", resourceGroupName, c.subscriptionID, "")
|
||||
|
||||
// Report errors if the client is rate limited.
|
||||
if !c.rateLimiterReader.TryAccept() {
|
||||
mc.RateLimitedCount()
|
||||
return nil, retry.GetRateLimitError(false, "VMSSVMList")
|
||||
}
|
||||
|
||||
// Report errors if the client is throttled.
|
||||
if c.RetryAfterReader.After(time.Now()) {
|
||||
mc.ThrottledCount()
|
||||
rerr := retry.GetThrottlingError("VMSSVMList", "client throttled", c.RetryAfterReader)
|
||||
return nil, rerr
|
||||
}
|
||||
|
||||
result, rerr := c.listVMSSVM(ctx, resourceGroupName, virtualMachineScaleSetName, expand)
|
||||
mc.Observe(rerr.Error())
|
||||
if rerr != nil {
|
||||
if rerr.IsThrottled() {
|
||||
// Update RetryAfterReader so that no more requests would be sent until RetryAfter expires.
|
||||
@ -200,18 +210,23 @@ func (c *Client) listVMSSVM(ctx context.Context, resourceGroupName string, virtu
|
||||
|
||||
// Update updates a VirtualMachineScaleSetVM.
|
||||
func (c *Client) Update(ctx context.Context, resourceGroupName string, VMScaleSetName string, instanceID string, parameters compute.VirtualMachineScaleSetVM, source string) *retry.Error {
|
||||
mc := metrics.NewMetricContext("vmssvm", "update", resourceGroupName, c.subscriptionID, source)
|
||||
|
||||
// Report errors if the client is rate limited.
|
||||
if !c.rateLimiterWriter.TryAccept() {
|
||||
mc.RateLimitedCount()
|
||||
return retry.GetRateLimitError(true, "VMSSVMUpdate")
|
||||
}
|
||||
|
||||
// Report errors if the client is throttled.
|
||||
if c.RetryAfterWriter.After(time.Now()) {
|
||||
mc.ThrottledCount()
|
||||
rerr := retry.GetThrottlingError("VMSSVMUpdate", "client throttled", c.RetryAfterWriter)
|
||||
return rerr
|
||||
}
|
||||
|
||||
rerr := c.updateVMSSVM(ctx, resourceGroupName, VMScaleSetName, instanceID, parameters)
|
||||
mc.Observe(rerr.Error())
|
||||
if rerr != nil {
|
||||
if rerr.IsThrottled() {
|
||||
// Update RetryAfterReader so that no more requests would be sent until RetryAfter expires.
|
||||
|
@ -0,0 +1,37 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"azure_metrics.go",
|
||||
"doc.go",
|
||||
],
|
||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/legacy-cloud-providers/azure/metrics",
|
||||
importpath = "k8s.io/legacy-cloud-providers/azure/metrics",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//staging/src/k8s.io/component-base/metrics:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["azure_metrics_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//vendor/github.com/stretchr/testify/assert:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -1842,6 +1842,7 @@ k8s.io/legacy-cloud-providers/azure/clients
|
||||
k8s.io/legacy-cloud-providers/azure/clients/armclient
|
||||
k8s.io/legacy-cloud-providers/azure/clients/vmssclient
|
||||
k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient
|
||||
k8s.io/legacy-cloud-providers/azure/metrics
|
||||
k8s.io/legacy-cloud-providers/azure/retry
|
||||
k8s.io/legacy-cloud-providers/gce
|
||||
k8s.io/legacy-cloud-providers/openstack
|
||||
|
Loading…
Reference in New Issue
Block a user