@@ -43,7 +43,7 @@ import (
43
43
"github.com/prometheus/common/model"
44
44
)
45
45
46
- // KubeletMetric stores metrics scraped from the kubelet server's /metric endpoint.
46
+ // KubeletLatencyMetric stores metrics scraped from the kubelet server's /metric endpoint.
47
47
// TODO: Get some more structure around the metrics and this type
48
48
type KubeletLatencyMetric struct {
49
49
// eg: list, info, create
@@ -55,7 +55,7 @@ type KubeletLatencyMetric struct {
55
55
Latency time.Duration
56
56
}
57
57
58
- // KubeletMetricByLatency implements sort.Interface for []KubeletMetric based on
58
+ // KubeletLatencyMetrics implements sort.Interface for []KubeletMetric based on
59
59
// the latency field.
60
60
type KubeletLatencyMetrics []KubeletLatencyMetric
61
61
@@ -159,6 +159,7 @@ type RuntimeOperationErrorRate struct {
159
159
TimeoutRate float64
160
160
}
161
161
162
+ // NewRuntimeOperationMonitor returns a new RuntimeOperationMonitor.
162
163
func NewRuntimeOperationMonitor (c clientset.Interface ) * RuntimeOperationMonitor {
163
164
m := & RuntimeOperationMonitor {
164
165
client : c ,
@@ -433,7 +434,7 @@ const (
433
434
rootContainerName = "/"
434
435
)
435
436
436
- // A list of containers for which we want to collect resource usage.
437
+ // TargetContainers returns a list of containers for which we want to collect resource usage.
437
438
func TargetContainers () []string {
438
439
return []string {
439
440
rootContainerName ,
@@ -442,6 +443,7 @@ func TargetContainers() []string {
442
443
}
443
444
}
444
445
446
+ // ContainerResourceUsage is a structure for gathering container resource usage.
445
447
type ContainerResourceUsage struct {
446
448
Name string
447
449
Timestamp time.Time
@@ -457,7 +459,10 @@ func (r *ContainerResourceUsage) isStrictlyGreaterThan(rhs *ContainerResourceUsa
457
459
return r .CPUUsageInCores > rhs .CPUUsageInCores && r .MemoryWorkingSetInBytes > rhs .MemoryWorkingSetInBytes
458
460
}
459
461
462
+ // ResourceUsagePerContainer is map of ContainerResourceUsage
460
463
type ResourceUsagePerContainer map [string ]* ContainerResourceUsage
464
+
465
+ // ResourceUsagePerNode is map of ResourceUsagePerContainer.
461
466
type ResourceUsagePerNode map [string ]ResourceUsagePerContainer
462
467
463
468
func formatResourceUsageStats (nodeName string , containerStats ResourceUsagePerContainer ) string {
@@ -491,6 +496,7 @@ type usageDataPerContainer struct {
491
496
memWorkSetData []uint64
492
497
}
493
498
499
+ // GetKubeletHeapStats returns stats of kubelet heap.
494
500
func GetKubeletHeapStats (c clientset.Interface , nodeName string ) (string , error ) {
495
501
client , err := NodeProxyRequest (c , nodeName , "debug/pprof/heap" , ports .KubeletPort )
496
502
if err != nil {
@@ -507,6 +513,7 @@ func GetKubeletHeapStats(c clientset.Interface, nodeName string) (string, error)
507
513
return strings .Join (lines [len (lines )- numLines :], "\n " ), nil
508
514
}
509
515
516
+ // PrintAllKubeletPods outputs status of all kubelet pods into log.
510
517
func PrintAllKubeletPods (c clientset.Interface , nodeName string ) {
511
518
podList , err := GetKubeletPods (c , nodeName )
512
519
if err != nil {
@@ -661,6 +668,7 @@ type ResourceMonitor struct {
661
668
collectors map [string ]* resourceCollector
662
669
}
663
670
671
+ // NewResourceMonitor returns a new ResourceMonitor.
664
672
func NewResourceMonitor (c clientset.Interface , containerNames []string , pollingInterval time.Duration ) * ResourceMonitor {
665
673
return & ResourceMonitor {
666
674
containers : containerNames ,
@@ -669,6 +677,7 @@ func NewResourceMonitor(c clientset.Interface, containerNames []string, pollingI
669
677
}
670
678
}
671
679
680
+ // Start starts collectors.
672
681
func (r * ResourceMonitor ) Start () {
673
682
// It should be OK to monitor unschedulable Nodes
674
683
nodes , err := r .client .CoreV1 ().Nodes ().List (metav1.ListOptions {})
@@ -683,18 +692,21 @@ func (r *ResourceMonitor) Start() {
683
692
}
684
693
}
685
694
695
+ // Stop stops collectors.
686
696
func (r * ResourceMonitor ) Stop () {
687
697
for _ , collector := range r .collectors {
688
698
collector .Stop ()
689
699
}
690
700
}
691
701
702
+ // Reset resets collectors.
692
703
func (r * ResourceMonitor ) Reset () {
693
704
for _ , collector := range r .collectors {
694
705
collector .Reset ()
695
706
}
696
707
}
697
708
709
+ // LogLatest outputs the latest resource usage into log.
698
710
func (r * ResourceMonitor ) LogLatest () {
699
711
summary , err := r .GetLatest ()
700
712
if err != nil {
@@ -703,6 +715,8 @@ func (r *ResourceMonitor) LogLatest() {
703
715
Logf ("%s" , r .FormatResourceUsage (summary ))
704
716
}
705
717
718
+ // FormatResourceUsage returns the formatted string for LogLatest().
719
+ // TODO(oomichi): This can be made to local function after making test/e2e/node/kubelet_perf.go use LogLatest directly instead.
706
720
func (r * ResourceMonitor ) FormatResourceUsage (s ResourceUsagePerNode ) string {
707
721
summary := []string {}
708
722
for node , usage := range s {
@@ -711,6 +725,7 @@ func (r *ResourceMonitor) FormatResourceUsage(s ResourceUsagePerNode) string {
711
725
return strings .Join (summary , "\n " )
712
726
}
713
727
728
+ // GetLatest returns the latest resource usage.
714
729
func (r * ResourceMonitor ) GetLatest () (ResourceUsagePerNode , error ) {
715
730
result := make (ResourceUsagePerNode )
716
731
errs := []error {}
@@ -725,6 +740,7 @@ func (r *ResourceMonitor) GetLatest() (ResourceUsagePerNode, error) {
725
740
return result , utilerrors .NewAggregate (errs )
726
741
}
727
742
743
+ // GetMasterNodeLatest returns the latest resource usage of master and node.
728
744
func (r * ResourceMonitor ) GetMasterNodeLatest (usagePerNode ResourceUsagePerNode ) ResourceUsagePerNode {
729
745
result := make (ResourceUsagePerNode )
730
746
var masterUsage ResourceUsagePerContainer
@@ -767,6 +783,7 @@ type ContainersCPUSummary map[string]map[float64]float64
767
783
// ContainersCPUSummary map.
768
784
type NodesCPUSummary map [string ]ContainersCPUSummary
769
785
786
+ // FormatCPUSummary returns the string of human-readable CPU summary from the specified summary data.
770
787
func (r * ResourceMonitor ) FormatCPUSummary (summary NodesCPUSummary ) string {
771
788
// Example output for a node (the percentiles may differ):
772
789
// CPU usage of containers on node "e2e-test-foo-node-0vj7":
@@ -804,11 +821,13 @@ func (r *ResourceMonitor) FormatCPUSummary(summary NodesCPUSummary) string {
804
821
return strings .Join (summaryStrings , "\n " )
805
822
}
806
823
824
+ // LogCPUSummary outputs summary of CPU into log.
807
825
func (r * ResourceMonitor ) LogCPUSummary () {
808
826
summary := r .GetCPUSummary ()
809
827
Logf ("%s" , r .FormatCPUSummary (summary ))
810
828
}
811
829
830
+ // GetCPUSummary returns summary of CPU.
812
831
func (r * ResourceMonitor ) GetCPUSummary () NodesCPUSummary {
813
832
result := make (NodesCPUSummary )
814
833
for nodeName , collector := range r .collectors {
@@ -821,6 +840,7 @@ func (r *ResourceMonitor) GetCPUSummary() NodesCPUSummary {
821
840
return result
822
841
}
823
842
843
+ // GetMasterNodeCPUSummary returns summary of master node CPUs.
824
844
func (r * ResourceMonitor ) GetMasterNodeCPUSummary (summaryPerNode NodesCPUSummary ) NodesCPUSummary {
825
845
result := make (NodesCPUSummary )
826
846
var masterSummary ContainersCPUSummary
0 commit comments