Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pyohannes committed May 31, 2024
1 parent 001940d commit 507cdf6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
3 changes: 1 addition & 2 deletions detectors/azure/azurevm/example_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ package azurevm_test
import (
"context"
"fmt"

"go.opentelemetry.io/contrib/detectors/azure/azurevm"
)

func ExampleNew() {
azureVMResourceDetector := azurevm.New()
resource, err := azureVMResourceDetector.Detect(context.Background())

if err != nil {
panic(err)
}
Expand Down
20 changes: 10 additions & 10 deletions detectors/azure/azurevm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
)

// AzureVMResourceDetector collects resource information of Azure VMs.
type AzureVMResourceDetector struct {
type ResourceDetector struct {
endpoint string
}

Expand All @@ -35,13 +35,13 @@ type vmMetadata struct {
}

// New returns a [resource.Detector] that will detect Azure VM resources.
func New() *AzureVMResourceDetector {
return &AzureVMResourceDetector{defaultAzureVMMetadataEndpoint}
func New() *ResourceDetector {
return &ResourceDetector{defaultAzureVMMetadataEndpoint}
}

// Detect detects associated resources when running on an Azure VM.
func (detector *AzureVMResourceDetector) Detect(ctx context.Context) (*resource.Resource, error) {
jsonMetadata, err, runningInAzure := detector.getJSONMetadata()
func (detector *ResourceDetector) Detect(ctx context.Context) (*resource.Resource, error) {
jsonMetadata, runningInAzure, err := detector.getJSONMetadata()
if err != nil {
if !runningInAzure {
return resource.Empty(), nil
Expand Down Expand Up @@ -86,31 +86,31 @@ func (detector *AzureVMResourceDetector) Detect(ctx context.Context) (*resource.
return resource.NewWithAttributes(semconv.SchemaURL, attributes...), nil
}

func (detector *AzureVMResourceDetector) getJSONMetadata() ([]byte, error, bool) {
func (detector *ResourceDetector) getJSONMetadata() ([]byte, bool, error) {
pTransport := &http.Transport{Proxy: nil}

client := http.Client{Transport: pTransport}

req, err := http.NewRequest("GET", detector.endpoint, nil)
if err != nil {
return nil, err, false
return nil, false, err

Check warning on line 96 in detectors/azure/azurevm/vm.go

View check run for this annotation

Codecov / codecov/patch

detectors/azure/azurevm/vm.go#L96

Added line #L96 was not covered by tests
}

req.Header.Add("Metadata", "True")

resp, err := client.Do(req)
if err != nil {
return nil, err, false
return nil, false, err

Check warning on line 103 in detectors/azure/azurevm/vm.go

View check run for this annotation

Codecov / codecov/patch

detectors/azure/azurevm/vm.go#L103

Added line #L103 was not covered by tests
}

defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
bytes, err := io.ReadAll(resp.Body)
return bytes, err, true
return bytes, true, err
}

runningInAzure := resp.StatusCode < 400 || resp.StatusCode > 499

return nil, errors.New(http.StatusText(resp.StatusCode)), runningInAzure
return nil, runningInAzure, errors.New(http.StatusText(resp.StatusCode))
}

0 comments on commit 507cdf6

Please sign in to comment.