fix(inputs/kube_inventory): don't skip resources with zero s/ns timestamps (#9978)

This commit is contained in:
Sam Lai 2021-10-25 22:01:35 +01:00 committed by GitHub
parent 036ae299a5
commit ecd4d3782c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 6 deletions

View File

@ -40,7 +40,8 @@ func (ki *KubernetesInventory) gatherDaemonSet(d v1.DaemonSet, acc telegraf.Accu
} }
} }
if d.GetCreationTimestamp().Second() != 0 { creationTs := d.GetCreationTimestamp()
if !creationTs.IsZero() {
fields["created"] = d.GetCreationTimestamp().UnixNano() fields["created"] = d.GetCreationTimestamp().UnixNano()
} }

View File

@ -20,7 +20,8 @@ func collectEndpoints(ctx context.Context, acc telegraf.Accumulator, ki *Kuberne
} }
func (ki *KubernetesInventory) gatherEndpoint(e corev1.Endpoints, acc telegraf.Accumulator) { func (ki *KubernetesInventory) gatherEndpoint(e corev1.Endpoints, acc telegraf.Accumulator) {
if e.GetCreationTimestamp().Second() == 0 && e.GetCreationTimestamp().Nanosecond() == 0 { creationTs := e.GetCreationTimestamp()
if creationTs.IsZero() {
return return
} }

View File

@ -20,7 +20,8 @@ func collectIngress(ctx context.Context, acc telegraf.Accumulator, ki *Kubernete
} }
func (ki *KubernetesInventory) gatherIngress(i netv1.Ingress, acc telegraf.Accumulator) { func (ki *KubernetesInventory) gatherIngress(i netv1.Ingress, acc telegraf.Accumulator) {
if i.GetCreationTimestamp().Second() == 0 && i.GetCreationTimestamp().Nanosecond() == 0 { creationTs := i.GetCreationTimestamp()
if creationTs.IsZero() {
return return
} }

View File

@ -20,7 +20,8 @@ func collectPods(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesIn
} }
func (ki *KubernetesInventory) gatherPod(p corev1.Pod, acc telegraf.Accumulator) { func (ki *KubernetesInventory) gatherPod(p corev1.Pod, acc telegraf.Accumulator) {
if p.GetCreationTimestamp().Second() == 0 && p.GetCreationTimestamp().Nanosecond() == 0 { creationTs := p.GetCreationTimestamp()
if creationTs.IsZero() {
return return
} }

View File

@ -20,7 +20,7 @@ func TestPod(t *testing.T) {
selectExclude := []string{} selectExclude := []string{}
now := time.Now() now := time.Now()
started := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-1, 1, 36, 0, now.Location()) started := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-1, 1, 36, 0, now.Location())
created := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-2, 1, 36, 0, now.Location()) created := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-2, 1, 0, 0, now.Location())
cond1 := time.Date(now.Year(), 7, 5, 7, 53, 29, 0, now.Location()) cond1 := time.Date(now.Year(), 7, 5, 7, 53, 29, 0, now.Location())
cond2 := time.Date(now.Year(), 7, 5, 7, 53, 31, 0, now.Location()) cond2 := time.Date(now.Year(), 7, 5, 7, 53, 31, 0, now.Location())

View File

@ -20,7 +20,8 @@ func collectServices(ctx context.Context, acc telegraf.Accumulator, ki *Kubernet
} }
func (ki *KubernetesInventory) gatherService(s corev1.Service, acc telegraf.Accumulator) { func (ki *KubernetesInventory) gatherService(s corev1.Service, acc telegraf.Accumulator) {
if s.GetCreationTimestamp().Second() == 0 && s.GetCreationTimestamp().Nanosecond() == 0 { creationTs := s.GetCreationTimestamp()
if creationTs.IsZero() {
return return
} }