Public source validation / validate (push) Failing after 3m8s
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package network
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/itworx/pulse/internal/host"
|
|
"github.com/itworx/pulse/internal/service"
|
|
)
|
|
|
|
type Aggregator struct {
|
|
Host host.Provider
|
|
Services service.Provider
|
|
Limits Limits
|
|
Now func() time.Time
|
|
}
|
|
|
|
func (a Aggregator) Snapshot(ctx context.Context) (Snapshot, error) {
|
|
if ctx == nil {
|
|
return Snapshot{}, errors.New("network context is nil")
|
|
}
|
|
if err := ctx.Err(); err != nil {
|
|
return Snapshot{}, err
|
|
}
|
|
now := time.Now().UTC()
|
|
if a.Now != nil {
|
|
now = a.Now().UTC()
|
|
}
|
|
hostSnapshot := host.UnknownSnapshot(now, "host", "agent", "source_unavailable")
|
|
if a.Host != nil {
|
|
next, err := a.Host.Snapshot(ctx)
|
|
if err != nil {
|
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
|
return Snapshot{}, err
|
|
}
|
|
hostSnapshot = host.UnknownSnapshot(now, "host", "agent", "source_unavailable")
|
|
} else {
|
|
hostSnapshot = next
|
|
}
|
|
}
|
|
serviceSnapshot := service.UnknownSnapshot(now, "source_unavailable")
|
|
if a.Services != nil {
|
|
next, err := a.Services.Snapshot(ctx)
|
|
if err != nil {
|
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
|
return Snapshot{}, err
|
|
}
|
|
serviceSnapshot = service.UnknownSnapshot(now, "source_unavailable")
|
|
} else {
|
|
serviceSnapshot = next
|
|
}
|
|
}
|
|
return BuildSnapshot(now, hostSnapshot, serviceSnapshot, nil, nil, a.Limits)
|
|
}
|