Skip to content

Commit

Permalink
Minor nits
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthvn authored and jdn5126 committed Nov 15, 2023
1 parent 047b0c6 commit 5a29a2f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
2 changes: 2 additions & 0 deletions cmd/cni-metrics-helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func main() {

cwENV, found := os.LookupEnv("USE_CLOUDWATCH")
if found {
cwENV = strings.ToLower(cwENV)
if strings.Compare(cwENV, "yes") == 0 || strings.Compare(cwENV, "true") == 0 {
options.submitCW = true
}
Expand All @@ -107,6 +108,7 @@ func main() {

prometheusENV, found := os.LookupEnv(envEnablePrometheusMetrics)
if found {
prometheusENV = strings.ToLower(prometheusENV)
if strings.Compare(prometheusENV, "yes") == 0 || strings.Compare(prometheusENV, "true") == 0 {
options.submitPrometheus = true
prometheusRegister()
Expand Down
48 changes: 21 additions & 27 deletions cmd/cni-metrics-helper/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,36 +322,28 @@ func produceCloudWatchMetrics(t metricsTarget, families map[string]*dto.MetricFa
for _, action := range convertMetrics.actions {
switch metricType {
case dto.MetricType_COUNTER:
if t.submitCloudWatch() {
dataPoint := &cloudwatch.MetricDatum{
MetricName: aws.String(action.cwMetricName),
Unit: aws.String(cloudwatch.StandardUnitCount),
Value: aws.Float64(action.data.curSingleDataPoint),
}
cw.Publish(dataPoint)
dataPoint := &cloudwatch.MetricDatum{
MetricName: aws.String(action.cwMetricName),
Unit: aws.String(cloudwatch.StandardUnitCount),
Value: aws.Float64(action.data.curSingleDataPoint),
}
cw.Publish(dataPoint)
case dto.MetricType_GAUGE:
if t.submitCloudWatch() {
dataPoint := &cloudwatch.MetricDatum{
MetricName: aws.String(action.cwMetricName),
Unit: aws.String(cloudwatch.StandardUnitCount),
Value: aws.Float64(action.data.curSingleDataPoint),
}
cw.Publish(dataPoint)
dataPoint := &cloudwatch.MetricDatum{
MetricName: aws.String(action.cwMetricName),
Unit: aws.String(cloudwatch.StandardUnitCount),
Value: aws.Float64(action.data.curSingleDataPoint),
}
cw.Publish(dataPoint)
case dto.MetricType_SUMMARY:
if t.submitCloudWatch() {
dataPoint := &cloudwatch.MetricDatum{
MetricName: aws.String(action.cwMetricName),
Unit: aws.String(cloudwatch.StandardUnitCount),
Value: aws.Float64(action.data.curSingleDataPoint),
}
cw.Publish(dataPoint)
dataPoint := &cloudwatch.MetricDatum{
MetricName: aws.String(action.cwMetricName),
Unit: aws.String(cloudwatch.StandardUnitCount),
Value: aws.Float64(action.data.curSingleDataPoint),
}
cw.Publish(dataPoint)
case dto.MetricType_HISTOGRAM:
if t.submitCloudWatch() {
produceHistogram(action, cw)
}
produceHistogram(action, cw)
}
}
}
Expand All @@ -378,7 +370,6 @@ func producePrometheusMetrics(t metricsTarget, families map[string]*dto.MetricFa
}
}
}

}

func resetMetrics(interestingMetrics map[string]metricsConvert) {
Expand Down Expand Up @@ -451,8 +442,11 @@ func Handler(ctx context.Context, t metricsTarget) {
t.getLogger().Infof("Skipping 1st poll after reset, error: %v", err)
}

cw := t.getCWMetricsPublisher()
produceCloudWatchMetrics(t, families, interestingMetrics, cw)
if t.submitCloudWatch() {
cw := t.getCWMetricsPublisher()
produceCloudWatchMetrics(t, families, interestingMetrics, cw)
}

if t.submitPrometheus() {
producePrometheusMetrics(t, families, interestingMetrics)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/ipamd/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/aws/amazon-vpc-cni-k8s/pkg/k8sapi"
"github.com/aws/amazon-vpc-cni-k8s/pkg/networkutils"
"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/retry"
"github.com/aws/amazon-vpc-cni-k8s/utils"
)

const (
Expand Down Expand Up @@ -199,7 +200,7 @@ func logErr(_ int, err error) {

// disableIntrospection returns true if we should disable the introspection
func disableIntrospection() bool {
return getEnvBoolWithDefault(envDisableIntrospection, false)
return utils.GetBoolAsStringEnvVar(envDisableENIProvisioning, false)
}

func getEnvBoolWithDefault(envName string, def bool) bool {
Expand Down

0 comments on commit 5a29a2f

Please sign in to comment.