Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert pkg/util/winutil to module #20851

Merged
merged 25 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@
/pkg/util/cgroups/ @DataDog/container-integrations
/pkg/util/retry/ @DataDog/container-integrations
/pkg/util/intern/ @DataDog/ebpf-platform
/pkg/util/crashreport/ @DataDog/windows-agent
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved
/pkg/util/pdhutil/ @DataDog/windows-agent
/pkg/util/winutil/ @DataDog/windows-agent
/pkg/languagedetection @DataDog/processes @DataDog/universal-service-monitoring
/pkg/logs/ @DataDog/agent-metrics-logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,23 @@ import (
"fmt"
"strings"

"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"go.uber.org/fx"
"golang.org/x/sys/windows/registry"
yaml "gopkg.in/yaml.v2"

"github.com/DataDog/datadog-agent/comp/checks/agentcrashdetect"
compsysconfig "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
comptraceconfig "github.com/DataDog/datadog-agent/comp/trace/config"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"

"github.com/DataDog/datadog-agent/pkg/collector/check"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/system/wincrashdetect/probe"

"github.com/DataDog/datadog-agent/comp/checks/agentcrashdetect"
compsysconfig "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
comptraceconfig "github.com/DataDog/datadog-agent/comp/trace/config"

"github.com/DataDog/datadog-agent/pkg/internaltelemetry"
traceconfig "github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/util/crashreport"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/winutil/crashreport"
"golang.org/x/sys/windows/registry"
yaml "gopkg.in/yaml.v2"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion comp/checks/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/DataDog/datadog-agent/comp/core"
comptraceconfig "github.com/DataDog/datadog-agent/comp/trace/config"
"github.com/DataDog/datadog-agent/pkg/util/crashreport"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/DataDog/datadog-agent/pkg/util/winutil/crashreport"
"go.uber.org/fx"
)

Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ replace (
github.com/DataDog/datadog-agent/pkg/process/util/api => ./pkg/process/util/api
github.com/DataDog/datadog-agent/pkg/proto => ./pkg/proto
github.com/DataDog/datadog-agent/pkg/remoteconfig/state => ./pkg/remoteconfig/state
github.com/DataDog/datadog-agent/pkg/secrets => ./pkg/secrets
github.com/DataDog/datadog-agent/pkg/security/secl => ./pkg/security/secl
github.com/DataDog/datadog-agent/pkg/status/health => ./pkg/status/health
github.com/DataDog/datadog-agent/pkg/tagset => ./pkg/tagset/
Expand All @@ -63,6 +64,7 @@ replace (
github.com/DataDog/datadog-agent/pkg/util/statstracker => ./pkg/util/statstracker
github.com/DataDog/datadog-agent/pkg/util/system/socket => ./pkg/util/system/socket/
github.com/DataDog/datadog-agent/pkg/util/testutil => ./pkg/util/testutil
github.com/DataDog/datadog-agent/pkg/util/winutil => ./pkg/util/winutil/
github.com/DataDog/datadog-agent/pkg/version => ./pkg/version
)

Expand Down Expand Up @@ -595,6 +597,7 @@ require (
github.com/DataDog/datadog-agent/pkg/orchestrator/model v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/process/util/api v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/proto v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/secrets v0.0.0-00010101000000-000000000000
github.com/DataDog/datadog-agent/pkg/status/health v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/tagset v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/telemetry v0.50.0-rc.2
Expand All @@ -611,6 +614,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/sort v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/util/statstracker v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/util/testutil v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/util/winutil v0.0.0-00010101000000-000000000000
github.com/DataDog/datadog-agent/pkg/version v0.50.0-rc.2
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.8.0
github.com/aquasecurity/trivy v0.0.0-00010101000000-000000000000
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/system/cpu/cpu_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/check"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
"github.com/DataDog/datadog-agent/pkg/util/pdhutil"
)

const cpuCheckName = "cpu"
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/system/cpu/cpu_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
gohaicpu "github.com/DataDog/datadog-agent/pkg/gohai/cpu"
gohaiutils "github.com/DataDog/datadog-agent/pkg/gohai/utils"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/pdhutil"
)

func CPUInfo() *gohaicpu.Info {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
"github.com/DataDog/datadog-agent/pkg/util/pdhutil"

"golang.org/x/sys/windows"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/pdhutil"
)

func testGetDriveType(drive string) uintptr {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"github.com/DataDog/datadog-agent/pkg/collector/check"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
"github.com/DataDog/datadog-agent/pkg/util/pdhutil"
)

const fileHandlesCheckName = "file_handle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/pdhutil"
)

func TestFhCheckWindows(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/system/memory/memory_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"

core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/util/pdhutil"
"github.com/DataDog/datadog-agent/pkg/util/winutil"
"github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
)

// For testing purpose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/pdhutil"
"github.com/DataDog/datadog-agent/pkg/util/winutil"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
)

func VirtualMemory() (*winutil.VirtualMemoryStat, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ package wincrashdetect
import (
"fmt"

"golang.org/x/sys/windows/registry"
yaml "gopkg.in/yaml.v2"

"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"github.com/DataDog/datadog-agent/pkg/collector/check"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/system/wincrashdetect/probe"
"github.com/DataDog/datadog-agent/pkg/metrics/event"
"github.com/DataDog/datadog-agent/pkg/util/crashreport"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/winutil/crashreport"
"golang.org/x/sys/windows/registry"
yaml "gopkg.in/yaml.v2"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"github.com/DataDog/datadog-agent/pkg/collector/check"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
"github.com/DataDog/datadog-agent/pkg/util/pdhutil"
)

const winprocCheckName = "winproc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
pdhtest "github.com/DataDog/datadog-agent/pkg/util/pdhutil"
)

func TestWinprocCheckWindows(t *testing.T) {
Expand Down
47 changes: 35 additions & 12 deletions pkg/network/protocols/http/etw_http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ package http
import (
"encoding/binary"
"errors"
"fmt"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -329,8 +330,8 @@ func completeReqRespTracking(eventInfo *etw.DDEtwEventInfo, httpConnLink *HttpCo
log.Infof(" ConnActivityId: %v\n", etw.FormatGUID(httpConnLink.connActivityId))
log.Infof(" ActivityId: %v\n", etw.FormatGUID(eventInfo.Event.ActivityId))
if connFound {
log.Infof(" Local: %v\n", etw.IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", etw.IPFormat(connOpen.conn.tup, false))
log.Infof(" Local: %v\n", IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", IPFormat(connOpen.conn.tup, false))
log.Infof(" Family: %v\n", connOpen.conn.tup.Family)
}
log.Infof(" AppPool: %v\n", httpConnLink.http.AppPool)
Expand All @@ -345,8 +346,8 @@ func completeReqRespTracking(eventInfo *etw.DDEtwEventInfo, httpConnLink *HttpCo
log.Infof("%v. %v L[%v], R[%v], F[%v], P[%v], C[%v], V[%v], U[%v]\n",
completedRequestCount,
etw.FormatUnixTime(httpConnLink.http.Txn.RequestStarted),
etw.IPFormat(connOpen.conn.tup, true),
etw.IPFormat(connOpen.conn.tup, false),
IPFormat(connOpen.conn.tup, true),
IPFormat(connOpen.conn.tup, false),
connOpen.conn.tup.Family,
httpConnLink.http.AppPool,
httpConnLink.http.Txn.ResponseStatusCode,
Expand Down Expand Up @@ -504,8 +505,8 @@ func httpCallbackOnHTTPConnectionTraceTaskConnConn(eventInfo *etw.DDEtwEventInfo
if HttpServiceLogVerbosity == HttpServiceLogVeryVerbose {
log.Infof(" Time: %v\n", etw.FormatUnixTime(connOpen.conn.connected))
log.Infof(" ActivityId: %v\n", etw.FormatGUID(eventInfo.Event.ActivityId))
log.Infof(" Local: %v\n", etw.IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", etw.IPFormat(connOpen.conn.tup, false))
log.Infof(" Local: %v\n", IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", IPFormat(connOpen.conn.tup, false))
log.Infof(" Family: %v\n", connOpen.conn.tup.Family)
log.Infof("\n")
}
Expand Down Expand Up @@ -542,8 +543,8 @@ func httpCallbackOnHTTPConnectionTraceTaskConnClose(eventInfo *etw.DDEtwEventInf
if found {
log.Infof(" ActivityId: %v, Local[%v], Remote[%v], Family[%v]\n",
etw.FormatGUID(eventInfo.Event.ActivityId),
etw.IPFormat(connOpen.conn.tup, true),
etw.IPFormat(connOpen.conn.tup, false),
IPFormat(connOpen.conn.tup, true),
IPFormat(connOpen.conn.tup, false),
connOpen.conn.tup.Family)
} else {
log.Infof(" ActivityId: %v not found\n", etw.FormatGUID(eventInfo.Event.ActivityId))
Expand Down Expand Up @@ -634,8 +635,8 @@ func httpCallbackOnHTTPRequestTraceTaskRecvReq(eventInfo *etw.DDEtwEventInfo) {
log.Infof(" ActivityId: %v\n", etw.FormatGUID(eventInfo.Event.ActivityId))
log.Infof(" RelActivityId: %v\n", etw.FormatGUID(*eventInfo.RelatedActivityId))
if connFound {
log.Infof(" Local: %v\n", etw.IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", etw.IPFormat(connOpen.conn.tup, false))
log.Infof(" Local: %v\n", IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", IPFormat(connOpen.conn.tup, false))
log.Infof(" Family: %v\n", connOpen.conn.tup.Family)
}
log.Infof("\n")
Expand Down Expand Up @@ -795,8 +796,8 @@ func httpCallbackOnHTTPRequestTraceTaskDeliver(eventInfo *etw.DDEtwEventInfo) {
log.Infof(" AppPool: %v\n", httpConnLink.http.AppPool)
log.Infof(" Url: %v\n", httpConnLink.url)
if connFound {
log.Infof(" Local: %v\n", etw.IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", etw.IPFormat(connOpen.conn.tup, false))
log.Infof(" Local: %v\n", IPFormat(connOpen.conn.tup, true))
log.Infof(" Remote: %v\n", IPFormat(connOpen.conn.tup, false))
log.Infof(" Family: %v\n", connOpen.conn.tup.Family)
}
log.Infof("\n")
Expand Down Expand Up @@ -1336,3 +1337,25 @@ func (hei *EtwInterface) OnStop() {
iisConfig = nil
}
}
func ipAndPortFromTup(tup driver.ConnTupleType, local bool) ([16]uint8, uint16) {
if local {
return tup.LocalAddr, tup.LocalPort
}
return tup.RemoteAddr, tup.RemotePort
}

// IPFormat takes a binary ip representation and returns a string type
func IPFormat(tup driver.ConnTupleType, local bool) string {
ip, port := ipAndPortFromTup(tup, local)

if tup.Family == 2 {
// IPv4
return fmt.Sprintf("%v:%v", ip4format(ip), port)
} else if tup.Family == 23 {
// IPv6
return fmt.Sprintf("[%v]:%v", ip6format(ip), port)
} else {
// everything else
return "<UNKNOWN>"
}
}
guyarb marked this conversation as resolved.
Show resolved Hide resolved
guyarb marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
guyarb marked this conversation as resolved.
Show resolved Hide resolved
guyarb marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file removed pkg/network/protocols/tls/java/testdata/Wait.class
guyarb marked this conversation as resolved.
Show resolved Hide resolved
guyarb marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file removed pkg/network/protocols/tls/java/testdata/Wget$1.class
guyarb marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file removed pkg/network/protocols/tls/java/testdata/Wget$2.class
guyarb marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
guyarb marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file removed pkg/network/protocols/tls/java/testdata/Wget.class
guyarb marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/process/procutil/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"golang.org/x/sys/windows"

"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/pdhutil"
"github.com/DataDog/datadog-agent/pkg/util/winutil"
"github.com/DataDog/datadog-agent/pkg/util/winutil/pdhutil"
)

var (
Expand Down
57 changes: 57 additions & 0 deletions pkg/secrets/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module github.com/DataDog/datadog-agent/pkg/secrets
hush-hush marked this conversation as resolved.
Show resolved Hide resolved

go 1.20

replace (
github.com/DataDog/datadog-agent/comp/core/telemetry => ../../comp/core/telemetry/
github.com/DataDog/datadog-agent/pkg/telemetry => ../telemetry/
github.com/DataDog/datadog-agent/pkg/util/fxutil => ../util/fxutil/
github.com/DataDog/datadog-agent/pkg/util/log => ../util/log/
github.com/DataDog/datadog-agent/pkg/util/scrubber => ../util/scrubber/
github.com/DataDog/datadog-agent/pkg/util/winutil => ../util/winutil/
)

require (
github.com/DataDog/datadog-agent/pkg/telemetry v0.0.0-00010101000000-000000000000
github.com/DataDog/datadog-agent/pkg/util/log v0.0.0-00010101000000-000000000000
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.50.0-rc.2
github.com/DataDog/datadog-agent/pkg/util/winutil v0.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.14.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/DataDog/datadog-agent/comp/core/telemetry v0.50.0-rc.2 // indirect
github.com/DataDog/datadog-agent/pkg/util/fxutil v0.50.0-rc.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.42.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/dig v1.17.0 // indirect
go.uber.org/fx v1.18.2 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.23.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading