Skip to content

Commit ef9fcef

Browse files
committed
Refactor Go service facade wrappers
1 parent e762aef commit ef9fcef

13 files changed

Lines changed: 237 additions & 402 deletions

File tree

.agents/sow/current/SOW-0014-20260603-maintainability-hotspots.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Status: in-progress
66

7-
Sub-state: implementing the approved first remediation target: Go raw L3 cache duplication.
7+
Sub-state: reviewing and applying only useful low-risk typed service-facade duplication cleanups before moving to complexity hotspots.
88

99
## Requirements
1010

@@ -146,7 +146,7 @@ Open-source reference evidence:
146146

147147
Open decisions:
148148

149-
- After the Go raw L3 cache target is validated, decide whether to continue with larger typed service-facade duplication or stop.
149+
- After low-risk typed service-facade cleanup is validated, switch to complexity hotspots.
150150

151151
## Implications And Decisions
152152

@@ -327,6 +327,19 @@ Refined recommendation:
327327
- Preserved public `NewCache()` signatures and platform-specific transport configuration types.
328328
- Kept platform-specific client construction in the build-tagged files; the shared helper accepts the already constructed raw `Client`.
329329
- The shared cache logic uses the checked `uint32` conversion path that was already present in the POSIX implementation.
330+
- Committed and pushed the raw-cache cleanup as `e762aef` with message `Refactor Go raw cache implementation`.
331+
- GitHub reported the direct push bypassed the pull-request rule for `main`, as requested by the user.
332+
- Reviewed typed service-facade duplication for obvious low-risk and useful cleanup:
333+
- Useful/low-risk: same-package Go POSIX/Windows wrappers in `src/go/pkg/netipc/service/cgroups/`, `src/go/pkg/netipc/service/apps_lookup/`, and `src/go/pkg/netipc/service/cgroups_lookup/`.
334+
- Reason: common wrapper code can move to untagged files inside the same package, while platform transport config conversion remains in build-tagged files.
335+
- Rejected for now: cross-service Go abstraction between apps lookup and cgroups lookup, because it would require generic/internal indirection across public service packages for modest readability gain.
336+
- Rejected for now: Rust apps/cgroups lookup facade abstraction, because it would likely require traits/generics/macros around service-specific public types and would make the facade less direct.
337+
- Applied the low-risk Go typed-facade cleanup:
338+
- `src/go/pkg/netipc/service/cgroups/client_common.go`
339+
- `src/go/pkg/netipc/service/cgroups/cache_common.go`
340+
- `src/go/pkg/netipc/service/apps_lookup/client_common.go`
341+
- `src/go/pkg/netipc/service/cgroups_lookup/client_common.go`
342+
- Left build-tagged Go files responsible only for POSIX/Windows transport config conversion and platform-specific `NewCache()` construction where needed.
330343

331344
## Validation
332345

@@ -371,6 +384,27 @@ Implementation validation:
371384
- total: 0 issues, 0 errors.
372385
- `bash .agents/sow/audit.sh` passed and reported SOW initialization complete and clean.
373386
- `git diff --check` passed.
387+
- Low-risk typed-facade validation:
388+
- `gofmt -w` passed for all touched Go facade files.
389+
- `go test ./pkg/netipc/service/apps_lookup ./pkg/netipc/service/cgroups_lookup ./pkg/netipc/service/cgroups` passed in `src/go`.
390+
- `GOOS=windows GOARCH=amd64 go test -c ./pkg/netipc/service/apps_lookup -o /tmp/plugin-ipc-apps-lookup-windows.test.exe` passed.
391+
- `GOOS=windows GOARCH=amd64 go test -c ./pkg/netipc/service/cgroups_lookup -o /tmp/plugin-ipc-cgroups-lookup-windows.test.exe` passed.
392+
- `GOOS=windows GOARCH=amd64 go test -c ./pkg/netipc/service/cgroups -o /tmp/plugin-ipc-cgroups-windows-b.test.exe` passed.
393+
- `go test ./...` passed in `src/go`.
394+
- JSCPD production-source after the Go typed-facade cleanup:
395+
- previous state after raw-cache cleanup: 40 exact clones, 905 duplicated lines, 11.38%.
396+
- after same-package Go typed-facade cleanup: 36 exact clones, 679 duplicated lines, 8.76%.
397+
- Remaining service-facade clones are cross-service config/type shapes and small constructor similarities; these were rejected for now because removing them would require broader public-package abstraction.
398+
- `codacy-analysis analyze --output-format json` passed:
399+
- Checkov: 0 issues.
400+
- Opengrep/Semgrep: 0 issues.
401+
- Trivy: 0 issues.
402+
- cppcheck: 0 issues.
403+
- ShellCheck: 0 issues.
404+
- Spectral: 0 issues.
405+
- total: 0 issues, 0 errors.
406+
- `bash .agents/sow/audit.sh` passed and reported SOW initialization complete and clean.
407+
- `git diff --check` passed.
374408

375409
Sensitive data gate:
376410

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package apps_lookup
44

55
import (
6-
"github.com/netdata/plugin-ipc/go/pkg/netipc/protocol"
7-
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
86
"github.com/netdata/plugin-ipc/go/pkg/netipc/transport/posix"
97
)
108

@@ -29,36 +27,3 @@ func serverConfigToTransport(config ServerConfig) posix.ServerConfig {
2927
AuthToken: config.AuthToken,
3028
}
3129
}
32-
33-
type Client struct {
34-
inner *raw.Client
35-
}
36-
37-
func NewClient(runDir, serviceName string, config ClientConfig) *Client {
38-
return &Client{inner: raw.NewAppsLookupClient(runDir, serviceName, clientConfigToTransport(config))}
39-
}
40-
41-
func (c *Client) Refresh() bool { return c.inner.Refresh() }
42-
func (c *Client) Ready() bool { return c.inner.Ready() }
43-
func (c *Client) Status() ClientStatus {
44-
return c.inner.Status()
45-
}
46-
func (c *Client) Call(pids []uint32) (*protocol.AppsLookupResponseView, error) {
47-
return c.inner.CallAppsLookup(pids)
48-
}
49-
func (c *Client) Close() { c.inner.Close() }
50-
51-
type Server struct {
52-
inner *raw.Server
53-
}
54-
55-
func NewServer(runDir, serviceName string, config ServerConfig, handler Handler) *Server {
56-
return &Server{inner: raw.NewServer(runDir, serviceName, serverConfigToTransport(config), protocol.MethodAppsLookup, raw.AppsLookupDispatch(handler.Handle))}
57-
}
58-
59-
func NewServerWithWorkers(runDir, serviceName string, config ServerConfig, handler Handler, workerCount int) *Server {
60-
return &Server{inner: raw.NewServerWithWorkers(runDir, serviceName, serverConfigToTransport(config), protocol.MethodAppsLookup, raw.AppsLookupDispatch(handler.Handle), workerCount)}
61-
}
62-
63-
func (s *Server) Run() error { return s.inner.Run() }
64-
func (s *Server) Stop() { s.inner.Stop() }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package apps_lookup
2+
3+
import (
4+
"github.com/netdata/plugin-ipc/go/pkg/netipc/protocol"
5+
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
6+
)
7+
8+
type Client struct {
9+
inner *raw.Client
10+
}
11+
12+
func NewClient(runDir, serviceName string, config ClientConfig) *Client {
13+
return &Client{inner: raw.NewAppsLookupClient(runDir, serviceName, clientConfigToTransport(config))}
14+
}
15+
16+
func (c *Client) Refresh() bool { return c.inner.Refresh() }
17+
func (c *Client) Ready() bool { return c.inner.Ready() }
18+
func (c *Client) Status() ClientStatus {
19+
return c.inner.Status()
20+
}
21+
func (c *Client) Call(pids []uint32) (*protocol.AppsLookupResponseView, error) {
22+
return c.inner.CallAppsLookup(pids)
23+
}
24+
func (c *Client) Close() { c.inner.Close() }
25+
26+
type Server struct {
27+
inner *raw.Server
28+
}
29+
30+
func NewServer(runDir, serviceName string, config ServerConfig, handler Handler) *Server {
31+
return &Server{inner: raw.NewServer(runDir, serviceName, serverConfigToTransport(config), protocol.MethodAppsLookup, raw.AppsLookupDispatch(handler.Handle))}
32+
}
33+
34+
func NewServerWithWorkers(runDir, serviceName string, config ServerConfig, handler Handler, workerCount int) *Server {
35+
return &Server{inner: raw.NewServerWithWorkers(runDir, serviceName, serverConfigToTransport(config), protocol.MethodAppsLookup, raw.AppsLookupDispatch(handler.Handle), workerCount)}
36+
}
37+
38+
func (s *Server) Run() error { return s.inner.Run() }
39+
func (s *Server) Stop() { s.inner.Stop() }

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package apps_lookup
44

55
import (
6-
"github.com/netdata/plugin-ipc/go/pkg/netipc/protocol"
7-
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
86
"github.com/netdata/plugin-ipc/go/pkg/netipc/transport/windows"
97
)
108

@@ -29,36 +27,3 @@ func serverConfigToTransport(config ServerConfig) windows.ServerConfig {
2927
AuthToken: config.AuthToken,
3028
}
3129
}
32-
33-
type Client struct {
34-
inner *raw.Client
35-
}
36-
37-
func NewClient(runDir, serviceName string, config ClientConfig) *Client {
38-
return &Client{inner: raw.NewAppsLookupClient(runDir, serviceName, clientConfigToTransport(config))}
39-
}
40-
41-
func (c *Client) Refresh() bool { return c.inner.Refresh() }
42-
func (c *Client) Ready() bool { return c.inner.Ready() }
43-
func (c *Client) Status() ClientStatus {
44-
return c.inner.Status()
45-
}
46-
func (c *Client) Call(pids []uint32) (*protocol.AppsLookupResponseView, error) {
47-
return c.inner.CallAppsLookup(pids)
48-
}
49-
func (c *Client) Close() { c.inner.Close() }
50-
51-
type Server struct {
52-
inner *raw.Server
53-
}
54-
55-
func NewServer(runDir, serviceName string, config ServerConfig, handler Handler) *Server {
56-
return &Server{inner: raw.NewServer(runDir, serviceName, serverConfigToTransport(config), protocol.MethodAppsLookup, raw.AppsLookupDispatch(handler.Handle))}
57-
}
58-
59-
func NewServerWithWorkers(runDir, serviceName string, config ServerConfig, handler Handler, workerCount int) *Server {
60-
return &Server{inner: raw.NewServerWithWorkers(runDir, serviceName, serverConfigToTransport(config), protocol.MethodAppsLookup, raw.AppsLookupDispatch(handler.Handle), workerCount)}
61-
}
62-
63-
func (s *Server) Run() error { return s.inner.Run() }
64-
func (s *Server) Stop() { s.inner.Stop() }

src/go/pkg/netipc/service/cgroups/cache.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,7 @@ import (
66
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
77
)
88

9-
// Cache is the public L3 client-side cgroups snapshot cache.
10-
type Cache struct {
11-
inner *raw.Cache
12-
}
13-
149
// NewCache creates a new L3 cache. Does NOT connect.
1510
func NewCache(runDir, serviceName string, config ClientConfig) *Cache {
1611
return &Cache{inner: raw.NewCache(runDir, serviceName, clientConfigToTransport(config))}
1712
}
18-
19-
// Refresh drives the L2 client and requests a fresh snapshot.
20-
func (c *Cache) Refresh() bool {
21-
return c.inner.Refresh()
22-
}
23-
24-
// Ready returns true if at least one successful refresh has occurred.
25-
func (c *Cache) Ready() bool {
26-
return c.inner.Ready()
27-
}
28-
29-
// Lookup finds a cached item by hash + name. O(1), no I/O.
30-
func (c *Cache) Lookup(hash uint32, name string) (CacheItem, bool) {
31-
return c.inner.Lookup(hash, name)
32-
}
33-
34-
// Status returns a diagnostic snapshot for the L3 cache.
35-
func (c *Cache) Status() CacheStatus {
36-
return c.inner.Status()
37-
}
38-
39-
// Close frees all cached items and closes the L2 client.
40-
func (c *Cache) Close() {
41-
c.inner.Close()
42-
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cgroups
2+
3+
import (
4+
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
5+
)
6+
7+
// Cache is the public L3 client-side cgroups snapshot cache.
8+
type Cache struct {
9+
inner *raw.Cache
10+
}
11+
12+
// Refresh drives the L2 client and requests a fresh snapshot.
13+
func (c *Cache) Refresh() bool {
14+
return c.inner.Refresh()
15+
}
16+
17+
// Ready returns true if at least one successful refresh has occurred.
18+
func (c *Cache) Ready() bool {
19+
return c.inner.Ready()
20+
}
21+
22+
// Lookup finds a cached item by hash + name. O(1), no I/O.
23+
func (c *Cache) Lookup(hash uint32, name string) (CacheItem, bool) {
24+
return c.inner.Lookup(hash, name)
25+
}
26+
27+
// Status returns a diagnostic snapshot for the L3 cache.
28+
func (c *Cache) Status() CacheStatus {
29+
return c.inner.Status()
30+
}
31+
32+
// Close frees all cached items and closes the L2 client.
33+
func (c *Cache) Close() {
34+
c.inner.Close()
35+
}

src/go/pkg/netipc/service/cgroups/cache_windows.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,7 @@ import (
66
raw "github.com/netdata/plugin-ipc/go/pkg/netipc/service/raw"
77
)
88

9-
// Cache is the public L3 client-side cgroups snapshot cache.
10-
type Cache struct {
11-
inner *raw.Cache
12-
}
13-
149
// NewCache creates a new L3 cache. Does NOT connect.
1510
func NewCache(runDir, serviceName string, config ClientConfig) *Cache {
1611
return &Cache{inner: raw.NewCache(runDir, serviceName, clientConfigToTransport(config))}
1712
}
18-
19-
// Refresh drives the L2 client and requests a fresh snapshot.
20-
func (c *Cache) Refresh() bool {
21-
return c.inner.Refresh()
22-
}
23-
24-
// Ready returns true if at least one successful refresh has occurred.
25-
func (c *Cache) Ready() bool {
26-
return c.inner.Ready()
27-
}
28-
29-
// Lookup finds a cached item by hash + name. O(1), no I/O.
30-
func (c *Cache) Lookup(hash uint32, name string) (CacheItem, bool) {
31-
return c.inner.Lookup(hash, name)
32-
}
33-
34-
// Status returns a diagnostic snapshot for the L3 cache.
35-
func (c *Cache) Status() CacheStatus {
36-
return c.inner.Status()
37-
}
38-
39-
// Close frees all cached items and closes the L2 client.
40-
func (c *Cache) Close() {
41-
c.inner.Close()
42-
}

0 commit comments

Comments
 (0)