From 06ae43400006ac762887c81c5cbb578b190db34b Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Tue, 16 Jan 2024 06:57:55 +0800 Subject: [PATCH 1/2] [receiver/podman] fix broken lifecycle test Signed-off-by: Ziqi Zhao --- receiver/podmanreceiver/libpod_client.go | 3 -- receiver/podmanreceiver/libpod_data.go | 3 -- receiver/podmanreceiver/metrics.go | 3 -- receiver/podmanreceiver/podman_connection.go | 3 -- receiver/podmanreceiver/podman_windows.go | 47 +++++++++++++++++++ receiver/podmanreceiver/receiver.go | 3 -- receiver/podmanreceiver/receiver_windows.go | 22 --------- .../podmanreceiver/receiver_windows_test.go | 20 -------- 8 files changed, 47 insertions(+), 57 deletions(-) create mode 100644 receiver/podmanreceiver/podman_windows.go delete mode 100644 receiver/podmanreceiver/receiver_windows.go delete mode 100644 receiver/podmanreceiver/receiver_windows_test.go diff --git a/receiver/podmanreceiver/libpod_client.go b/receiver/podmanreceiver/libpod_client.go index 97e61e18b31a..b36b391f27dc 100644 --- a/receiver/podmanreceiver/libpod_client.go +++ b/receiver/podmanreceiver/libpod_client.go @@ -1,9 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -//go:build !windows -// +build !windows - package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver" import ( diff --git a/receiver/podmanreceiver/libpod_data.go b/receiver/podmanreceiver/libpod_data.go index d68e72648e61..931b963ccdd1 100644 --- a/receiver/podmanreceiver/libpod_data.go +++ b/receiver/podmanreceiver/libpod_data.go @@ -1,9 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -//go:build !windows -// +build !windows - package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver" import "time" diff --git a/receiver/podmanreceiver/metrics.go b/receiver/podmanreceiver/metrics.go index e262e93c16c9..9b48cfd2a80b 100644 --- a/receiver/podmanreceiver/metrics.go +++ b/receiver/podmanreceiver/metrics.go @@ -1,9 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -//go:build !windows -// +build !windows - package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver" import ( diff --git a/receiver/podmanreceiver/podman_connection.go b/receiver/podmanreceiver/podman_connection.go index 88b83b4b1165..7161e88b32cb 100644 --- a/receiver/podmanreceiver/podman_connection.go +++ b/receiver/podmanreceiver/podman_connection.go @@ -1,9 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -//go:build !windows -// +build !windows - package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver" import ( diff --git a/receiver/podmanreceiver/podman_windows.go b/receiver/podmanreceiver/podman_windows.go new file mode 100644 index 000000000000..627e25c120c7 --- /dev/null +++ b/receiver/podmanreceiver/podman_windows.go @@ -0,0 +1,47 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver" + +import ( + "context" + "net/url" + + "go.uber.org/zap" +) + +type clientFactory func(logger *zap.Logger, cfg *Config) (PodmanClient, error) + +type PodmanClient interface { + ping(context.Context) error + stats(context.Context, url.Values) ([]containerStats, error) + list(context.Context, url.Values) ([]container, error) + events(context.Context, url.Values) (<-chan event, <-chan error) +} + +type ContainerScraper struct { +} + +func newContainerScraper(engineClient PodmanClient, logger *zap.Logger, config *Config) *ContainerScraper { + return &ContainerScraper{} +} + +func (pc *ContainerScraper) getContainers() []container { + cs := make([]container, 0) + return cs +} + +func (pc *ContainerScraper) loadContainerList(ctx context.Context) error { + return nil +} + +func (pc *ContainerScraper) fetchContainerStats(ctx context.Context, c container) (containerStats, error) { + return containerStats{}, nil +} + +func (pc *ContainerScraper) persistContainer(c container) { +} + +func (pc *ContainerScraper) containerEventLoop(ctx context.Context) { + +} diff --git a/receiver/podmanreceiver/receiver.go b/receiver/podmanreceiver/receiver.go index 0ecf83192175..79315217c1fe 100644 --- a/receiver/podmanreceiver/receiver.go +++ b/receiver/podmanreceiver/receiver.go @@ -1,9 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -//go:build !windows -// +build !windows - package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver" import ( diff --git a/receiver/podmanreceiver/receiver_windows.go b/receiver/podmanreceiver/receiver_windows.go deleted file mode 100644 index a2811ef4b345..000000000000 --- a/receiver/podmanreceiver/receiver_windows.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver" - -import ( - "context" - "fmt" - - "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/receiver" -) - -func newMetricsReceiver( - _ context.Context, - _ receiver.CreateSettings, - _ *Config, - _ consumer.Metrics, - _ any, -) (receiver.Metrics, error) { - return nil, fmt.Errorf("podman receiver is not supported on windows") -} diff --git a/receiver/podmanreceiver/receiver_windows_test.go b/receiver/podmanreceiver/receiver_windows_test.go deleted file mode 100644 index df40abb722ed..000000000000 --- a/receiver/podmanreceiver/receiver_windows_test.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package podmanreceiver - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/receiver/receivertest" -) - -func TestNewReceiver(t *testing.T) { - mr, err := newMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), &Config{}, consumertest.NewNop(), nil) - assert.Nil(t, mr) - assert.Error(t, err) - assert.Equal(t, "podman receiver is not supported on windows", err.Error()) -} From 3991161f1d2ffc773bbc8f8adb7b6409705c0cd6 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Tue, 16 Jan 2024 09:55:23 +0800 Subject: [PATCH 2/2] fix windows unit test failed for opampsupervisor Signed-off-by: Ziqi Zhao --- cmd/opampsupervisor/supervisor/supervisor_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/opampsupervisor/supervisor/supervisor_test.go b/cmd/opampsupervisor/supervisor/supervisor_test.go index 2e7cafab11af..f247b169907a 100644 --- a/cmd/opampsupervisor/supervisor/supervisor_test.go +++ b/cmd/opampsupervisor/supervisor/supervisor_test.go @@ -4,6 +4,7 @@ package supervisor import ( + "bytes" "os" "sync/atomic" "testing" @@ -52,6 +53,7 @@ func Test_composeEffectiveConfig(t *testing.T) { expectedConfig, err := os.ReadFile("../testdata/collector/effective_config.yaml") require.NoError(t, err) + expectedConfig = bytes.ReplaceAll(expectedConfig, []byte("\r\n"), []byte("\n")) require.True(t, configChanged) require.Equal(t, string(expectedConfig), s.effectiveConfig.Load().(string))