mirror of https://github.com/k3s-io/k3s
Fix golint in test/e2e/instrumentation/monitoring
parent
79e8a29544
commit
873fbf9112
|
@ -646,7 +646,6 @@ test/e2e/framework
|
|||
test/e2e/framework/providers/gce
|
||||
test/e2e/framework/providers/kubemark
|
||||
test/e2e/instrumentation/logging
|
||||
test/e2e/instrumentation/monitoring
|
||||
test/e2e/lifecycle
|
||||
test/e2e/lifecycle/bootstrap
|
||||
test/e2e/network
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
"github.com/onsi/ginkgo"
|
||||
"golang.org/x/oauth2/google"
|
||||
gcm "google.golang.org/api/monitoring/v3"
|
||||
"k8s.io/api/core/v1"
|
||||
|
@ -43,20 +43,20 @@ var acceleratorMetrics = []string{
|
|||
}
|
||||
|
||||
var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
framework.SkipUnlessProviderIs("gce", "gke")
|
||||
})
|
||||
|
||||
f := framework.NewDefaultFramework("stackdriver-monitoring")
|
||||
|
||||
It("should have accelerator metrics [Feature:StackdriverAcceleratorMonitoring]", func() {
|
||||
ginkgo.It("should have accelerator metrics [Feature:StackdriverAcceleratorMonitoring]", func() {
|
||||
testStackdriverAcceleratorMonitoring(f)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
func testStackdriverAcceleratorMonitoring(f *framework.Framework) {
|
||||
projectId := framework.TestContext.CloudConfig.ProjectID
|
||||
projectID := framework.TestContext.CloudConfig.ProjectID
|
||||
|
||||
ctx := context.Background()
|
||||
client, err := google.DefaultClient(ctx, gcm.CloudPlatformScope)
|
||||
|
@ -97,7 +97,7 @@ func testStackdriverAcceleratorMonitoring(f *framework.Framework) {
|
|||
})
|
||||
|
||||
metricsMap := map[string]bool{}
|
||||
pollingFunction := checkForAcceleratorMetrics(projectId, gcmService, time.Now(), metricsMap)
|
||||
pollingFunction := checkForAcceleratorMetrics(projectID, gcmService, time.Now(), metricsMap)
|
||||
err = wait.Poll(pollFrequency, pollTimeout, pollingFunction)
|
||||
if err != nil {
|
||||
framework.Logf("Missing metrics: %+v", metricsMap)
|
||||
|
@ -105,7 +105,7 @@ func testStackdriverAcceleratorMonitoring(f *framework.Framework) {
|
|||
framework.ExpectNoError(err)
|
||||
}
|
||||
|
||||
func checkForAcceleratorMetrics(projectId string, gcmService *gcm.Service, start time.Time, metricsMap map[string]bool) func() (bool, error) {
|
||||
func checkForAcceleratorMetrics(projectID string, gcmService *gcm.Service, start time.Time, metricsMap map[string]bool) func() (bool, error) {
|
||||
return func() (bool, error) {
|
||||
counter := 0
|
||||
for _, metric := range acceleratorMetrics {
|
||||
|
@ -113,7 +113,7 @@ func checkForAcceleratorMetrics(projectId string, gcmService *gcm.Service, start
|
|||
}
|
||||
for _, metric := range acceleratorMetrics {
|
||||
// TODO: check only for metrics from this cluster
|
||||
ts, err := fetchTimeSeries(projectId, gcmService, metric, start, time.Now())
|
||||
ts, err := fetchTimeSeries(projectID, gcmService, metric, start, time.Now())
|
||||
framework.ExpectNoError(err)
|
||||
if len(ts) > 0 {
|
||||
counter = counter + 1
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
"k8s.io/kubernetes/test/e2e/framework/config"
|
||||
instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
"github.com/onsi/ginkgo"
|
||||
)
|
||||
|
||||
var cadvisor struct {
|
||||
|
@ -39,14 +39,15 @@ var _ = instrumentation.SIGDescribe("Cadvisor", func() {
|
|||
|
||||
f := framework.NewDefaultFramework("cadvisor")
|
||||
|
||||
It("should be healthy on every node.", func() {
|
||||
ginkgo.It("should be healthy on every node.", func() {
|
||||
CheckCadvisorHealthOnAllNodes(f.ClientSet, 5*time.Minute)
|
||||
})
|
||||
})
|
||||
|
||||
// CheckCadvisorHealthOnAllNodes check cadvisor health via kubelet endpoint
|
||||
func CheckCadvisorHealthOnAllNodes(c clientset.Interface, timeout time.Duration) {
|
||||
// It should be OK to list unschedulable Nodes here.
|
||||
By("getting list of nodes")
|
||||
ginkgo.By("getting list of nodes")
|
||||
nodeList, err := c.CoreV1().Nodes().List(metav1.ListOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
var errors []error
|
||||
|
@ -58,7 +59,7 @@ func CheckCadvisorHealthOnAllNodes(c clientset.Interface, timeout time.Duration)
|
|||
// cadvisor is not accessible directly unless its port (4194 by default) is exposed.
|
||||
// Here, we access '/stats/' REST endpoint on the kubelet which polls cadvisor internally.
|
||||
statsResource := fmt.Sprintf("api/v1/nodes/%s/proxy/stats/", node.Name)
|
||||
By(fmt.Sprintf("Querying stats from node %s using url %s", node.Name, statsResource))
|
||||
ginkgo.By(fmt.Sprintf("Querying stats from node %s using url %s", node.Name, statsResource))
|
||||
_, err = c.CoreV1().RESTClient().Get().AbsPath(statsResource).Timeout(timeout).Do().Raw()
|
||||
if err != nil {
|
||||
errors = append(errors, err)
|
||||
|
|
|
@ -18,9 +18,8 @@ package monitoring
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
gcm "google.golang.org/api/monitoring/v3"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
|
@ -31,10 +30,15 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
CustomMetricName = "foo"
|
||||
UnusedMetricName = "unused"
|
||||
CustomMetricValue = int64(448)
|
||||
UnusedMetricValue = int64(446)
|
||||
// CustomMetricName is the metrics name used in test cases.
|
||||
CustomMetricName = "foo"
|
||||
// UnusedMetricName is the unused metrics name used in test cases.
|
||||
UnusedMetricName = "unused"
|
||||
// CustomMetricValue is the value for CustomMetricName.
|
||||
CustomMetricValue = int64(448)
|
||||
// UnusedMetricValue is the value for UnusedMetricName.
|
||||
UnusedMetricValue = int64(446)
|
||||
// StackdriverExporter is exporter name.
|
||||
StackdriverExporter = "stackdriver-exporter"
|
||||
// HPAPermissions is a ClusterRoleBinding that grants unauthenticated user permissions granted for
|
||||
// HPA for testing purposes, i.e. it should grant permission to read custom metrics.
|
||||
|
@ -55,11 +59,16 @@ var (
|
|||
},
|
||||
},
|
||||
}
|
||||
// StagingDeploymentsLocation is the location where the adapter deployment files are stored.
|
||||
StagingDeploymentsLocation = "https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/staging/"
|
||||
// AdapterForOldResourceModel is file name for the old resource model.
|
||||
AdapterForOldResourceModel = "adapter_old_resource_model.yaml"
|
||||
// AdapterForNewResourceModel is file name for the new resource model.
|
||||
AdapterForNewResourceModel = "adapter_new_resource_model.yaml"
|
||||
AdapterDefault = AdapterForOldResourceModel
|
||||
ClusterAdminBinding = "e2e-test-cluster-admin-binding"
|
||||
// AdapterDefault is the default model.
|
||||
AdapterDefault = AdapterForOldResourceModel
|
||||
// ClusterAdminBinding is the cluster rolebinding name for test cases.
|
||||
ClusterAdminBinding = "e2e-test-cluster-admin-binding"
|
||||
)
|
||||
|
||||
// CustomMetricContainerSpec allows to specify a config for StackdriverExporterDeployment
|
||||
|
@ -273,8 +282,8 @@ func createClusterAdminBinding() error {
|
|||
}
|
||||
|
||||
// CreateDescriptors creates descriptors for metrics: CustomMetricName and UnusedMetricName.
|
||||
func CreateDescriptors(service *gcm.Service, projectId string) error {
|
||||
_, err := service.Projects.MetricDescriptors.Create(fmt.Sprintf("projects/%s", projectId), &gcm.MetricDescriptor{
|
||||
func CreateDescriptors(service *gcm.Service, projectID string) error {
|
||||
_, err := service.Projects.MetricDescriptors.Create(fmt.Sprintf("projects/%s", projectID), &gcm.MetricDescriptor{
|
||||
Name: CustomMetricName,
|
||||
ValueType: "INT64",
|
||||
Type: "custom.googleapis.com/" + CustomMetricName,
|
||||
|
@ -283,7 +292,7 @@ func CreateDescriptors(service *gcm.Service, projectId string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = service.Projects.MetricDescriptors.Create(fmt.Sprintf("projects/%s", projectId), &gcm.MetricDescriptor{
|
||||
_, err = service.Projects.MetricDescriptors.Create(fmt.Sprintf("projects/%s", projectID), &gcm.MetricDescriptor{
|
||||
Name: UnusedMetricName,
|
||||
ValueType: "INT64",
|
||||
Type: "custom.googleapis.com/" + UnusedMetricName,
|
||||
|
@ -294,12 +303,12 @@ func CreateDescriptors(service *gcm.Service, projectId string) error {
|
|||
|
||||
// CleanupDescriptors deletes descriptors for metrics: CustomMetricName and UnusedMetricName.
|
||||
// TODO: Cleanup time series as well
|
||||
func CleanupDescriptors(service *gcm.Service, projectId string) {
|
||||
_, err := service.Projects.MetricDescriptors.Delete(fmt.Sprintf("projects/%s/metricDescriptors/custom.googleapis.com/%s", projectId, CustomMetricName)).Do()
|
||||
func CleanupDescriptors(service *gcm.Service, projectID string) {
|
||||
_, err := service.Projects.MetricDescriptors.Delete(fmt.Sprintf("projects/%s/metricDescriptors/custom.googleapis.com/%s", projectID, CustomMetricName)).Do()
|
||||
if err != nil {
|
||||
framework.Logf("Failed to delete descriptor for metric '%s': %v", CustomMetricName, err)
|
||||
}
|
||||
_, err = service.Projects.MetricDescriptors.Delete(fmt.Sprintf("projects/%s/metricDescriptors/custom.googleapis.com/%s", projectId, UnusedMetricName)).Do()
|
||||
_, err = service.Projects.MetricDescriptors.Delete(fmt.Sprintf("projects/%s/metricDescriptors/custom.googleapis.com/%s", projectID, UnusedMetricName)).Do()
|
||||
if err != nil {
|
||||
framework.Logf("Failed to delete descriptor for metric '%s': %v", CustomMetricName, err)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
"golang.org/x/oauth2/google"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
"github.com/onsi/ginkgo"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common"
|
||||
|
||||
|
@ -47,13 +47,13 @@ const (
|
|||
)
|
||||
|
||||
var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
framework.SkipUnlessProviderIs("gce", "gke")
|
||||
})
|
||||
|
||||
f := framework.NewDefaultFramework("stackdriver-monitoring")
|
||||
|
||||
It("should run Custom Metrics - Stackdriver Adapter for old resource model [Feature:StackdriverCustomMetrics]", func() {
|
||||
ginkgo.It("should run Custom Metrics - Stackdriver Adapter for old resource model [Feature:StackdriverCustomMetrics]", func() {
|
||||
kubeClient := f.ClientSet
|
||||
config, err := framework.LoadConfig()
|
||||
if err != nil {
|
||||
|
@ -68,7 +68,7 @@ var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
|
|||
testCustomMetrics(f, kubeClient, customMetricsClient, discoveryClient, AdapterForOldResourceModel)
|
||||
})
|
||||
|
||||
It("should run Custom Metrics - Stackdriver Adapter for new resource model [Feature:StackdriverCustomMetrics]", func() {
|
||||
ginkgo.It("should run Custom Metrics - Stackdriver Adapter for new resource model [Feature:StackdriverCustomMetrics]", func() {
|
||||
kubeClient := f.ClientSet
|
||||
config, err := framework.LoadConfig()
|
||||
if err != nil {
|
||||
|
@ -83,7 +83,7 @@ var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
|
|||
testCustomMetrics(f, kubeClient, customMetricsClient, discoveryClient, AdapterForNewResourceModel)
|
||||
})
|
||||
|
||||
It("should run Custom Metrics - Stackdriver Adapter for external metrics [Feature:StackdriverExternalMetrics]", func() {
|
||||
ginkgo.It("should run Custom Metrics - Stackdriver Adapter for external metrics [Feature:StackdriverExternalMetrics]", func() {
|
||||
kubeClient := f.ClientSet
|
||||
config, err := framework.LoadConfig()
|
||||
if err != nil {
|
||||
|
@ -95,7 +95,7 @@ var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
|
|||
})
|
||||
|
||||
func testCustomMetrics(f *framework.Framework, kubeClient clientset.Interface, customMetricsClient customclient.CustomMetricsClient, discoveryClient *discovery.DiscoveryClient, adapterDeployment string) {
|
||||
projectId := framework.TestContext.CloudConfig.ProjectID
|
||||
projectID := framework.TestContext.CloudConfig.ProjectID
|
||||
|
||||
ctx := context.Background()
|
||||
client, err := google.DefaultClient(ctx, gcm.CloudPlatformScope)
|
||||
|
@ -106,11 +106,11 @@ func testCustomMetrics(f *framework.Framework, kubeClient clientset.Interface, c
|
|||
}
|
||||
|
||||
// Set up a cluster: create a custom metric and set up k8s-sd adapter
|
||||
err = CreateDescriptors(gcmService, projectId)
|
||||
err = CreateDescriptors(gcmService, projectID)
|
||||
if err != nil {
|
||||
framework.Failf("Failed to create metric descriptor: %s", err)
|
||||
}
|
||||
defer CleanupDescriptors(gcmService, projectId)
|
||||
defer CleanupDescriptors(gcmService, projectID)
|
||||
|
||||
err = CreateAdapter(adapterDeployment)
|
||||
if err != nil {
|
||||
|
@ -141,7 +141,7 @@ func testCustomMetrics(f *framework.Framework, kubeClient clientset.Interface, c
|
|||
|
||||
// TODO(kawych): migrate this test to new resource model
|
||||
func testExternalMetrics(f *framework.Framework, kubeClient clientset.Interface, externalMetricsClient externalclient.ExternalMetricsClient) {
|
||||
projectId := framework.TestContext.CloudConfig.ProjectID
|
||||
projectID := framework.TestContext.CloudConfig.ProjectID
|
||||
|
||||
ctx := context.Background()
|
||||
client, err := google.DefaultClient(ctx, gcm.CloudPlatformScope)
|
||||
|
@ -152,11 +152,11 @@ func testExternalMetrics(f *framework.Framework, kubeClient clientset.Interface,
|
|||
}
|
||||
|
||||
// Set up a cluster: create a custom metric and set up k8s-sd adapter
|
||||
err = CreateDescriptors(gcmService, projectId)
|
||||
err = CreateDescriptors(gcmService, projectID)
|
||||
if err != nil {
|
||||
framework.Failf("Failed to create metric descriptor: %s", err)
|
||||
}
|
||||
defer CleanupDescriptors(gcmService, projectId)
|
||||
defer CleanupDescriptors(gcmService, projectID)
|
||||
|
||||
// Both deployments - for old and new resource model - expose External Metrics API.
|
||||
err = CreateAdapter(AdapterForOldResourceModel)
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
"github.com/onsi/ginkgo"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/test/e2e/common"
|
||||
|
@ -47,24 +47,24 @@ const (
|
|||
)
|
||||
|
||||
var _ = instrumentation.SIGDescribe("[Feature:PrometheusMonitoring] Prometheus", func() {
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
framework.SkipUnlessPrometheusMonitoringIsEnabled()
|
||||
})
|
||||
|
||||
f := framework.NewDefaultFramework("prometheus-monitoring")
|
||||
It("should scrape container metrics from all nodes.", func() {
|
||||
ginkgo.It("should scrape container metrics from all nodes.", func() {
|
||||
expectedNodes, err := getAllNodes(f.ClientSet)
|
||||
framework.ExpectNoError(err)
|
||||
retryUntilSucceeds(func() error {
|
||||
return validateMetricAvailableForAllNodes(f.ClientSet, `container_cpu_usage_seconds_total`, expectedNodes)
|
||||
}, prometheusTestTimeout)
|
||||
})
|
||||
It("should successfully scrape all targets", func() {
|
||||
ginkgo.It("should successfully scrape all targets", func() {
|
||||
retryUntilSucceeds(func() error {
|
||||
return validateAllActiveTargetsAreHealthy(f.ClientSet)
|
||||
}, prometheusTestTimeout)
|
||||
})
|
||||
It("should contain correct container CPU metric.", func() {
|
||||
ginkgo.It("should contain correct container CPU metric.", func() {
|
||||
query := prometheusCPUQuery(f.Namespace.Name, "prometheus-cpu-consumer", prometheusRate)
|
||||
consumer := consumeCPUResources(f, "prometheus-cpu-consumer", targetCPUUsage*1000)
|
||||
defer consumer.CleanUp()
|
||||
|
@ -72,7 +72,7 @@ var _ = instrumentation.SIGDescribe("[Feature:PrometheusMonitoring] Prometheus",
|
|||
return validateQueryReturnsCorrectValues(f.ClientSet, query, targetCPUUsage, 3, prometheusMetricErrorTolerance)
|
||||
}, prometheusTestTimeout)
|
||||
})
|
||||
It("should scrape metrics from annotated pods.", func() {
|
||||
ginkgo.It("should scrape metrics from annotated pods.", func() {
|
||||
query := prometheusPodCustomMetricQuery(f.Namespace.Name, "prometheus-custom-pod-metric")
|
||||
consumer := exportCustomMetricFromPod(f, "prometheus-custom-pod-metric", customMetricValue)
|
||||
defer consumer.CleanUp()
|
||||
|
@ -80,7 +80,7 @@ var _ = instrumentation.SIGDescribe("[Feature:PrometheusMonitoring] Prometheus",
|
|||
return validateQueryReturnsCorrectValues(f.ClientSet, query, customMetricValue, 1, prometheusMetricErrorTolerance)
|
||||
}, prometheusTestTimeout)
|
||||
})
|
||||
It("should scrape metrics from annotated services.", func() {
|
||||
ginkgo.It("should scrape metrics from annotated services.", func() {
|
||||
query := prometheusServiceCustomMetricQuery(f.Namespace.Name, "prometheus-custom-service-metric")
|
||||
consumer := exportCustomMetricFromService(f, "prometheus-custom-service-metric", customMetricValue)
|
||||
defer consumer.CleanUp()
|
||||
|
@ -251,10 +251,13 @@ type promTargetsResponse struct {
|
|||
Data TargetDiscovery `json:"data"`
|
||||
}
|
||||
|
||||
// TargetDiscovery has all the active targets.
|
||||
type TargetDiscovery struct {
|
||||
ActiveTargets []*Target `json:"activeTargets"`
|
||||
DroppedTargets []*DroppedTarget `json:"droppedTargets"`
|
||||
}
|
||||
|
||||
// Target has the information for one target.
|
||||
type Target struct {
|
||||
DiscoveredLabels map[string]string `json:"discoveredLabels"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
|
@ -266,17 +269,20 @@ type Target struct {
|
|||
Health TargetHealth `json:"health"`
|
||||
}
|
||||
|
||||
// DroppedTarget has the information for one target that was dropped during relabelling.
|
||||
type DroppedTarget struct {
|
||||
// Labels before any processing.
|
||||
DiscoveredLabels map[string]string `json:"discoveredLabels"`
|
||||
}
|
||||
|
||||
// The possible health states of a target based on the last performed scrape.
|
||||
const (
|
||||
HealthUnknown TargetHealth = "unknown"
|
||||
HealthGood TargetHealth = "up"
|
||||
HealthBad TargetHealth = "down"
|
||||
)
|
||||
|
||||
// TargetHealth describes the health state of a target.
|
||||
type TargetHealth string
|
||||
|
||||
func queryPrometheus(c clientset.Interface, query string, start, end time.Time, step time.Duration) (model.Value, error) {
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
"golang.org/x/oauth2/google"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
"github.com/onsi/ginkgo"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/kubernetes/test/e2e/common"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
|
@ -59,20 +59,20 @@ var (
|
|||
)
|
||||
|
||||
var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
framework.SkipUnlessProviderIs("gce", "gke")
|
||||
})
|
||||
|
||||
f := framework.NewDefaultFramework("stackdriver-monitoring")
|
||||
|
||||
It("should have cluster metrics [Feature:StackdriverMonitoring]", func() {
|
||||
ginkgo.It("should have cluster metrics [Feature:StackdriverMonitoring]", func() {
|
||||
testStackdriverMonitoring(f, 1, 100, 200)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
func testStackdriverMonitoring(f *framework.Framework, pods, allPodsCPU int, perPodCPU int64) {
|
||||
projectId := framework.TestContext.CloudConfig.ProjectID
|
||||
projectID := framework.TestContext.CloudConfig.ProjectID
|
||||
|
||||
ctx := context.Background()
|
||||
client, err := google.DefaultClient(ctx, gcm.CloudPlatformScope)
|
||||
|
@ -107,7 +107,7 @@ func testStackdriverMonitoring(f *framework.Framework, pods, allPodsCPU int, per
|
|||
rc.WaitForReplicas(pods, 15*time.Minute)
|
||||
|
||||
metricsMap := map[string]bool{}
|
||||
pollingFunction := checkForMetrics(projectId, gcmService, time.Now(), metricsMap, allPodsCPU, perPodCPU)
|
||||
pollingFunction := checkForMetrics(projectID, gcmService, time.Now(), metricsMap, allPodsCPU, perPodCPU)
|
||||
err = wait.Poll(pollFrequency, pollTimeout, pollingFunction)
|
||||
if err != nil {
|
||||
framework.Logf("Missing metrics: %+v\n", metricsMap)
|
||||
|
@ -115,7 +115,7 @@ func testStackdriverMonitoring(f *framework.Framework, pods, allPodsCPU int, per
|
|||
framework.ExpectNoError(err)
|
||||
}
|
||||
|
||||
func checkForMetrics(projectId string, gcmService *gcm.Service, start time.Time, metricsMap map[string]bool, cpuUsed int, cpuLimit int64) func() (bool, error) {
|
||||
func checkForMetrics(projectID string, gcmService *gcm.Service, start time.Time, metricsMap map[string]bool, cpuUsed int, cpuLimit int64) func() (bool, error) {
|
||||
return func() (bool, error) {
|
||||
counter := 0
|
||||
correctUtilization := false
|
||||
|
@ -124,7 +124,7 @@ func checkForMetrics(projectId string, gcmService *gcm.Service, start time.Time,
|
|||
}
|
||||
for _, metric := range stackdriverMetrics {
|
||||
// TODO: check only for metrics from this cluster
|
||||
ts, err := fetchTimeSeries(projectId, gcmService, metric, start, time.Now())
|
||||
ts, err := fetchTimeSeries(projectID, gcmService, metric, start, time.Now())
|
||||
framework.ExpectNoError(err)
|
||||
if len(ts) > 0 {
|
||||
counter = counter + 1
|
||||
|
@ -134,7 +134,7 @@ func checkForMetrics(projectId string, gcmService *gcm.Service, start time.Time,
|
|||
framework.Logf("No timeseries for metric %v\n", metric)
|
||||
}
|
||||
|
||||
var sum float64 = 0
|
||||
var sum float64
|
||||
switch metric {
|
||||
case "cpu/utilization":
|
||||
for _, t := range ts {
|
||||
|
@ -154,9 +154,8 @@ func checkForMetrics(projectId string, gcmService *gcm.Service, start time.Time,
|
|||
framework.Logf("Most recent cpu/utilization sum*cpu/limit: %v\n", sum*float64(cpuLimit))
|
||||
if math.Abs(sum*float64(cpuLimit)-float64(cpuUsed)) > tolerance*float64(cpuUsed) {
|
||||
return false, nil
|
||||
} else {
|
||||
correctUtilization = true
|
||||
}
|
||||
correctUtilization = true
|
||||
}
|
||||
}
|
||||
if counter < 9 || !correctUtilization {
|
||||
|
@ -166,14 +165,14 @@ func checkForMetrics(projectId string, gcmService *gcm.Service, start time.Time,
|
|||
}
|
||||
}
|
||||
|
||||
func createMetricFilter(metric string, container_name string) string {
|
||||
func createMetricFilter(metric string, containerName string) string {
|
||||
return fmt.Sprintf(`metric.type="container.googleapis.com/container/%s" AND
|
||||
resource.label.container_name="%s"`, metric, container_name)
|
||||
resource.label.container_name="%s"`, metric, containerName)
|
||||
}
|
||||
|
||||
func fetchTimeSeries(projectId string, gcmService *gcm.Service, metric string, start time.Time, end time.Time) ([]*gcm.TimeSeries, error) {
|
||||
func fetchTimeSeries(projectID string, gcmService *gcm.Service, metric string, start time.Time, end time.Time) ([]*gcm.TimeSeries, error) {
|
||||
response, err := gcmService.Projects.TimeSeries.
|
||||
List(fullProjectName(projectId)).
|
||||
List(fullProjectName(projectID)).
|
||||
Filter(createMetricFilter(metric, rcName)).
|
||||
IntervalStartTime(start.Format(time.RFC3339)).
|
||||
IntervalEndTime(end.Format(time.RFC3339)).
|
||||
|
|
|
@ -17,52 +17,51 @@ limitations under the License.
|
|||
package monitoring
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/oauth2/google"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
. "github.com/onsi/ginkgo"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
"golang.org/x/oauth2/google"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
// Time to wait after a pod creation for it's metadata to be exported
|
||||
metadataWaitTime = 120 * time.Second
|
||||
|
||||
// Scope for Stackdriver Metadata API
|
||||
// MonitoringScope is the scope for Stackdriver Metadata API
|
||||
MonitoringScope = "https://www.googleapis.com/auth/monitoring"
|
||||
)
|
||||
|
||||
var _ = instrumentation.SIGDescribe("Stackdriver Monitoring", func() {
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
framework.SkipUnlessProviderIs("gce", "gke")
|
||||
})
|
||||
|
||||
f := framework.NewDefaultFramework("stackdriver-monitoring")
|
||||
var kubeClient clientset.Interface
|
||||
|
||||
It("should run Stackdriver Metadata Agent [Feature:StackdriverMetadataAgent]", func() {
|
||||
ginkgo.It("should run Stackdriver Metadata Agent [Feature:StackdriverMetadataAgent]", func() {
|
||||
kubeClient = f.ClientSet
|
||||
testAgent(f, kubeClient)
|
||||
})
|
||||
})
|
||||
|
||||
func testAgent(f *framework.Framework, kubeClient clientset.Interface) {
|
||||
projectId := framework.TestContext.CloudConfig.ProjectID
|
||||
projectID := framework.TestContext.CloudConfig.ProjectID
|
||||
resourceType := "k8s_container"
|
||||
uniqueContainerName := fmt.Sprintf("test-container-%v", time.Now().Unix())
|
||||
endpoint := fmt.Sprintf(
|
||||
"https://stackdriver.googleapis.com/v1beta2/projects/%v/resourceMetadata?filter=resource.type%%3D%v+AND+resource.label.container_name%%3D%v",
|
||||
projectId,
|
||||
projectID,
|
||||
resourceType,
|
||||
uniqueContainerName)
|
||||
|
||||
|
@ -101,10 +100,12 @@ func testAgent(f *framework.Framework, kubeClient clientset.Interface) {
|
|||
}
|
||||
}
|
||||
|
||||
// Metadata has the information fetched from Stackdriver metadata API.
|
||||
type Metadata struct {
|
||||
Results []map[string]interface{}
|
||||
}
|
||||
|
||||
// Resource contains the resource type and labels from Stackdriver metadata API.
|
||||
type Resource struct {
|
||||
resourceType string
|
||||
resourceLabels map[string]string
|
||||
|
@ -135,7 +136,7 @@ func verifyPodExists(response []byte, containerName string) (bool, error) {
|
|||
}
|
||||
|
||||
func parseResource(resource interface{}) (*Resource, error) {
|
||||
var labels map[string]string = map[string]string{}
|
||||
var labels = map[string]string{}
|
||||
resourceMap, ok := resource.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Resource entry is of type %s, expected map[string]interface{}", reflect.TypeOf(resource))
|
||||
|
|
Loading…
Reference in New Issue