Skip to content

Commit

Permalink
influxdb: fix metric name generation (#1444)
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
zroubalik authored Dec 22, 2020
1 parent 75e77bf commit fbfa738
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/scalers/influxdb_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ func parseInfluxDBMetadata(config *ScalerConfig) (*influxDBMetadata, error) {
}

if val, ok := config.TriggerMetadata["metricName"]; ok {
metricName = val
metricName = kedautil.NormalizeString(fmt.Sprintf("influxdb-%s", val))
} else {
parsedURL, err := url.Parse(serverURL)
if err != nil {
return nil, fmt.Errorf("unable to parse server url")
}

metricName, err = kedautil.MaskPartOfURL(parsedURL.String(), kedautil.Hostname)
maskedURL, err := kedautil.MaskPartOfURL(parsedURL.String(), kedautil.Hostname)
if err != nil {
return nil, fmt.Errorf("failure masking part of url")
}
metricName = kedautil.NormalizeString(fmt.Sprintf("influxdb-%s-%s", maskedURL, organizationName))
}

if val, ok := config.TriggerMetadata["thresholdValue"]; ok {
Expand Down Expand Up @@ -195,7 +196,7 @@ func (s *influxDBScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec {
targetMetricValue := resource.NewQuantity(int64(s.metadata.thresholdValue), resource.DecimalSI)
externalMetric := &v2beta2.ExternalMetricSource{
Metric: v2beta2.MetricIdentifier{
Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s", "influxdb", s.metadata.metricName, s.metadata.organizationName)),
Name: s.metadata.metricName,
},
Target: v2beta2.MetricTarget{
Type: v2beta2.AverageValueMetricType,
Expand Down
6 changes: 3 additions & 3 deletions pkg/scalers/influxdb_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var testInfluxDBMetadata = []parseInfluxDBMetadataTestData{
{map[string]string{"serverURL": "https://influxdata.com", "organizationName": "influx_org", "query": "from(bucket: hello)", "thresholdValue": "10"}, true}}

var influxDBMetricIdentifiers = []influxDBMetricIdentifier{
{&testInfluxDBMetadata[1], "influxdb-influx_metric-influx_org"},
{&testInfluxDBMetadata[1], "influxdb-influx_metric"},
{&testInfluxDBMetadata[2], "influxdb-https---xxx-influx_org"},
}

Expand All @@ -52,7 +52,7 @@ func TestInfluxDBParseMetadata(t *testing.T) {
t.Errorf("Expected success but got error for unit test # %v", testCaseNum)
}
if testData.isError && err == nil {
t.Errorf("Expected error but got success for unit test #%v", testCaseNum)
t.Errorf("Expected error but got success for unit test # %v", testCaseNum)
}
testCaseNum++
}
Expand All @@ -69,7 +69,7 @@ func TestInfluxDBGetMetricSpecForScaling(t *testing.T) {
metricSpec := mockInfluxDBScaler.GetMetricSpecForScaling()
metricName := metricSpec[0].External.Metric.Name
if metricName != testData.name {
t.Error("Wrong External metric source name:", metricName)
t.Errorf("Wrong External metric source name: %s, expected: %s", metricName, testData.name)
}
}
}

0 comments on commit fbfa738

Please sign in to comment.