Skip to content

Commit

Permalink
Support components multiple implementation for package name (#31551)
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso authored Dec 10, 2024
1 parent 92cf9c4 commit 03a3f1c
Show file tree
Hide file tree
Showing 26 changed files with 51 additions and 46 deletions.
4 changes: 2 additions & 2 deletions comp/core/log/impl-systemprobe/systemprobe_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// Package logimpl implements a component to handle logging internal to the agent for system-probe.
package logimpl
// Package systemprobeimpl implements a component to handle logging internal to the agent for system-probe.
package systemprobeimpl

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion comp/core/log/impl-systemprobe/systemprobe_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package logimpl
package systemprobeimpl

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions comp/core/log/impl-trace/trace_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// Package logimpl provides a component that implements the log.Component for the trace-agent logger
package logimpl
// Package traceimpl provides a component that implements the log.Component for the trace-agent logger
package traceimpl

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion comp/core/log/impl-trace/trace_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package logimpl
package traceimpl

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions comp/core/tagger/impl-remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// Package remotetaggerimpl implements a remote Tagger.
package remotetaggerimpl
// Package remoteimpl implements a remote Tagger.
package remoteimpl

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion comp/core/tagger/impl-remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package remotetaggerimpl
package remoteimpl

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion comp/core/tagger/impl-remote/tagstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package remotetaggerimpl
package remoteimpl

import (
"sync"
Expand Down
2 changes: 1 addition & 1 deletion comp/core/tagger/impl-remote/tagstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package remotetaggerimpl
package remoteimpl

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/replay/impl-noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2021 Datadog, Inc.

// Package replayimpl implements a no-op version of the component
package replayimpl
// Package noopimpl implements a no-op version of the component
package noopimpl

import (
"sync"
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/collector/impl-pipeline/flare_filler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

//go:build otlp

// Package collectorimpl implements the collector component
package collectorimpl
// Package pipelineimpl implements the collector component
package pipelineimpl

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/collector/impl-pipeline/flare_filler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//go:build test && otlp
// +build test,otlp

// Package collectorimpl implements the collector component
package collectorimpl
// Package pipelineimpl implements the collector component
package pipelineimpl

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/collector/impl-pipeline/no_otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

//go:build !otlp

// Package collectorimpl contains a no-op implementation of the collector
package collectorimpl
// Package pipelineimpl contains a no-op implementation of the collector
package pipelineimpl

import (
collector "github.com/DataDog/datadog-agent/comp/otelcol/collector/def"
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/collector/impl-pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

//go:build otlp

// Package collectorimpl implements the collector component
package collectorimpl
// Package pipelineimpl implements the collector component
package pipelineimpl

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion comp/otelcol/collector/impl-pipeline/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//go:build otlp

package collectorimpl
package pipelineimpl

import (
"embed"
Expand Down
2 changes: 1 addition & 1 deletion comp/otelcol/collector/impl-pipeline/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//go:build otlp && test

package collectorimpl
package pipelineimpl

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions comp/rdnsquerier/impl-none/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

// Package rdnsquerierimpl provides the noop rdnsquerier component
package rdnsquerierimpl
// Package noneimpl provides the noop rdnsquerier component
package noneimpl

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions comp/serializer/compression/impl-noop/no_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// Package compressionimpl provides a set of functions for compressing with zlib / zstd
package compressionimpl
// Package noopimpl provides a set of functions for compressing with zlib / zstd
package noopimpl

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions comp/serializer/compression/impl-zlib/zlib_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// Package compressionimpl provides a set of functions for compressing with zlib
package compressionimpl
// Package zlibimpl provides a set of functions for compressing with zlib
package zlibimpl

import (
"bytes"
Expand Down
7 changes: 4 additions & 3 deletions comp/serializer/compression/impl-zstd/zstd_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// Package compressionimpl provides a set of functions for compressing with zstd
package compressionimpl
// Package zstdimpl provides a set of functions for compressing with zstd
package zstdimpl

import (
"bytes"

compression "github.com/DataDog/datadog-agent/comp/serializer/compression/def"
"github.com/DataDog/zstd"

compression "github.com/DataDog/datadog-agent/comp/serializer/compression/def"
)

// Requires contains the compression level for zstd compression
Expand Down
4 changes: 2 additions & 2 deletions comp/trace/compression/impl-gzip/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

// Package compressionimpl implements the compression component interface
package compressionimpl
// Package gzipimpl implements the compression component interface
package gzipimpl

import (
"compress/gzip"
Expand Down
4 changes: 2 additions & 2 deletions comp/trace/compression/impl-zstd/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

// Package compressionimpl implements the compression component interface
package compressionimpl
// Package zstdimpl implements the compression component interface
package zstdimpl

import (
"io"
Expand Down
10 changes: 5 additions & 5 deletions docs/public/components/creating-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ internally by each component (more on this [here TODO]()). -->
### The impl folders

The `impl` folder is where the component implementation is written. The details of component implementation are up to the developer.
The only requirements are that the package name follows the pattern `<COMPONENT_NAME>impl` and that there is a public instantiation function called `NewComponent`.
The only requirements are that the package name follows the pattern `<COMPONENT_NAME>impl` for the regular implementation or `<IMPL_NAME>impl` for the alternative implementation, and that there is a public instantiation function called `NewComponent`.

=== ":octicons-file-code-16: comp/compression/impl-zstd/compressor.go"
```go
package compressionimpl
package zstdimpl

// NewComponent returns a new ZSTD implementation for the compression component
func NewComponent(reqs Requires) Provides {
Expand All @@ -134,7 +134,7 @@ In this example, the compression component must access the configuration compone

=== ":octicons-file-code-16: comp/compression/impl-zstd/compressor.go"
```go
package compressionimpl
package zstdimpl

import (
"fmt"
Expand All @@ -160,7 +160,7 @@ In this example, the compression component must access the configuration compone
For the output of the component, populate the `Provides` struct with the return values.
=== ":octicons-file-code-16: comp/compression/impl-zstd/compressor.go"
```go
package compressionimpl
package zstdimpl

import (
// Always import the component def folder, so that you can return a 'compression.Component' type.
Expand All @@ -180,7 +180,7 @@ All together, the component code looks like the following:

=== ":octicons-file-code-16: comp/compression/impl-zstd/compressor.go"
```go
package compressionimpl
package zstdimpl

import (
"fmt"
Expand Down
9 changes: 6 additions & 3 deletions tasks/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ def has_type_component(content) -> bool:
'comp/core/configsync/configsyncimpl',
'comp/core/gui/guiimpl',
'comp/core/hostname/hostnameimpl',
'comp/core/log/logimpl',
'comp/core/log/tracelogimpl',
'comp/core/pid/pidimpl',
'comp/core/secrets/secretsimpl',
'comp/core/settings/settingsimpl',
Expand Down Expand Up @@ -165,7 +163,6 @@ def has_type_component(content) -> bool:
# Please do not add a new component to this list.
components_missing_implementation_folder = [
"comp/dogstatsd/statsd",
"comp/core/tagger",
"comp/forwarder/orchestrator/orchestratorinterface",
"comp/core/hostname/hostnameinterface",
]
Expand Down Expand Up @@ -233,6 +230,12 @@ def check_component_contents_and_file_hiearchy(comp):
for src_file in locate_nontest_source_files(impl_folders):
pkgname = parse_package_name(src_file)
expectname = comp.name + 'impl'

for part in src_file.parts:
if "impl-" in part:
parts = part.split("-")
expectname = parts[1] + 'impl'

if pkgname != expectname:
return f"** {src_file} has wrong package name '{pkgname}', must be '{expectname}'"
if comp.path in ignore_fx_import:
Expand Down
1 change: 1 addition & 0 deletions tasks/unit_tests/components_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def test_validate_component_implementation(self):

implfolder = os.path.join(comps[3].path, 'impl')
newfolder = os.path.join(comps[3].path, 'impl-alt')
replace_line(filename, 'package newstyleimpl', 'package altimpl')
shutil.move(implfolder, newfolder)

comps, _ = components.get_components_and_bundles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package multipleimpl
package oneimpl

import (
multiple "github.com/DataDog/datadog-agent/comp/multiple/def"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package multipleimpl
package twoimpl

import (
multiple "github.com/DataDog/datadog-agent/comp/multiple/def"
Expand Down

0 comments on commit 03a3f1c

Please sign in to comment.