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

fix: validation not performed #163

Merged
merged 5 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,13 @@ func run() {
}
go reportStateDaemon(reportState, errCh)

var canceled bool
for i := 0; i < 2; {
select {
case <-reloadSigChan:
println("Reloading...")
wCancel()
canceled = true
case err := <-errCh:
if i == 0 {
tasks.CloseSend()
Expand All @@ -349,7 +351,9 @@ func run() {
}
}

wCancel()
if !canceled {
wCancel()
}
close(errCh)

retry()
Expand Down Expand Up @@ -862,8 +866,8 @@ func handleApplyConfigTask(task *pb.Task) {
return
}

println("Will reload workers in 30 seconds")
time.AfterFunc(time.Second*30, func() {
println("Will reload workers in 10 seconds")
time.AfterFunc(10*time.Second, func() {
println("Applying new configuration...")
agentConfig.Apply(&tmpConfig)
agentConfig.Save()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/prometheus-community/pro-bing v0.4.1
github.com/quic-go/quic-go v0.40.1
github.com/refraction-networking/utls v1.6.3
github.com/shirou/gopsutil/v4 v4.24.12
github.com/shirou/gopsutil/v4 v4.25.1
github.com/tidwall/gjson v1.18.0
github.com/urfave/cli/v2 v2.27.5
golang.org/x/net v0.32.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shirou/gopsutil/v4 v4.24.12 h1:qvePBOk20e0IKA1QXrIIU+jmk+zEiYVVx06WjBRlZo4=
github.com/shirou/gopsutil/v4 v4.24.12/go.mod h1:DCtMPAad2XceTeIAbGyVfycbYQNBGk2P8cvDi7/VN9o=
github.com/shirou/gopsutil/v4 v4.25.1 h1:QSWkTc+fu9LTAWfkZwZ6j8MSUk4A2LV7rbH0ZqmLjXs=
github.com/shirou/gopsutil/v4 v4.25.1/go.mod h1:RoUCUpndaJFtT+2zsZzzmhvbfGoDCJ7nFXKJf8GqJbI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
6 changes: 3 additions & 3 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type AgentConfig struct {
DisableAutoUpdate bool `koanf:"disable_auto_update" json:"disable_auto_update"` // 关闭自动更新
DisableForceUpdate bool `koanf:"disable_force_update" json:"disable_force_update"` // 关闭强制更新
DisableCommandExecute bool `koanf:"disable_command_execute" json:"disable_command_execute"` // 关闭命令执行
ReportDelay int `koanf:"report_delay" json:"report_delay"` // 报告间隔
ReportDelay uint32 `koanf:"report_delay" json:"report_delay"` // 报告间隔
TLS bool `koanf:"tls" json:"tls"` // 是否使用TLS加密传输至服务端
InsecureTLS bool `koanf:"insecure_tls" json:"insecure_tls"` // 是否禁用证书检查
UseIPv6CountryCode bool `koanf:"use_ipv6_country_code" json:"use_ipv6_country_code"` // 默认优先展示IPv6旗帜
Expand All @@ -42,7 +42,7 @@ type AgentConfig struct {
DisableSendQuery bool `koanf:"disable_send_query" json:"disable_send_query"` // 关闭发送TCP/ICMP/HTTP请求
IPReportPeriod uint32 `koanf:"ip_report_period" json:"ip_report_period"` // IP上报周期
SelfUpdatePeriod uint32 `koanf:"self_update_period" json:"self_update_period"` // 自动更新周期
CustomIPApi []string `koanf:"custom_ip_api" json:"custom_ip_api,omitempty"` // 自定义 IP API
CustomIPApi []string `koanf:"custom_ip_api" json:"custom_ip_api,omitempty"` // 自定义 IP API // 重载间隔

k *koanf.Koanf `json:"-"`
filePath string `json:"-"`
Expand Down Expand Up @@ -78,7 +78,7 @@ func (c *AgentConfig) Read(path string) error {
if c.UUID == "" {
if uuid, err := uuid.GenerateUUID(); err == nil {
c.UUID = uuid
return saveOnce()
saveOnce()
} else {
return fmt.Errorf("generate UUID failed: %v", err)
}
Expand Down
25 changes: 14 additions & 11 deletions pkg/monitor/gpu/gpu_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func findDevices(key string) ([]string, error) {
}

cfStr := CFStringCreateWithCString(kCFAllocatorDefault, key, kCFStringEncodingUTF8)
result, _, _ := findProperties(service, uintptr(cfStr), 0)
r, _ := findProperties(service, uintptr(cfStr), 0)
result, _ := r.(string)
IOObjectRelease(service)

if util.ContainsStr(validVendors, result) {
Expand All @@ -173,8 +174,8 @@ func findDevices(key string) ([]string, error) {

func findUtilization(key, dictKey string) (int, error) {
var iterator ioIterator
var result int
var err error
result := 0

iv := IOServiceGetMatchingServices(kIOMainPortDefault, uintptr(IOServiceMatching(IOSERVICE_GPU)), &iterator)
if iv != KERN_SUCCESS {
Expand All @@ -192,12 +193,14 @@ func findUtilization(key, dictKey string) (int, error) {
cfStr := CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringEncoding(kCFStringEncodingUTF8))
cfDictStr := CFStringCreateWithCString(kCFAllocatorDefault, dictKey, CFStringEncoding(kCFStringEncodingUTF8))

_, result, err = findProperties(service, uintptr(cfStr), uintptr(cfDictStr))
r, rerr := findProperties(service, uintptr(cfStr), uintptr(cfDictStr))
result, _ = r.(int)

CFRelease(uintptr(cfStr))
CFRelease(uintptr(cfDictStr))

if err != nil {
if rerr != nil {
err = rerr
IOObjectRelease(service)
continue
} else if result != 0 {
Expand All @@ -211,7 +214,7 @@ func findUtilization(key, dictKey string) (int, error) {
return result, err
}

func findProperties(service ioRegistryEntry, key, dictKey uintptr) (string, int, error) {
func findProperties(service ioRegistryEntry, key, dictKey uintptr) (any, error) {
properties := IORegistryEntrySearchCFProperty(service, kIOServicePlane, key, kCFAllocatorDefault, kIORegistryIterateRecursively)
ptrValue := uintptr(properties)
if properties != nil {
Expand All @@ -222,26 +225,26 @@ func findProperties(service ioRegistryEntry, key, dictKey uintptr) (string, int,
buf := make([]byte, length-1)
CFStringGetCString(ptrValue, &buf[0], length, uint32(kCFStringEncodingUTF8))
CFRelease(ptrValue)
return string(buf), 0, nil
return string(buf), nil
case CFDataGetTypeID():
length := CFDataGetLength(ptrValue)
bin := unsafe.String((*byte)(CFDataGetBytePtr(ptrValue)), length)
CFRelease(ptrValue)
return bin, 0, nil
return bin, nil
// PerformanceStatistics
case CFDictionaryGetTypeID():
cfValue := CFDictionaryGetValue(ptrValue, dictKey)
if cfValue != nil {
var value int
if CFNumberGetValue(uintptr(cfValue), kCFNumberIntType, uintptr(unsafe.Pointer(&value))) {
return "", value, nil
return value, nil
} else {
return "", 0, fmt.Errorf("failed to exec CFNumberGetValue")
return nil, fmt.Errorf("failed to exec CFNumberGetValue")
}
} else {
return "", 0, fmt.Errorf("failed to exec CFDictionaryGetValue")
return nil, fmt.Errorf("failed to exec CFDictionaryGetValue")
}
}
}
return "", 0, fmt.Errorf("failed to exec IORegistryEntrySearchCFProperty")
return nil, fmt.Errorf("failed to exec IORegistryEntrySearchCFProperty")
}
2 changes: 1 addition & 1 deletion pkg/processgroup/process_group.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !windows
//go:build unix && !aix

package processgroup

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/kill_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !windows
//go:build unix && !aix

package util

Expand Down
Loading