@@ -525,34 +525,28 @@ func translateMemory(memory *stats.MemoryStats, tsFactory *timeSeriesFactory, st
525525
526526 // Only send page fault metric if start time is before current time. Right after container is started, kubelet can return start time == end time.
527527 if pageFaultsMD != nil && memory .Time .Time .After (startTime ) {
528- if memory .MajorPageFaults == nil {
529- return nil , fmt .Errorf ("MajorPageFaults missing in MemoryStats %v" , memory )
528+ if memory .MajorPageFaults != nil {
529+ // Major page faults.
530+ majorPFPoint := tsFactory .newPoint (& v3.TypedValue {
531+ Int64Value : monitor .Int64Ptr (int64 (* memory .MajorPageFaults )),
532+ ForceSendFields : []string {"Int64Value" },
533+ }, startTime , memory .Time .Time , pageFaultsMD .MetricKind )
534+ timeSeries = append (timeSeries , tsFactory .newTimeSeries (majorPageFaultLabels , pageFaultsMD , majorPFPoint ))
530535 }
531- if memory .PageFaults == nil {
532- return nil , fmt .Errorf ("PageFaults missing in MemoryStats %v" , memory )
536+ if memory .PageFaults != nil {
537+ // Minor page faults.
538+ minorPFPoint := tsFactory .newPoint (& v3.TypedValue {
539+ Int64Value : monitor .Int64Ptr (int64 (* memory .PageFaults - * memory .MajorPageFaults )),
540+ ForceSendFields : []string {"Int64Value" },
541+ }, startTime , memory .Time .Time , pageFaultsMD .MetricKind )
542+ timeSeries = append (timeSeries , tsFactory .newTimeSeries (minorPageFaultLabels , pageFaultsMD , minorPFPoint ))
533543 }
534- // Major page faults.
535- majorPFPoint := tsFactory .newPoint (& v3.TypedValue {
536- Int64Value : monitor .Int64Ptr (int64 (* memory .MajorPageFaults )),
537- ForceSendFields : []string {"Int64Value" },
538- }, startTime , memory .Time .Time , pageFaultsMD .MetricKind )
539- timeSeries = append (timeSeries , tsFactory .newTimeSeries (majorPageFaultLabels , pageFaultsMD , majorPFPoint ))
540- // Minor page faults.
541- minorPFPoint := tsFactory .newPoint (& v3.TypedValue {
542- Int64Value : monitor .Int64Ptr (int64 (* memory .PageFaults - * memory .MajorPageFaults )),
543- ForceSendFields : []string {"Int64Value" },
544- }, startTime , memory .Time .Time , pageFaultsMD .MetricKind )
545- timeSeries = append (timeSeries , tsFactory .newTimeSeries (minorPageFaultLabels , pageFaultsMD , minorPFPoint ))
546544 }
547545
548546 if memUsedMD != nil {
549547 if memory .WorkingSetBytes == nil {
550548 return nil , fmt .Errorf ("WorkingSetBytes information missing in MemoryStats %v" , memory )
551549 }
552- if memory .UsageBytes == nil {
553- return nil , fmt .Errorf ("UsageBytes information missing in MemoryStats %v" , memory )
554- }
555-
556550 // Non-evictable memory.
557551 nonEvictMemPoint := tsFactory .newPoint (& v3.TypedValue {
558552 Int64Value : monitor .Int64Ptr (int64 (* memory .WorkingSetBytes )),
@@ -564,16 +558,18 @@ func translateMemory(memory *stats.MemoryStats, tsFactory *timeSeriesFactory, st
564558 }
565559 timeSeries = append (timeSeries , tsFactory .newTimeSeries (labels , memUsedMD , nonEvictMemPoint ))
566560
567- // Evictable memory.
568- evictMemPoint := tsFactory .newPoint (& v3.TypedValue {
569- Int64Value : monitor .Int64Ptr (int64 (* memory .UsageBytes - * memory .WorkingSetBytes )),
570- ForceSendFields : []string {"Int64Value" },
571- }, startTime , memory .Time .Time , memUsedMD .MetricKind )
572- labels = map [string ]string {"memory_type" : "evictable" }
573- if component != "" {
574- labels ["component" ] = component
561+ if memory .UsageBytes != nil {
562+ // Evictable memory.
563+ evictMemPoint := tsFactory .newPoint (& v3.TypedValue {
564+ Int64Value : monitor .Int64Ptr (int64 (* memory .UsageBytes - * memory .WorkingSetBytes )),
565+ ForceSendFields : []string {"Int64Value" },
566+ }, startTime , memory .Time .Time , memUsedMD .MetricKind )
567+ labels = map [string ]string {"memory_type" : "evictable" }
568+ if component != "" {
569+ labels ["component" ] = component
570+ }
571+ timeSeries = append (timeSeries , tsFactory .newTimeSeries (labels , memUsedMD , evictMemPoint ))
575572 }
576- timeSeries = append (timeSeries , tsFactory .newTimeSeries (labels , memUsedMD , evictMemPoint ))
577573 }
578574
579575 if memTotalMD != nil {
0 commit comments