Skip to content

Commit

Permalink
[chore] k8sobjects receiver lifecycle generated tests (open-telemetry…
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored and XinRanZhAWS committed Mar 13, 2024
1 parent 79d645c commit ef17a4b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
4 changes: 3 additions & 1 deletion receiver/k8sobjectsreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/receivertest"

Expand Down Expand Up @@ -42,8 +43,9 @@ func TestCreateReceiver(t *testing.T) {
context.Background(), receivertest.NewNopCreateSettings(),
rCfg, consumertest.NewNop(),
)
assert.NoError(t, err)
err = r.Start(context.Background(), componenttest.NewNopHost())
assert.Error(t, err)
assert.Nil(t, r)

// Override for test.
rCfg.makeDynamicClient = newMockDynamicClient().getMockDynamicClient
Expand Down
76 changes: 76 additions & 0 deletions receiver/k8sobjectsreceiver/generated_component_test.go

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

4 changes: 4 additions & 0 deletions receiver/k8sobjectsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ status:
distributions: [contrib, splunk, sumo]
codeowners:
active: [dmitryax, hvaghani221, TylerHelmuth]

tests:
config:
skip_lifecycle: true
16 changes: 8 additions & 8 deletions receiver/k8sobjectsreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

type k8sobjectsreceiver struct {
setting receiver.CreateSettings
objects []*K8sObjectsConfig
config *Config
stopperChanList []chan struct{}
client dynamic.Interface
consumer consumer.Logs
Expand All @@ -38,10 +38,6 @@ type k8sobjectsreceiver struct {

func newReceiver(params receiver.CreateSettings, config *Config, consumer consumer.Logs) (receiver.Logs, error) {
transport := "http"
client, err := config.getDynamicClient()
if err != nil {
return nil, err
}

obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: params.ID,
Expand All @@ -60,19 +56,23 @@ func newReceiver(params receiver.CreateSettings, config *Config, consumer consum
}

return &k8sobjectsreceiver{
client: client,
setting: params,
consumer: consumer,
objects: config.Objects,
config: config,
obsrecv: obsrecv,
mu: sync.Mutex{},
}, nil
}

func (kr *k8sobjectsreceiver) Start(ctx context.Context, _ component.Host) error {
client, err := kr.config.getDynamicClient()
if err != nil {
return err
}
kr.client = client
kr.setting.Logger.Info("Object Receiver started")

for _, object := range kr.objects {
for _, object := range kr.config.Objects {
kr.start(ctx, object)
}
return nil
Expand Down

0 comments on commit ef17a4b

Please sign in to comment.