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

modify code to make it extensive for logs #42

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ receivers:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/influxdbreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.108.0
Expand Down Expand Up @@ -258,7 +258,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sobjectsreceiver => ../../receiver/k8sobjectsreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver => ../../receiver/haproxyreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver => ../../receiver/httpcheckreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver => ../../receiver/huaweicloudcesreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver => ../../receiver/huaweicloudreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/dockerobserver => ../../extension/observer/dockerobserver
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/k8sobserver => ../../extension/observer/k8sobserver
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sentryexporter => ../../exporter/sentryexporter
Expand Down
6 changes: 3 additions & 3 deletions cmd/otelcontribcol/components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/influxdbreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.108.0
Expand Down Expand Up @@ -884,7 +884,7 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hapro

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver => ../../receiver/httpcheckreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver => ../../receiver/huaweicloudcesreceiver
replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver => ../../receiver/huaweicloudreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/dockerobserver => ../../extension/observer/dockerobserver

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development]: metrics |
| Stability | [development]: metrics, logs |
| Distributions | [] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fhuaweicloudces%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fhuaweicloudces) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fhuaweicloudces%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fhuaweicloudces) |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fhuaweicloud%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fhuaweicloud) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fhuaweicloud%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fhuaweicloud) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@heitorganzeli](https://www.github.com/heitorganzeli), [@narcis96](https://www.github.com/narcis96) |

[development]: https://github.com/open-telemetry/opentelemetry-collector#development
Expand Down Expand Up @@ -60,7 +60,7 @@ The following settings are optional:

```yaml
receivers:
huaweicloudcesreceiver:
huaweicloudreceiver:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since LTS is effectively a different service, i think it makes more sense to keep separate components like awscloudwatchlogsexporter and awskinesisexporter

but, i'm open for discussion

collection_interval: 3h
initial_delay: 5s
region_name: eu-west-101
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 huaweicloudcesreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver"
package huaweicloudreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver"

import (
"errors"
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 huaweicloudcesreceiver
package huaweicloudreceiver

import (
"testing"
Expand Down
53 changes: 53 additions & 0 deletions receiver/huaweicloudreceiver/consumers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package huaweicloudreceiver

import (
"context"

"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver"
)

type receiverProcessor interface {
processReceivedData(ctx context.Context, data []byte) error
}

type metricsReceiver struct {
consumer consumer.Metrics
}

func (r *metricsReceiver) processReceivedData(ctx context.Context, data []byte) error {
unmarshaler := &pmetric.JSONUnmarshaler{}

metrics, err := unmarshaler.UnmarshalMetrics(data)
if err != nil {
return err
}
return r.consumer.ConsumeMetrics(ctx, metrics)
}

func newHuaweiCloudMetricsReceiver(cfg *Config, metrics consumer.Metrics, settings receiver.Settings) *huaweiReceiver {
return newHuaweiCloudReceiver(settings, Metrics, cfg, &metricsReceiver{consumer: metrics})
}

type logsReceiver struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if keeping the same component, i think you could separate files, ces_consumer, lts_consumer. And the same for the other files, so that they don't grow indefinitely

consumer consumer.Logs
}

func (r *logsReceiver) processReceivedData(ctx context.Context, data []byte) error {
unmarshaler := &plog.JSONUnmarshaler{}

logs, err := unmarshaler.UnmarshalLogs(data)
if err != nil {
return err
}
return r.consumer.ConsumeLogs(ctx, logs)
}

func newHuaweiCloudLogsReceiver(cfg *Config, logs consumer.Logs, settings receiver.Settings) *huaweiReceiver {
return newHuaweiCloudReceiver(settings, Logs, cfg, &logsReceiver{consumer: logs})
}
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 huaweicloudcesreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver"
package huaweicloudreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver"

import (
"context"
Expand All @@ -13,14 +13,16 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver/internal/metadata"
)

func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
receiver.WithLogs(createLogsReceiver, metadata.LogsStability),
)
}

func createDefaultConfig() component.Config {
Expand All @@ -44,11 +46,14 @@ func createMetricsReceiver(
params receiver.Settings,
cfg component.Config,
next consumer.Metrics) (receiver.Metrics, error) {
return newHuaweiCloudMetricsReceiver(cfg.(*Config), next, params), nil

cesCfg := cfg.(*Config)

cesReceiver := newHuaweiCloudCesReceiver(params, cesCfg, next)

return cesReceiver, nil
}

func createLogsReceiver(
_ context.Context,
params receiver.Settings,
cfg component.Config,
next consumer.Logs) (receiver.Logs, error) {
return newHuaweiCloudLogsReceiver(cfg.(*Config), next, params), nil
}
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 huaweicloudcesreceiver
package huaweicloudreceiver

import (
"context"
Expand All @@ -18,7 +18,7 @@ import (
func TestNewFactory(t *testing.T) {
factory := NewFactory()
assert.NotNil(t, factory)
assert.Equal(t, component.MustNewType("huaweicloudcesreceiver"), factory.Type())
assert.Equal(t, component.MustNewType("huaweicloudreceiver"), factory.Type())
}

func TestCreateDefaultConfig(t *testing.T) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver

go 1.22.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//go:build integration

package huaweicloudcesreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver"
package huaweicloudreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver"

import (
"context"
Expand All @@ -20,10 +20,10 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/internal/mocks"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver/internal/mocks"
)

func TestHuaweiCloudCESReceiverIntegration(t *testing.T) {
func TestHuaweiCloudMetricsReceiverIntegration(t *testing.T) {
mc := mocks.NewCesClient(t)

mc.On("ListMetrics", mock.Anything).Return(&model.ListMetricsResponse{
Expand Down Expand Up @@ -71,9 +71,9 @@ func TestHuaweiCloudCESReceiverIntegration(t *testing.T) {
)
require.NoError(t, err)

rcvr, ok := recv.(*cesReceiver)
rcvr, ok := recv.(*huaweiReceiver)
require.True(t, ok)
rcvr.client = mc
rcvr.clients = &clients{ces: mc}

err = recv.Start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/internal"
package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver/internal"

import (
"context"
"fmt"
"time"

"github.com/cenkalti/backoff/v4"
"go.opentelemetry.io/collector/config/configretry"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -86,3 +87,15 @@ func MakeAPICallWithRetry[T any](

return nil, err
}

func NewExponentialBackOff(backOffConfig *configretry.BackOffConfig) *backoff.ExponentialBackOff {
return &backoff.ExponentialBackOff{
InitialInterval: backOffConfig.InitialInterval,
RandomizationFactor: backOffConfig.RandomizationFactor,
Multiplier: backOffConfig.Multiplier,
MaxInterval: backOffConfig.MaxInterval,
MaxElapsedTime: backOffConfig.MaxElapsedTime,
Stop: backoff.Stop,
Clock: backoff.SystemClock,
}
}
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 internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/internal"
package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver/internal"

import (
ces "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1"
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 internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/internal"
package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudreceiver/internal"

import (
"fmt"
Expand Down Expand Up @@ -37,11 +37,8 @@ func GetDimension(dimensions []model.MetricsDimension, index int) *string {
return nil
}

func ConvertCESMetricsToOTLP(projectID, region, filter string, cesMetrics map[string]MetricData) pmetric.Metrics {
func ConvertCESMetricsToOTLP(projectID, region, filter string, cesMetrics map[string]MetricData) ([]byte, error) {
metrics := pmetric.NewMetrics()
if len(cesMetrics) == 0 {
return metrics
}
resourceMetric := metrics.ResourceMetrics().AppendEmpty()

resource := resourceMetric.Resource()
Expand Down Expand Up @@ -81,6 +78,10 @@ func ConvertCESMetricsToOTLP(projectID, region, filter string, cesMetrics map[st
}
}
}

return metrics
marshaler := &pmetric.JSONMarshaler{}
data, err := marshaler.MarshalMetrics(metrics)
if err != nil {
return nil, err
}
return data, nil
}
Loading
Loading