Skip to content

Commit

Permalink
Add copyright headers and rename a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Claes Mogren committed May 1, 2019
1 parent 5fb8995 commit 74f3d04
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 15 deletions.
13 changes: 13 additions & 0 deletions cni-metrics-helper/cni-metrics-helper.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 main

import (
Expand Down
34 changes: 24 additions & 10 deletions cni-metrics-helper/metrics/cni_metrics.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
// Package metrics handles the processing of all metrics. This file handles metrics for kube-state-metrics
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 metrics handles the processing of all metrics. This file handles metrics for ipamd
package metrics

import (
Expand All @@ -10,6 +23,9 @@ import (
"github.com/aws/amazon-vpc-cni-k8s/pkg/publisher"
)

// Port where prometheus metrics are published.
const metricsPort = 61678

// InterestingCNIMetrics defines metrics parsing definition for kube-state-metrics
var InterestingCNIMetrics = map[string]metricsConvert{
"awscni_assigned_ip_addresses": {
Expand Down Expand Up @@ -103,7 +119,7 @@ var InterestingCNIMetrics = map[string]metricsConvert{
// CNIMetricsTarget defines data structure for kube-state-metric target
type CNIMetricsTarget struct {
interestingMetrics map[string]metricsConvert
cwClient publisher.Publisher
cwMetricsPublisher publisher.Publisher
kubeClient clientset.Interface
cniPods []string
discoveryController *k8sapi.Controller
Expand All @@ -114,33 +130,31 @@ type CNIMetricsTarget struct {
func CNIMetricsNew(c clientset.Interface, cw publisher.Publisher, d *k8sapi.Controller, submitCW bool) *CNIMetricsTarget {
return &CNIMetricsTarget{
interestingMetrics: InterestingCNIMetrics,
cwClient: cw,
cwMetricsPublisher: cw,
kubeClient: c,
discoveryController: d,
submitCW: submitCW,
}
}

func (t *CNIMetricsTarget) grabMetricsFromTarget(cniPod string) ([]byte, error) {

glog.Info("Grabbing metrics from CNI ", cniPod)
output, err := getMetricsFromPod(t.kubeClient, cniPod, metav1.NamespaceSystem, 61678)
glog.Infof("Grabbing metrics from CNI: %s", cniPod)
output, err := getMetricsFromPod(t.kubeClient, cniPod, metav1.NamespaceSystem, metricsPort)
if err != nil {
glog.Errorf("grabMetricsFromTarget: Failed to grab CNI endpoint: %v", err)
return nil, err
}

glog.V(5).Infof("cni-metrics text output: %v", string(output))

glog.V(5).Infof("cni-metrics text output: %s", string(output))
return output, nil
}

func (t *CNIMetricsTarget) getInterestingMetrics() map[string]metricsConvert {
return InterestingCNIMetrics
}

func (t *CNIMetricsTarget) getCWContext() publisher.Publisher {
return t.cwClient
func (t *CNIMetricsTarget) getCWMetricsPublisher() publisher.Publisher {
return t.cwMetricsPublisher
}

func (t *CNIMetricsTarget) getTargetList() []string {
Expand Down
19 changes: 15 additions & 4 deletions cni-metrics-helper/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 metrics provide common data structure and routines for converting/aggregating prometheus metrics to cloudwatch metrics
package metrics

Expand All @@ -22,7 +35,7 @@ type actionFuncType func(aggregatedValue *float64, sampleValue float64)
type metricsTarget interface {
grabMetricsFromTarget(target string) ([]byte, error)
getInterestingMetrics() map[string]metricsConvert
getCWContext() publisher.Publisher
getCWMetricsPublisher() publisher.Publisher
getTargetList() []string
submitCloudWatch() bool
}
Expand Down Expand Up @@ -318,10 +331,8 @@ func filterMetrics(originalMetrics map[string]*dto.MetricFamily,
}

func produceCloudWatchMetrics(t metricsTarget, families map[string]*dto.MetricFamily, convertDef map[string]metricsConvert, cw publisher.Publisher) {
// TODO: The following will be changed to integrate with CloudWatch publisher
for key, family := range families {
convertMetrics := convertDef[key]

mType := family.GetType()
for _, action := range convertMetrics.actions {
switch mType {
Expand Down Expand Up @@ -439,6 +450,6 @@ func Handler(t metricsTarget) {
glog.Info("Skipping 1st poll after reset, error:", err)
}

cw := t.getCWContext()
cw := t.getCWMetricsPublisher()
produceCloudWatchMetrics(t, families, interestingMetrics, cw)
}
15 changes: 14 additions & 1 deletion cni-metrics-helper/metrics/metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 metrics

import (
Expand Down Expand Up @@ -31,7 +44,7 @@ func (target *testMetricsTarget) getInterestingMetrics() map[string]metricsConve
return target.interestingMetrics
}

func (target *testMetricsTarget) getCWContext() publisher.Publisher {
func (target *testMetricsTarget) getCWMetricsPublisher() publisher.Publisher {
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/publisher/publisher.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 publisher is used to batch and send metric data to CloudWatch
package publisher

Expand Down
13 changes: 13 additions & 0 deletions pkg/publisher/publisher_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 publisher

import (
Expand Down

0 comments on commit 74f3d04

Please sign in to comment.