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

chore: updating getCanaryConfigId to be more efficient with better error handling #3070

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
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
18 changes: 6 additions & 12 deletions metricproviders/kayenta/kayenta.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,20 @@
}

func getCanaryConfigId(metric v1alpha1.Metric, p *Provider) (string, error) {

configIdLookupURL := fmt.Sprintf(configIdLookupURLFormat, metric.Provider.Kayenta.Address, metric.Provider.Kayenta.Application, metric.Provider.Kayenta.StorageAccountName)

response, err := p.client.Get(configIdLookupURL)
if err != nil || response.Body == nil || response.StatusCode != 200 {
if err == nil {
err = errors.New("Invalid Response")
}
if err != nil {
return "", err
}
defer response.Body.Close()

data, err := io.ReadAll(response.Body)
if err != nil {
return "", err
if response.StatusCode != 200 {
return "", fmt.Errorf("Invalid Response: HTTP %d", response.StatusCode)
}

var cc []canaryConfig

err = json.Unmarshal(data, &cc)
if err != nil {
if err := json.NewDecoder(response.Body).Decode(&cc); err != nil {
return "", err
}

Expand All @@ -96,7 +90,7 @@
}
}

return "", err
return "", errors.New("Canary config not found")

Check warning on line 93 in metricproviders/kayenta/kayenta.go

View check run for this annotation

Codecov / codecov/patch

metricproviders/kayenta/kayenta.go#L93

Added line #L93 was not covered by tests
}

// Run queries kayentd for the metric
Expand Down
Loading