Skip to content

Commit f5eca1e

Browse files
committed
Reduce NetIPC Go transport duplication
1 parent d821f42 commit f5eca1e

28 files changed

Lines changed: 634 additions & 565 deletions

.agents/sow/current/SOW-0015-20260605-codacy-scope-and-maintainability.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,49 @@ Validation and benchmark evidence:
861861
- `git diff --check`: passed.
862862
- `cd src/go && go test -count=1 ./pkg/netipc/...`: passed.
863863

864+
### 2026-06-08 - Netdata PR Sonar Duplication Refresh
865+
866+
Fresh Netdata PR #22649 review evidence:
867+
868+
- GitHub review state for `netdata/netdata#22649` at head `9e7474eded`:
869+
- 10 review threads total.
870+
- 9 review threads resolved.
871+
- 1 open review thread at `src/go/pkg/netipc/transport/internal/framing/handshake.go`.
872+
- The open handshake thread was verified against the checked-in protocol contract and implementations:
873+
- `docs/level1-wire-envelope.md` says a client request payload proposal above `1 MiB` is rejected with `LIMIT_EXCEEDED`; accepted request payload proposals are echoed unchanged.
874+
- C POSIX, C Windows, Rust POSIX, Rust Windows, and Go already implement that same contract.
875+
- No code change was made to this contract in this increment.
876+
- SonarCloud PR API evidence for `netdata/netdata#22649`:
877+
- open issues: 0.
878+
- open security hotspots: 0.
879+
- Quality Gate failure source is new-code duplication, not Sonar issue findings.
880+
- New duplicated lines: 1024.
881+
- New duplicated blocks: 48.
882+
- New duplicated line density: 5.903378300472731%, above the required 3% gate.
883+
884+
Implemented SDK follow-up:
885+
886+
- Moved duplicated Go POSIX/Windows handshake flow into shared framing helpers:
887+
- `ClientHandshake`
888+
- `ServerHandshake`
889+
- platform files keep only socket/pipe I/O and session construction.
890+
- Moved duplicated Go POSIX/Windows receive and send session orchestration into shared framing helpers:
891+
- `SessionReceive`
892+
- `SessionSend`
893+
- platform files keep only raw packet send/receive details.
894+
- Moved duplicated typed-service transport configuration conversion into `service/internal/transportconfig`.
895+
- Moved duplicated raw-service server initialization, worker-slot handling, accept retry, and session-worker launch into shared raw-service helpers.
896+
- Preserved platform-specific behavior:
897+
- POSIX UDS and Windows Named Pipe raw I/O remain in platform files.
898+
- SHM preparation/finalization remains platform-specific.
899+
- request-payload handshake negotiation remains unchanged.
900+
901+
Validation for this increment:
902+
903+
- `cd src/go && go test -count=1 ./pkg/netipc/...`: passed.
904+
- `cd src/go && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go test -run '^$' ./pkg/netipc/transport/windows ./pkg/netipc/service/raw ./pkg/netipc/service/apps_lookup ./pkg/netipc/service/cgroups_lookup ./pkg/netipc/service/cgroups_snapshot`: passed.
905+
- `git diff --check`: passed.
906+
864907
## Validation
865908

866909
Acceptance criteria evidence:
@@ -877,6 +920,7 @@ Acceptance criteria evidence:
877920
- Netdata PR #22649 SonarCloud security hotspots for C string/path copying were verified and addressed in the SDK before re-vendoring.
878921
- Go apps/cgroups lookup unknown codec paths now have canonical fast paths and regression tests.
879922
- POSIX and Windows benchmark runners now distinguish floor/correctness failures from scheduler-stability noise using documented repeated-sample policies.
923+
- Netdata PR #22649 SonarCloud duplication gate was rechecked; the current SDK increment removes duplicated Go transport/service flow before re-vendoring.
880924

881925
Tests or equivalent validation:
882926

@@ -894,6 +938,8 @@ Tests or equivalent validation:
894938
- `codacy-analysis analyze --files ... --output-format json`: 0 issues; known local Revive adapter invocation error remains.
895939
- `bash -n tests/run-posix-bench.sh tests/generate-benchmarks-posix.sh tests/run-windows-bench.sh tests/generate-benchmarks-windows.sh`: passed on 2026-06-08.
896940
- `cd src/go && go test -count=1 ./pkg/netipc/...`: passed on 2026-06-08.
941+
- `cd src/go && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go test -run '^$' ./pkg/netipc/transport/windows ./pkg/netipc/service/raw ./pkg/netipc/service/apps_lookup ./pkg/netipc/service/cgroups_lookup ./pkg/netipc/service/cgroups_snapshot`: passed on 2026-06-08.
942+
- `git diff --check`: passed on 2026-06-08 after the Go duplication-reduction increment.
897943

898944
Real-use evidence:
899945

src/go/pkg/netipc/service/apps_lookup/client.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@
33
package apps_lookup
44

55
import (
6+
"github.com/netdata/plugin-ipc/go/pkg/netipc/service/internal/transportconfig"
67
"github.com/netdata/plugin-ipc/go/pkg/netipc/transport/posix"
78
)
89

910
func clientConfigToTransport(config ClientConfig) posix.ClientConfig {
10-
return posix.ClientConfig{
11-
SupportedProfiles: config.SupportedProfiles,
12-
PreferredProfiles: config.PreferredProfiles,
13-
MaxRequestBatchItems: config.MaxRequestBatchItems,
14-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
15-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
16-
AuthToken: config.AuthToken,
17-
}
11+
return transportconfig.PosixClient(transportconfig.TypedConfig(config))
1812
}
1913

2014
func serverConfigToTransport(config ServerConfig) posix.ServerConfig {
21-
return posix.ServerConfig{
22-
SupportedProfiles: config.SupportedProfiles,
23-
PreferredProfiles: config.PreferredProfiles,
24-
MaxRequestBatchItems: config.MaxRequestBatchItems,
25-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
26-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
27-
AuthToken: config.AuthToken,
28-
}
15+
return transportconfig.PosixServer(transportconfig.TypedConfig(config))
2916
}

src/go/pkg/netipc/service/apps_lookup/client_common.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ type Client struct {
99
inner *raw.Client
1010
}
1111

12-
// typedResponseBatchItems keeps typed request/response batch counts symmetric.
13-
func typedResponseBatchItems(maxRequestBatchItems uint32) uint32 {
14-
return maxRequestBatchItems
15-
}
16-
1712
func NewClient(runDir, serviceName string, config ClientConfig) *Client {
1813
return &Client{inner: raw.NewAppsLookupClient(runDir, serviceName, clientConfigToTransport(config))}
1914
}

src/go/pkg/netipc/service/apps_lookup/client_windows.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@
33
package apps_lookup
44

55
import (
6+
"github.com/netdata/plugin-ipc/go/pkg/netipc/service/internal/transportconfig"
67
"github.com/netdata/plugin-ipc/go/pkg/netipc/transport/windows"
78
)
89

910
func clientConfigToTransport(config ClientConfig) windows.ClientConfig {
10-
return windows.ClientConfig{
11-
SupportedProfiles: config.SupportedProfiles,
12-
PreferredProfiles: config.PreferredProfiles,
13-
MaxRequestBatchItems: config.MaxRequestBatchItems,
14-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
15-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
16-
AuthToken: config.AuthToken,
17-
}
11+
return transportconfig.WindowsClient(transportconfig.TypedConfig(config))
1812
}
1913

2014
func serverConfigToTransport(config ServerConfig) windows.ServerConfig {
21-
return windows.ServerConfig{
22-
SupportedProfiles: config.SupportedProfiles,
23-
PreferredProfiles: config.PreferredProfiles,
24-
MaxRequestBatchItems: config.MaxRequestBatchItems,
25-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
26-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
27-
AuthToken: config.AuthToken,
28-
}
15+
return transportconfig.WindowsServer(transportconfig.TypedConfig(config))
2916
}

src/go/pkg/netipc/service/apps_lookup/types.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package apps_lookup
44

55
import (
66
"github.com/netdata/plugin-ipc/go/pkg/netipc/protocol"
7+
"github.com/netdata/plugin-ipc/go/pkg/netipc/service/internal/transportconfig"
78
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
89
)
910

@@ -21,21 +22,9 @@ const (
2122

2223
type ClientStatus = raw.ClientStatus
2324

24-
type ClientConfig struct {
25-
SupportedProfiles uint32
26-
PreferredProfiles uint32
27-
MaxRequestBatchItems uint32
28-
MaxResponsePayloadBytes uint32
29-
AuthToken uint64
30-
}
25+
type ClientConfig transportconfig.TypedConfig
3126

32-
type ServerConfig struct {
33-
SupportedProfiles uint32
34-
PreferredProfiles uint32
35-
MaxRequestBatchItems uint32
36-
MaxResponsePayloadBytes uint32
37-
AuthToken uint64
38-
}
27+
type ServerConfig transportconfig.TypedConfig
3928

4029
type HandlerFunc = func(*protocol.AppsLookupRequestView, *protocol.AppsLookupBuilder) bool
4130

src/go/pkg/netipc/service/cgroups_lookup/client.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@
33
package cgroups_lookup
44

55
import (
6+
"github.com/netdata/plugin-ipc/go/pkg/netipc/service/internal/transportconfig"
67
"github.com/netdata/plugin-ipc/go/pkg/netipc/transport/posix"
78
)
89

910
func clientConfigToTransport(config ClientConfig) posix.ClientConfig {
10-
return posix.ClientConfig{
11-
SupportedProfiles: config.SupportedProfiles,
12-
PreferredProfiles: config.PreferredProfiles,
13-
MaxRequestBatchItems: config.MaxRequestBatchItems,
14-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
15-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
16-
AuthToken: config.AuthToken,
17-
}
11+
return transportconfig.PosixClient(transportconfig.TypedConfig(config))
1812
}
1913

2014
func serverConfigToTransport(config ServerConfig) posix.ServerConfig {
21-
return posix.ServerConfig{
22-
SupportedProfiles: config.SupportedProfiles,
23-
PreferredProfiles: config.PreferredProfiles,
24-
MaxRequestBatchItems: config.MaxRequestBatchItems,
25-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
26-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
27-
AuthToken: config.AuthToken,
28-
}
15+
return transportconfig.PosixServer(transportconfig.TypedConfig(config))
2916
}

src/go/pkg/netipc/service/cgroups_lookup/client_common.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ type Client struct {
99
inner *raw.Client
1010
}
1111

12-
// typedResponseBatchItems keeps typed request/response batch counts symmetric.
13-
func typedResponseBatchItems(maxRequestBatchItems uint32) uint32 {
14-
return maxRequestBatchItems
15-
}
16-
1712
func NewClient(runDir, serviceName string, config ClientConfig) *Client {
1813
return &Client{inner: raw.NewCgroupsLookupClient(runDir, serviceName, clientConfigToTransport(config))}
1914
}

src/go/pkg/netipc/service/cgroups_lookup/client_windows.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@
33
package cgroups_lookup
44

55
import (
6+
"github.com/netdata/plugin-ipc/go/pkg/netipc/service/internal/transportconfig"
67
"github.com/netdata/plugin-ipc/go/pkg/netipc/transport/windows"
78
)
89

910
func clientConfigToTransport(config ClientConfig) windows.ClientConfig {
10-
return windows.ClientConfig{
11-
SupportedProfiles: config.SupportedProfiles,
12-
PreferredProfiles: config.PreferredProfiles,
13-
MaxRequestBatchItems: config.MaxRequestBatchItems,
14-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
15-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
16-
AuthToken: config.AuthToken,
17-
}
11+
return transportconfig.WindowsClient(transportconfig.TypedConfig(config))
1812
}
1913

2014
func serverConfigToTransport(config ServerConfig) windows.ServerConfig {
21-
return windows.ServerConfig{
22-
SupportedProfiles: config.SupportedProfiles,
23-
PreferredProfiles: config.PreferredProfiles,
24-
MaxRequestBatchItems: config.MaxRequestBatchItems,
25-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
26-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
27-
AuthToken: config.AuthToken,
28-
}
15+
return transportconfig.WindowsServer(transportconfig.TypedConfig(config))
2916
}

src/go/pkg/netipc/service/cgroups_lookup/types.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package cgroups_lookup
44

55
import (
66
"github.com/netdata/plugin-ipc/go/pkg/netipc/protocol"
7+
"github.com/netdata/plugin-ipc/go/pkg/netipc/service/internal/transportconfig"
78
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
89
)
910

@@ -21,21 +22,9 @@ const (
2122

2223
type ClientStatus = raw.ClientStatus
2324

24-
type ClientConfig struct {
25-
SupportedProfiles uint32
26-
PreferredProfiles uint32
27-
MaxRequestBatchItems uint32
28-
MaxResponsePayloadBytes uint32
29-
AuthToken uint64
30-
}
25+
type ClientConfig transportconfig.TypedConfig
3126

32-
type ServerConfig struct {
33-
SupportedProfiles uint32
34-
PreferredProfiles uint32
35-
MaxRequestBatchItems uint32
36-
MaxResponsePayloadBytes uint32
37-
AuthToken uint64
38-
}
27+
type ServerConfig transportconfig.TypedConfig
3928

4029
type HandlerFunc = func(*protocol.CgroupsLookupRequestView, *protocol.CgroupsLookupBuilder) bool
4130

src/go/pkg/netipc/service/cgroups_snapshot/client.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@
33
package cgroups_snapshot
44

55
import (
6+
"github.com/netdata/plugin-ipc/go/pkg/netipc/service/internal/transportconfig"
67
"github.com/netdata/plugin-ipc/go/pkg/netipc/transport/posix"
78
)
89

910
func clientConfigToTransport(config ClientConfig) posix.ClientConfig {
10-
return posix.ClientConfig{
11-
SupportedProfiles: config.SupportedProfiles,
12-
PreferredProfiles: config.PreferredProfiles,
13-
MaxRequestBatchItems: config.MaxRequestBatchItems,
14-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
15-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
16-
AuthToken: config.AuthToken,
17-
}
11+
return transportconfig.PosixClient(transportconfig.TypedConfig(config))
1812
}
1913

2014
func serverConfigToTransport(config ServerConfig) posix.ServerConfig {
21-
return posix.ServerConfig{
22-
SupportedProfiles: config.SupportedProfiles,
23-
PreferredProfiles: config.PreferredProfiles,
24-
MaxRequestBatchItems: config.MaxRequestBatchItems,
25-
MaxResponsePayloadBytes: config.MaxResponsePayloadBytes,
26-
MaxResponseBatchItems: typedResponseBatchItems(config.MaxRequestBatchItems),
27-
AuthToken: config.AuthToken,
28-
}
15+
return transportconfig.PosixServer(transportconfig.TypedConfig(config))
2916
}

0 commit comments

Comments
 (0)