Skip to content

Commit

Permalink
Gather time of last failed PNCC instead of count
Browse files Browse the repository at this point in the history
  • Loading branch information
natiiix committed Apr 16, 2021
1 parent a7734cc commit 292c9e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions pkg/gather/clusterconfig/pod_network_connectivity_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clusterconfig
import (
"context"
"encoding/json"
"time"

controlplanev1 "github.com/openshift/api/operatorcontrolplane/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -75,12 +76,14 @@ func gatherPNCC(ctx context.Context, dynamicClient dynamic.Interface, coreClient
}
}

reasons := map[string]map[string]int{}
reasons := map[string]map[string]time.Time{}
for _, entry := range unsuccessful {
if _, exists := reasons[entry.Reason]; !exists {
reasons[entry.Reason] = map[string]int{}
reasons[entry.Reason] = map[string]time.Time{}
}
if oldTime, exists := reasons[entry.Reason][entry.Message]; !exists || entry.Start.After(oldTime) {
reasons[entry.Reason][entry.Message] = entry.Start.Time
}
reasons[entry.Reason][entry.Message]++
}

return []record.Record{{Name: "config/podnetworkconnectivitychecks", Item: record.JSONMarshaller{Object: reasons}}}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"reflect"
"testing"
"time"

"github.com/openshift/insights-operator/pkg/record"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -58,7 +59,7 @@ status:
if !ok {
t.Fatalf("unexpected type of record item in the first run: %q", rec.Name)
}
if !reflect.DeepEqual(recItem.Object, map[string]map[string]int{}) {
if !reflect.DeepEqual(recItem.Object, map[string]map[string]time.Time{}) {
t.Fatalf("unexpected value of record item in the first run: %#v", recItem)
}

Expand All @@ -80,7 +81,7 @@ status:
if !ok {
t.Fatalf("unexpected type of record item in the second run: %q", rec.Name)
}
if !reflect.DeepEqual(recItem.Object, map[string]map[string]int{"TestReason": {"TestMessage": 1}}) {
if !reflect.DeepEqual(recItem.Object, map[string]map[string]time.Time{"TestReason": {"TestMessage": time.Time{}}}) {
t.Fatalf("unexpected value of record item in the second run: %#v", recItem)
}
}

0 comments on commit 292c9e7

Please sign in to comment.