Skip to content

Commit

Permalink
Fix hcsshim.ProcessStat undefined issue
Browse files Browse the repository at this point in the history
1. Add windows build tag to fix building cw agent on Windows
2. Downgrade internal/aws/containerinsight from 0.92 0.89
3. Separate unit tests in util.go specific for Windows
4. Fix util unit tests applicable for Windows
5. Fix goporto issue
6. Fix lint issue
7. Fix regression in unit tests caused due to rebasing mainlin
  • Loading branch information
KlwntSingh committed Mar 2, 2024
1 parent e19435c commit c1bda62
Show file tree
Hide file tree
Showing 32 changed files with 144 additions and 73 deletions.
3 changes: 3 additions & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ require (
github.com/IBM/sarama v1.42.1 // indirect
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/ReneKroon/ttlcache/v2 v2.11.0 // indirect
github.com/SAP/go-hdb v1.6.2 // indirect
github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2 // indirect
Expand Down Expand Up @@ -297,8 +298,10 @@ require (
github.com/cloudfoundry-incubator/uaago v0.0.0-20190307164349-8136b7bbe76e // indirect
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/cgroups/v3 v3.0.2 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/containerd/containerd v1.7.7 // indirect
github.com/containerd/ttrpc v1.2.2 // indirect
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
Expand Down
6 changes: 5 additions & 1 deletion cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ require (
github.com/nginxinc/nginx-prometheus-exporter v0.8.1-0.20201110005315-f5a5f8086c19 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.92.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s v0.89.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ require (
github.com/nginxinc/nginx-prometheus-exporter v0.8.1-0.20201110005315-f5a5f8086c19 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.92.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s v0.89.0 // indirect
Expand Down
12 changes: 0 additions & 12 deletions internal/aws/containerinsight/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package containerinsight
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -867,14 +866,3 @@ func TestConvertToOTLPMetricsForPodContainerStatusMetrics(t *testing.T) {
md = ConvertToOTLPMetrics(fields, tags, zap.NewNop())
checkMetricsAreExpected(t, md, fields, tags, expectedUnits)
}

func TestHostProcessContainer(t *testing.T) {
os.Setenv(RunInContainer, "True")
assert.Equal(t, IsWindowsHostProcessContainer(), false)

os.Setenv(RunAsHostProcessContainer, "True")
assert.Equal(t, IsWindowsHostProcessContainer(), true)

os.Unsetenv(RunInContainer)
os.Unsetenv(RunAsHostProcessContainer)
}
21 changes: 21 additions & 0 deletions internal/aws/containerinsight/utils_windows_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package containerinsight // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight"

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestHostProcessContainer(t *testing.T) {
t.Setenv(RunInContainer, "True")
assert.Equal(t, IsWindowsHostProcessContainer(), false)

t.Setenv(RunAsHostProcessContainer, "True")
assert.Equal(t, IsWindowsHostProcessContainer(), true)
}
5 changes: 4 additions & 1 deletion internal/aws/k8s/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ go 1.20

require (
github.com/aws/aws-sdk-go v1.47.10
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0
)

require (
Expand Down Expand Up @@ -37,6 +37,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/collector/pdata v1.0.0-rcv0018 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
Expand All @@ -45,6 +46,8 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions internal/aws/k8s/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions internal/kubelet/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"regexp"
"strings"
Expand All @@ -27,7 +26,6 @@ import (
"go.uber.org/zap"
"k8s.io/client-go/tools/clientcmd"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
)

Expand Down Expand Up @@ -73,32 +71,6 @@ func TestNewTLSClientProvider(t *testing.T) {
require.NotNil(t, tcc.RootCAs)
}

func TestSAPathInHostProcessContainer(t *testing.T) {
// todo: Remove this workaround func when Windows AMIs has containerd 1.7 which solves upstream bug.

// Test default SA cert and token.
assert.Equal(t, svcAcctCACertPath, "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
assert.Equal(t, svcAcctTokenPath, "/var/run/secrets/kubernetes.io/serviceaccount/token")

// Test SA cert and token when run inside container.
os.Setenv(containerinsight.RunInContainer, "True")
updateSVCPath()
assert.Equal(t, svcAcctCACertPath, "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
assert.Equal(t, svcAcctTokenPath, "/var/run/secrets/kubernetes.io/serviceaccount/token")

// Test SA cert and token when run inside host process container.
os.Setenv(containerinsight.RunAsHostProcessContainer, "True")
os.Setenv("CONTAINER_SANDBOX_MOUNT_POINT", "test123456")
updateSVCPath()
assert.Equal(t, svcAcctCACertPath, "test123456/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
assert.Equal(t, svcAcctTokenPath, "test123456/var/run/secrets/kubernetes.io/serviceaccount/token")

os.Unsetenv("CONTAINER_SANDBOX_MOUNT_POINT")
os.Unsetenv(containerinsight.RunInContainer)
os.Unsetenv(containerinsight.RunAsHostProcessContainer)
updateSVCPath()
}

func TestNewSAClientProvider(t *testing.T) {
p, err := NewClientProvider("localhost:9876", &ClientConfig{
APIConfig: k8sconfig.APIConfig{
Expand Down
2 changes: 1 addition & 1 deletion internal/kubelet/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/kubele
go 1.20

require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.89.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.89.0
github.com/stretchr/testify v1.8.4
Expand Down
1 change: 0 additions & 1 deletion internal/kubelet/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion receiver/awscontainerinsightreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-kit/log v0.2.1
github.com/google/cadvisor v0.48.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.89.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s v0.89.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/metrics v0.89.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.89.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package extractors
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors"

import (
ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package extractors
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors"

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package extractors
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors"

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors"
//go:build windows
// +build windows

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors"

import (
ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors"
//go:build windows
// +build windows

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors"

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors"
//go:build windows
// +build windows

package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors"

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package extractors

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package hcsshim
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package hcsshim // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim"

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package hcsshim // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8s_windox2"
package hcsshim // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim"

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build windows
// +build windows

package hcsshim

import (
Expand Down
Loading

0 comments on commit c1bda62

Please sign in to comment.