mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-24 13:46:36 +00:00
feat: Tolerate collector failures (#1769)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user