opsgenie / kubernetes-event-exporter

Export Kubernetes events to multiple destinations with routing and filtering
Apache License 2.0
1.05k stars 345 forks source link

Wrong GetTimestampMs value of FailedScheduling event #194

Open lobshunter opened 2 years ago

lobshunter commented 2 years ago

On kubernetes 1.19.x version, kube-scheduler emits FailedScheduling event with FirstTimestamp field set to null.

$ kubectl get event mypod.16e645b5c10bc186 -o json | jq
{
  "action": "Scheduling",
  "apiVersion": "v1",
  "eventTime": "2022-04-16T04:22:40.408032Z",
  "firstTimestamp": null,
  "involvedObject": {
    "apiVersion": "v1",
    "kind": "Pod",
    "name": "mypod",
    "namespace": "mynamespace",
    "resourceVersion": "775554465",
    "uid": "1901567b-4b02-4b9c-a67f-2c8977a818d6"
  },
  "kind": "Event",
  "lastTimestamp": null,
  "message": "0/1 nodes are available: 1 node(s) didn't match node selector.",
  "metadata": {
    "creationTimestamp": "2022-04-16T04:22:40Z",
    "name": "mypod.16e645b5c10bc186",
    "namespace": "mynamespace",
    "resourceVersion": "775554468",
    "selfLink": "/api/v1/namespaces/mynamespace/events/mypod.16e645b5c10bc186",
    "uid": "dd5843da-a3f1-404a-9f40-2c592a256054"
  },
  "reason": "FailedScheduling",
  "reportingComponent": "default-scheduler",
  "reportingInstance": "default-scheduler-172.16.4.67",
  "source": {},
  "type": "Warning"
}

GetTimestampMs method should read timestamp from eventTime instead. Otherwise the timestamp is regarded as zero value, such timestamp cause issues(e.g. Loki sink rejects the event).

I will submit a PR for this and check the behavior of different versions of kube-scheduler.

lobshunter commented 2 years ago

There are two very similar EventRecorder implementations in client-go, one uses EventTime, the other uses FirstTimestamp and LastTimestamp.đŸ˜…