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

add error checks for datadog exporter #9964

Merged
merged 4 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

### 🧰 Bug fixes 🧰

- `datadogexporter`: add error checks for datadog exporter (#9964)
- `k8sclusterreceiver`: Fix the receiver to work with 1.19 and 1.20 k8s API versions (#9523)
- `azuremonitorexporter`: Fix log exporter bug related to incorrectly mapping SpanId (#9579)
- `mysqlreceiver`: Fix attribute values mismatch with its definition (#9688)
Expand Down
6 changes: 4 additions & 2 deletions exporter/datadogexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package datadogexporter

import (
Expand Down Expand Up @@ -580,7 +579,10 @@ func TestOnlyMetadata(t *testing.T) {

err = expTraces.Start(ctx, nil)
assert.NoError(t, err)
defer expTraces.Shutdown(ctx)
defer func() {
err = expTraces.Shutdown(ctx)
assert.NoError(t, err)
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
}()

err = expTraces.ConsumeTraces(ctx, testutils.TestTraces.Clone())
require.NoError(t, err)
Expand Down
7 changes: 4 additions & 3 deletions exporter/datadogexporter/internal/metrics/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package metrics

import (
Expand Down Expand Up @@ -71,7 +70,8 @@ func TestRunningMetrics(t *testing.T) {

ctx := context.Background()
consumer := NewConsumer()
tr.MapMetrics(ctx, ms, consumer)
err := tr.MapMetrics(ctx, ms, consumer)
assert.NoError(t, err)
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved

runningHostnames := []string{}
for _, metric := range consumer.runningMetrics(0, component.BuildInfo{}) {
Expand Down Expand Up @@ -115,7 +115,8 @@ func TestTagsMetrics(t *testing.T) {

ctx := context.Background()
consumer := NewConsumer()
tr.MapMetrics(ctx, ms, consumer)
err := tr.MapMetrics(ctx, ms, consumer)
assert.NoError(t, err)
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved

runningMetrics := consumer.runningMetrics(0, component.BuildInfo{})
runningTags := []string{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package translator

import (
Expand Down Expand Up @@ -134,7 +133,8 @@ func TestHistogramSketches(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
md := fromCDF(test.cdf)
consumer := &sketchConsumer{}
tr.MapMetrics(ctx, md, consumer)
err := tr.MapMetrics(ctx, md, consumer)
assert.NoError(t, err)
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
sk := consumer.sk

// Check the minimum is 0.0
Expand Down Expand Up @@ -305,7 +305,8 @@ func TestExactSumCount(t *testing.T) {
t.Run(testInstance.name, func(t *testing.T) {
md := testInstance.getHist()
consumer := &sketchConsumer{}
tr.MapMetrics(ctx, md, consumer)
err := tr.MapMetrics(ctx, md, consumer)
assert.NoError(t, err)
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
sk := consumer.sk

assert.Equal(t, testInstance.count, uint64(sk.Basic.Cnt), "counts differ")
Expand Down Expand Up @@ -363,7 +364,8 @@ func TestInfiniteBounds(t *testing.T) {
t.Run(testInstance.name, func(t *testing.T) {
md := testInstance.getHist()
consumer := &sketchConsumer{}
tr.MapMetrics(ctx, md, consumer)
err := tr.MapMetrics(ctx, md, consumer)
assert.NoError(t, err)
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
sk := consumer.sk

p := md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Histogram().DataPoints().At(0)
Expand Down
17 changes: 13 additions & 4 deletions exporter/datadogexporter/internal/testutils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package testutils // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/testutils"

import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"

Expand Down Expand Up @@ -83,15 +83,21 @@ func validateAPIKeyEndpoint(w http.ResponseWriter, r *http.Request) {
resJSON, _ := json.Marshal(res)

w.Header().Set("Content-Type", "application/json")
w.Write(resJSON)
_, err := w.Write(resJSON)
if err != nil {
log.Fatalln(err)
}
}

func validateAPIKeyEndpointInvalid(w http.ResponseWriter, r *http.Request) {
res := validateAPIKeyResponse{Valid: false}
resJSON, _ := json.Marshal(res)

w.Header().Set("Content-Type", "application/json")
w.Write(resJSON)
_, err := w.Write(resJSON)
if err != nil {
log.Fatalln(err)
}
}

type metricsResponse struct {
Expand All @@ -104,7 +110,10 @@ func metricsEndpoint(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
w.Write(resJSON)
_, err := w.Write(resJSON)
if err != nil {
log.Fatalln(err)
}
}

func newMetadataEndpoint(c chan []byte) func(http.ResponseWriter, *http.Request) {
Expand Down
7 changes: 5 additions & 2 deletions exporter/datadogexporter/traces_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter"

import (
Expand Down Expand Up @@ -147,9 +146,13 @@ func (exp *traceExporter) pushTraceData(
for _, ddTracePayload := range aggregatedTraces {
// currently we don't want to do retries since api endpoints may not dedupe in certain situations
// adding a helper function here to make custom retry logic easier in the future
exp.pushWithRetry(ctx, ddTracePayload, 1, pushTime, func() error {
err := exp.pushWithRetry(ctx, ddTracePayload, 1, pushTime, func() error {
return nil
})

if err != nil {
exp.params.Logger.Info("failed to push with retry", zap.Error(err))
}
}

_ = exp.client.PostMetrics(ms)
Expand Down
6 changes: 4 additions & 2 deletions exporter/datadogexporter/traces_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package datadogexporter

import (
Expand Down Expand Up @@ -91,7 +90,10 @@ func testTracesExporterHelper(td ptrace.Traces, t *testing.T) []string {

assert.NoError(t, err)

defer exporter.Shutdown(context.Background())
defer func() {
err = exporter.Shutdown(context.Background())
assert.NoError(t, err)
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
}()

ctx := context.Background()
errConsume := exporter.ConsumeTraces(ctx, td)
Expand Down