Skip to content

Commit

Permalink
Fix Azure error handling and add AnySet method to vendors struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Apr 26, 2024
1 parent 2c742a8 commit abd9719
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions v3/internal/utilization/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func gatherAzure(util *Data, client *http.Client) error {
if err != nil {
// Only return the error here if it is unexpected to prevent
// warning customers who aren't running Azure about a timeout.
if _, ok := err.(unexpectedAzureErr); ok {
// If any of the other vendors have been detected, and we have an unauthorized error, we should not return the error
// If no vendors have been detected, we should return the error.
if _, ok := err.(unexpectedAzureErr); ok && !util.Vendors.AnySet() {
return err
}
return nil
Expand Down Expand Up @@ -59,10 +61,14 @@ func getAzure(client *http.Client) (*azure, error) {
}
defer response.Body.Close()

if response.StatusCode != 200 {
if response.StatusCode != 200 && response.StatusCode != 401 {
return nil, unexpectedAzureErr{e: fmt.Errorf("response code %d", response.StatusCode)}
}

if response.StatusCode == 401 {
return nil, unexpectedAzureErr{e: err}
}

data, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, unexpectedAzureErr{e: err}
Expand Down
4 changes: 3 additions & 1 deletion v3/internal/utilization/utilization.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

// Package utilization implements the Utilization spec, available at
// https://source.datanerd.us/agents/agent-specs/blob/master/Utilization.md
//
package utilization

import (
Expand Down Expand Up @@ -84,6 +83,9 @@ type vendors struct {
Kubernetes *kubernetes `json:"kubernetes,omitempty"`
}

func (v *vendors) AnySet() bool {
return v.AWS != nil || v.Azure != nil || v.GCP != nil || v.PCF != nil || v.Docker != nil || v.Kubernetes != nil
}
func (v *vendors) isEmpty() bool {
return nil == v || *v == vendors{}
}
Expand Down

0 comments on commit abd9719

Please sign in to comment.