Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Matrics API Scaler now can read any prometheus metric #6078

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update message
Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
  • Loading branch information
JorTurFer committed Aug 15, 2024
commit 9d4fc070fc340e09d6de8b55764bd7da662718a8
7 changes: 2 additions & 5 deletions pkg/scalers/metrics_api_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ func GetValueFromResponse(body []byte, valueLocation string, format APIFormat) (

// getValueFromPrometheusResponse uses provided valueLocation to access the numeric value in provided body
func getValueFromPrometheusResponse(body []byte, valueLocation string) (float64, error) {
familiesParser := expfmt.TextParser{}
metricss, _ := parser.ParseMetric(string(body))

matchers, err := parser.ParseMetricSelector(valueLocation)
if err != nil {
return 0, err
Expand All @@ -277,16 +274,16 @@ func getValueFromPrometheusResponse(body []byte, valueLocation string) (float64,
metricName = v.Value
}
}
_ = metricss
// Ensure EOL
reader := strings.NewReader(strings.ReplaceAll(string(body), "\r\n", "\n"))
familiesParser := expfmt.TextParser{}
families, err := familiesParser.TextToMetricFamilies(reader)
if err != nil {
return 0, err
}
family, ok := families[metricName]
if !ok {
return 0, fmt.Errorf("metric %s not found", metricName)
return 0, fmt.Errorf("metric '%s' not found", metricName)
}

metrics := family.GetMetric()
Expand Down
Loading