Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pyohannes committed May 30, 2024
1 parent ce392f0 commit ef19296
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- The `go.opentelemetry.io/contrib/config` add support to configure periodic reader interval and timeout. (#5661)
- Add the new `go.opentelemetry.io/contrib/detectors/azure/vm` package to provide a resource detector for Azure VMs. (#5422)
- Add the new `go.opentelemetry.io/contrib/detectors/azure/azurevm` package to provide a resource detector for Azure VMs. (#5422)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ The Azure VM resource detector supports detecting attributes specific to Azure V
## Usage

```golang
// Instantiate a new azure vm resource detector
azureVmResourceDetector := vm.New()
// Instantiate a new Azure VM resource detector
azureVmResourceDetector := azurevm.New()
resource, err := azureVmResourceDetector.Detect(context.Background())
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module go.opentelemetry.io/contrib/detectors/azure/vm
module go.opentelemetry.io/contrib/detectors/azure/azurevm

go 1.21

Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions detectors/azure/vm/vm.go → detectors/azure/azurevm/vm.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package vm // import "go.opentelemetry.io/contrib/detectors/azure/vm"
package azurevm // import "go.opentelemetry.io/contrib/detectors/azure/azurevm"

import (
"context"
"encoding/json"
"errors"
"io"
"net/http"

Expand Down Expand Up @@ -75,7 +76,7 @@ func New(opts ...Option) resource.Detector {
func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resource, error) {
jsonMetadata, err := detector.getJSONMetadata()
if err != nil {
return nil, err
return resource.Empty(), nil
}

var metadata vmMetadata
Expand Down Expand Up @@ -131,6 +132,10 @@ func (detector *resourceDetector) getJSONMetadata() ([]byte, error) {
return nil, err

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

View check run for this annotation

Codecov / codecov/patch

detectors/azure/azurevm/vm.go#L132

Added line #L132 was not covered by tests
}

if resp.StatusCode != http.StatusOK {
return nil, errors.New(http.StatusText(resp.StatusCode))
}

defer resp.Body.Close()

return io.ReadAll(resp.Body)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package vm
package azurevm

import (
"context"
Expand Down Expand Up @@ -72,19 +72,19 @@ func TestDetect(t *testing.T) {
},
{
input: input{
jsonMetadata: "",
jsonMetadata: "{}",
statusCode: http.StatusNotFound,
},
expected: expected{
resource: nil,
err: true,
resource: resource.Empty(),
err: false,
},
},
}

for _, tCase := range testTable {
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
w.WriteHeader(tCase.input.statusCode)

if r.Header.Get("Metadata") == "True" {
fmt.Fprintf(w, tCase.input.jsonMetadata)
Expand Down
2 changes: 1 addition & 1 deletion versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module-sets:
modules:
- go.opentelemetry.io/contrib/bridges/prometheus
- go.opentelemetry.io/contrib/detectors/aws/lambda
- go.opentelemetry.io/contrib/detectors/azure/vm
- go.opentelemetry.io/contrib/detectors/azure/azurevm
- go.opentelemetry.io/contrib/exporters/autoexport
- go.opentelemetry.io/contrib/propagators/autoprop
- go.opentelemetry.io/contrib/propagators/opencensus
Expand Down

0 comments on commit ef19296

Please sign in to comment.