Skip to content

Commit

Permalink
Merge pull request #838 from yangjunmyfm192085/delete-start-time
Browse files Browse the repository at this point in the history
Don‘t use Kubelet start time for metrics-server.
  • Loading branch information
k8s-ci-robot authored Sep 24, 2021
2 parents b6cdcda + 0752a66 commit 151e822
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 22 deletions.
3 changes: 1 addition & 2 deletions pkg/scraper/client/summary/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ func decodeBatch(summary *Summary) *storage.MetricsBatch {
}

func decodeNodeStats(nodeStats *NodeStats, target *storage.NodeMetricsPoint) (success bool) {
if nodeStats.StartTime.IsZero() || nodeStats.CPU == nil || nodeStats.CPU.Time.IsZero() {
if nodeStats.CPU == nil || nodeStats.CPU.Time.IsZero() {
// if we can't get a timestamp, assume bad data in general
klog.V(1).InfoS("Failed getting node metric timestamp", "node", klog.KRef("", nodeStats.NodeName))
return false
}
*target = storage.NodeMetricsPoint{
Name: nodeStats.NodeName,
MetricsPoint: storage.MetricsPoint{
StartTime: nodeStats.StartTime.Time,
Timestamp: nodeStats.CPU.Time.Time,
},
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/scraper/client/summary/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ var _ = Describe("Decode", func() {
scrapeTime := time.Now()
summary = &Summary{
Node: NodeStats{
NodeName: "node1",
CPU: cpuStats(100, scrapeTime.Add(100*time.Millisecond)),
Memory: memStats(200, scrapeTime.Add(200*time.Millisecond)),
StartTime: metav1.Time{Time: scrapeTime.Add(-100 * time.Millisecond)},
NodeName: "node1",
CPU: cpuStats(100, scrapeTime.Add(100*time.Millisecond)),
Memory: memStats(200, scrapeTime.Add(200*time.Millisecond)),
},
Pods: []PodStats{
podStats("ns1", "pod1",
Expand Down Expand Up @@ -75,7 +74,6 @@ var _ = Describe("Decode", func() {
batch := decodeBatch(summary)

By("verifying that the scrape time is as expected")
Expect(batch.Nodes[0].StartTime).To(Equal(summary.Node.StartTime.Time))
Expect(batch.Pods[0].Containers[0].StartTime).To(Equal(summary.Pods[0].Containers[0].StartTime.Time))
Expect(batch.Pods[1].Containers[0].StartTime).To(Equal(summary.Pods[1].Containers[0].StartTime.Time))
})
Expand Down
2 changes: 0 additions & 2 deletions pkg/scraper/client/summary/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ type Summary struct {
type NodeStats struct {
// Reference to the measured Node.
NodeName string `json:"nodeName"`
// Start time of system
StartTime metav1.Time `json:"startTime"`
// Stats pertaining to CPU resources.
// +optional
CPU *CPUStats `json:"cpu,omitempty"`
Expand Down
9 changes: 0 additions & 9 deletions pkg/scraper/client/summary/types_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/scraper/client/summary/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ var expected = &storage.MetricsBatch{
{
Name: "e2e-v1.17.0-control-plane",
MetricsPoint: storage.MetricsPoint{
StartTime: time.Date(2020, 3, 31, 18, 00, 54, 0, time.UTC),
Timestamp: time.Date(2020, 4, 16, 20, 25, 28, 0, time.UTC),
CumulativeCpuUsed: 519978197128,
MemoryUsage: 1417551872,
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type nodeStorage struct {
// last stores node metric points from last scrape
last map[string]NodeMetricsPoint
// prev stores node metric points from scrape preceding the last one.
// Points timestamp should proceed the corresponding points from last and have same start time (no restart between them).
// Points timestamp should proceed the corresponding points from last.
prev map[string]NodeMetricsPoint
}

Expand Down Expand Up @@ -69,8 +69,7 @@ func (s *nodeStorage) Store(newNodes []NodeMetricsPoint) {
}
lastNodes[newNode.Name] = newNode

// Keep previous metric point if newNode has not restarted (new metric start time < stored timestamp)
if lastNode, found := s.last[newNode.Name]; found && newNode.StartTime.Before(lastNode.Timestamp) {
if lastNode, found := s.last[newNode.Name]; found {
// If new point is different then one already stored
if newNode.Timestamp.After(lastNode.Timestamp) {
// Move stored point to previous
Expand Down

0 comments on commit 151e822

Please sign in to comment.