mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-18 18:49:05 +02:00
wmi: add generic wmi collector (#2530)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a67a64c55c
commit
88034b818e
@@ -51,6 +51,11 @@ type Operation struct {
|
||||
reserved1 uint64
|
||||
reserved2 uintptr
|
||||
ft *OperationFT
|
||||
|
||||
// completed is set once GetInstance has returned the final result. It is
|
||||
// Go-only state after the MI_Operation fields, which MI never writes past;
|
||||
// every Operation is allocated in Go.
|
||||
completed bool
|
||||
}
|
||||
|
||||
// OperationFT represents the function table for Operation.
|
||||
@@ -106,14 +111,17 @@ func (o *Operation) Close() error {
|
||||
return ErrNotInitialized
|
||||
}
|
||||
|
||||
moreResults := true
|
||||
// MI_Operation_Close blocks until the final result has been delivered, so
|
||||
// pending results must be read first. Reading them would cost the full
|
||||
// remaining result set, so the operation is cancelled, which makes the
|
||||
// final result arrive right away. A fully read operation needs neither.
|
||||
if !o.completed {
|
||||
_ = o.Cancel()
|
||||
|
||||
var err error
|
||||
|
||||
for moreResults {
|
||||
_, moreResults, err = o.GetInstance()
|
||||
if err != nil {
|
||||
break
|
||||
for !o.completed {
|
||||
if _, _, err := o.GetInstance(); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +198,9 @@ func (o *Operation) GetInstance() (*Instance, bool, error) {
|
||||
errorMessage = fmt.Sprintf(" (%s)", errorMessage)
|
||||
}
|
||||
|
||||
// A failed result is always the final one.
|
||||
o.completed = true
|
||||
|
||||
return nil, false, fmt.Errorf("instance result: %w%s", instanceResult, errorMessage)
|
||||
}
|
||||
|
||||
@@ -197,6 +208,10 @@ func (o *Operation) GetInstance() (*Instance, bool, error) {
|
||||
return nil, false, result
|
||||
}
|
||||
|
||||
if moreResults != True {
|
||||
o.completed = true
|
||||
}
|
||||
|
||||
return instance, moreResults == True, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user