feat: Tolerate collector failures (#1769)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2024-11-25 21:27:31 +01:00
committed by GitHub
parent fd76be38e0
commit 1a4c6c5ce7
121 changed files with 1726 additions and 1221 deletions

View File

@@ -31,6 +31,7 @@ const (
LocaleEnglish = "en-us"
)
//nolint:gochecknoglobals
var (
// DestinationOptionsTimeout is the key for the timeout option.
//
@@ -43,6 +44,7 @@ var (
DestinationOptionsUILocale = UTF16PtrFromString[*uint16]("__MI_DESTINATIONOPTIONS_UI_LOCALE")
)
//nolint:gochecknoglobals
var (
modMi = windows.NewLazySystemDLL("mi.dll")

View File

@@ -27,7 +27,10 @@ import (
"golang.org/x/sys/windows"
)
// We have to registry a global callback function, since the amount of callbacks is limited.
// operationUnmarshalCallbacksInstanceResult registers a global callback function.
// The amount of system callbacks is limited to 2000.
//
//nolint:gochecknoglobals
var operationUnmarshalCallbacksInstanceResult = sync.OnceValue[uintptr](func() uintptr {
// Workaround for a deadlock issue in go.
// Ref: https://github.com/golang/go/issues/55015
@@ -135,7 +138,7 @@ func (o *OperationUnmarshalCallbacks) InstanceResult(
element, err := instance.GetElement(miTag)
if err != nil {
o.errCh <- fmt.Errorf("failed to get element: %w", err)
o.errCh <- fmt.Errorf("failed to get element %s: %w", miTag, err)
return 0
}
@@ -149,9 +152,8 @@ func (o *OperationUnmarshalCallbacks) InstanceResult(
field.SetInt(int64(element.value))
case ValueTypeSTRING:
if element.value == 0 {
o.errCh <- fmt.Errorf("%s: invalid pointer: value is nil", miTag)
return 0
// value is null
continue
}
// Convert the UTF-16 string to a Go string

View File

@@ -29,6 +29,8 @@ import (
// OperationOptionsTimeout is the key for the timeout option.
//
// https://github.com/microsoft/win32metadata/blob/527806d20d83d3abd43d16cd3fa8795d8deba343/generation/WinSDK/RecompiledIdlHeaders/um/mi.h#L9240
//
//nolint:gochecknoglobals
var OperationOptionsTimeout = UTF16PtrFromString[*uint16]("__MI_OPERATIONOPTIONS_TIMEOUT")
// OperationFlags represents the flags for an operation.
@@ -214,7 +216,7 @@ func (o *Operation) Unmarshal(dst any) error {
element, err := instance.GetElement(miTag)
if err != nil {
return fmt.Errorf("failed to get element: %w", err)
return fmt.Errorf("failed to get element %s: %w", miTag, err)
}
switch element.valueType {

View File

@@ -36,10 +36,8 @@ func NewQueryDialect(queryDialect string) (QueryDialect, error) {
return windows.UTF16PtrFromString(queryDialect)
}
var (
QueryDialectWQL = utils.Must(NewQueryDialect("WQL"))
QueryDialectCQL = utils.Must(NewQueryDialect("CQL"))
)
//nolint:gochecknoglobals
var QueryDialectWQL = utils.Must(NewQueryDialect("WQL"))
type Namespace *uint16
@@ -47,6 +45,7 @@ func NewNamespace(namespace string) (Namespace, error) {
return windows.UTF16PtrFromString(namespace)
}
//nolint:gochecknoglobals
var (
NamespaceRootCIMv2 = utils.Must(NewNamespace("root/CIMv2"))
NamespaceRootWindowsFSRM = utils.Must(NewNamespace("root/microsoft/windows/fsrm"))