Skip to content

Commit

Permalink
chore: Save component.TelemetrySettings on chronicle exporter (#2047)
Browse files Browse the repository at this point in the history
* chore: Minor cleanup of chronicle exporter names

* chore: Chronicle exporter - save component.TelemetrySettings
  • Loading branch information
djaglowski authored Dec 12, 2024
1 parent 8d67555 commit e7ce981
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions exporter/chronicleexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (

type chronicleExporter struct {
cfg *Config
logger *zap.Logger
set component.TelemetrySettings
marshaler logMarshaler
collectorID, exporterID string

Expand Down Expand Up @@ -85,7 +85,7 @@ func newExporter(cfg *Config, params exporter.Settings, collectorID, exporterID

return &chronicleExporter{
cfg: cfg,
logger: params.Logger,
set: params.TelemetrySettings,
metrics: newHostMetricsReporter(uuidCID[:], customerID[:], exporterID, cfg.Namespace),
marshaler: marshaller,
collectorID: collectorID,
Expand Down Expand Up @@ -238,12 +238,12 @@ func (ce *chronicleExporter) startHostMetricsCollection(ctx context.Context) {
case <-ticker.C:
err := ce.metrics.collectHostMetrics()
if err != nil {
ce.logger.Error("Failed to collect host metrics", zap.Error(err))
ce.set.Logger.Error("Failed to collect host metrics", zap.Error(err))
}
request := ce.metrics.getAndReset()
_, err = ce.grpcClient.BatchCreateEvents(ctx, request, ce.buildOptions()...)
if err != nil {
ce.logger.Error("Failed to upload host metrics", zap.Error(err))
ce.set.Logger.Error("Failed to upload host metrics", zap.Error(err))
}
}
}
Expand Down Expand Up @@ -317,9 +317,9 @@ func (ce *chronicleExporter) uploadToChronicleHTTP(ctx context.Context, logs *ap
respBody, err := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
if err != nil {
ce.logger.Warn("Failed to read response body", zap.Error(err))
ce.set.Logger.Warn("Failed to read response body", zap.Error(err))
} else {
ce.logger.Warn("Received non-OK response from Chronicle", zap.String("status", resp.Status), zap.ByteString("response", respBody))
ce.set.Logger.Warn("Received non-OK response from Chronicle", zap.String("status", resp.Status), zap.ByteString("response", respBody))
}
return fmt.Errorf("received non-OK response from Chronicle: %s", resp.Status)
}
Expand Down
12 changes: 6 additions & 6 deletions exporter/chronicleexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/observiq/bindplane-agent/exporter/chronicleexporter/protos/api/mocks"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -52,7 +52,7 @@ func TestLogsDataPusher(t *testing.T) {
return &chronicleExporter{
cfg: &cfg,
metrics: newHostMetricsReporter([]byte{}, []byte{}, "", cfg.Namespace),
logger: zap.NewNop(),
set: componenttest.NewNopTelemetrySettings(),
grpcClient: mockClient,
marshaler: marshaller,
}
Expand All @@ -71,7 +71,7 @@ func TestLogsDataPusher(t *testing.T) {
return &chronicleExporter{
cfg: &cfg,
metrics: newHostMetricsReporter([]byte{}, []byte{}, "", cfg.Namespace),
logger: zap.NewNop(),
set: componenttest.NewNopTelemetrySettings(),
grpcClient: mockClient,
marshaler: marshaller,
}
Expand All @@ -92,7 +92,7 @@ func TestLogsDataPusher(t *testing.T) {
return &chronicleExporter{
cfg: &cfg,
metrics: newHostMetricsReporter([]byte{}, []byte{}, "", cfg.Namespace),
logger: zap.NewNop(),
set: componenttest.NewNopTelemetrySettings(),
grpcClient: mockClient,
marshaler: marshaller,
}
Expand All @@ -114,7 +114,7 @@ func TestLogsDataPusher(t *testing.T) {
return &chronicleExporter{
cfg: &cfg,
metrics: newHostMetricsReporter([]byte{}, []byte{}, "", cfg.Namespace),
logger: zap.NewNop(),
set: componenttest.NewNopTelemetrySettings(),
grpcClient: mockClient,
marshaler: marshaller,
}
Expand All @@ -134,7 +134,7 @@ func TestLogsDataPusher(t *testing.T) {
return &chronicleExporter{
cfg: &cfg,
metrics: newHostMetricsReporter([]byte{}, []byte{}, "", cfg.Namespace),
logger: zap.NewNop(),
set: componenttest.NewNopTelemetrySettings(),
grpcClient: mockClient,
marshaler: marshaller,
}
Expand Down

0 comments on commit e7ce981

Please sign in to comment.