-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enhance metric name matching to match on prefix (#327)
* feat: Enhance metric name matching to match on prefix This allows for a class of Metrics to be enabled with one configured metric name. App SDK uses this for PipelineMetrics by appending the pipeline ID to the name of the metric(s) it is collecting for multiple function pipelines. Signed-off-by: Leonard Goodell <[email protected]>
- Loading branch information
Lenny Goodell
authored
Apr 25, 2022
1 parent
575cc54
commit a90d46a
Showing
2 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright 2022 Intel Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* 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 config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTelemetryInfo_MetricEnabled(t *testing.T) { | ||
target := TelemetryInfo{} | ||
|
||
manyMetrics := map[string]bool{ | ||
"OtherMetric": false, | ||
"YourMetric": false, | ||
"MyMetricSpecial": false, | ||
"MyMetric": true, | ||
} | ||
|
||
tests := []struct { | ||
Name string | ||
Metrics map[string]bool | ||
ServiceMetricName string | ||
Expected bool | ||
}{ | ||
{"Simple Match", manyMetrics, "MyMetric", true}, | ||
{"Has Prefix Match", manyMetrics, "MyMetric-1234", true}, | ||
{"No Match", manyMetrics, "1234-MyMetric", false}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.Name, func(t *testing.T) { | ||
target.Metrics = test.Metrics | ||
actual := target.MetricEnabled(test.ServiceMetricName) | ||
assert.Equal(t, test.Expected, actual) | ||
}) | ||
} | ||
} |