Skip to content

Commit

Permalink
Separate windows and unix client_container for infra-ctl
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarocabanas committed Aug 18, 2023
1 parent b86a3bd commit ab931fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
12 changes: 0 additions & 12 deletions pkg/ctl/sender/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import (
"github.com/newrelic/infrastructure-agent/pkg/log"
)

const (
Runtime_docker = "docker"
Runtime_containerd = "containerd"
)

var clog = log.WithComponent("NotificationClient")

// Client is used to notify a running agent process.
Expand All @@ -27,13 +22,6 @@ type Client interface {
GetID() string
}

func NewContainerClient(dockerAPIVersion, containerdNamespace, containerID, runtime string) (Client, error) {
if runtime == Runtime_containerd {
return NewContainerdClient(containerdNamespace, containerID)
}
return NewDockerClient(dockerAPIVersion, containerID)
}

// NewAutoDetectedClient will try to detect the NRIA instance type and return a notification client for it.
func NewAutoDetectedClient(dockerAPIVersion, containerdNamespace, containerRuntime string) (Client, error) {
pid, err := detection.GetInfraAgentProcess()
Expand Down
17 changes: 17 additions & 0 deletions pkg/ctl/sender/client_container_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2023 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//go:build linux || darwin

package sender

const (
Runtime_docker = "docker"

Check failure on line 8 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-linux / Run Linter

var-naming: don't use underscores in Go names; const Runtime_docker should be RuntimeDocker (revive)

Check failure on line 8 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-macos / Lint tests

var-naming: don't use underscores in Go names; const Runtime_docker should be RuntimeDocker (revive)
Runtime_containerd = "containerd"

Check failure on line 9 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-linux / Run Linter

var-naming: don't use underscores in Go names; const Runtime_containerd should be RuntimeContainerd (revive)

Check failure on line 9 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-macos / Lint tests

var-naming: don't use underscores in Go names; const Runtime_containerd should be RuntimeContainerd (revive)
)

func NewContainerClient(dockerAPIVersion, containerdNamespace, containerID, runtime string) (Client, error) {

Check failure on line 12 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-linux / Run Linter

NewContainerClient returns interface (github.com/newrelic/infrastructure-agent/pkg/ctl/sender.Client) (ireturn)

Check failure on line 12 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-macos / Lint tests

NewContainerClient returns interface (github.com/newrelic/infrastructure-agent/pkg/ctl/sender.Client) (ireturn)
if runtime == Runtime_containerd {
return NewContainerdClient(containerdNamespace, containerID)
}
return NewDockerClient(dockerAPIVersion, containerID)

Check failure on line 16 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-linux / Run Linter

return statements should not be cuddled if block has more than two lines (wsl)

Check failure on line 16 in pkg/ctl/sender/client_container_unix.go

View workflow job for this annotation

GitHub Actions / linter-macos / Lint tests

return statements should not be cuddled if block has more than two lines (wsl)
}
7 changes: 7 additions & 0 deletions pkg/ctl/sender/client_container_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package sender

func NewContainerClient(dockerAPIVersion, containerdNamespace, containerID, runtime string) (Client, error) {
return NewDockerClient(dockerAPIVersion, containerID)
}
6 changes: 4 additions & 2 deletions pkg/ctl/sender/client_containerd.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// Copyright 2023 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//go:build linux || darwin

package sender

import (
Expand Down Expand Up @@ -59,7 +61,7 @@ func (c *ContainerdClient) Notify(ctx context.Context, _ ipc.Message) error {
return err
}

// Return the identification for the notified agent.
// GetID returns the identification for the notified agent.
func (c *ContainerdClient) GetID() string {
return c.containerID
}
2 changes: 1 addition & 1 deletion pkg/metrics/docker_sampler_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDocker(t *testing.T) {
ctx.On("GetServiceForPid", mock.Anything).Return("", false)

procs := NewProcsMonitor(ctx)
procs.containerSampler = docker
procs.containerSamplers = []ContainerSampler{docker}
procs.getAllProcs = mockGetAllWin32Procs
procs.getMemoryInfo = mockGetMemoryInfo
procs.getStatus = mockGetStatus
Expand Down

0 comments on commit ab931fb

Please sign in to comment.