Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
CatherineF-dev committed Apr 24, 2024
1 parent ee602fd commit b38bca9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom-metrics-stackdriver-adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (sa *StackdriverAdapter) withCoreMetrics(translator *translator.Translator)

nodes := informers.Core().V1().Nodes()
if err := api.Install(provider, podInformer.Lister(), nodes.Lister(), server.GenericAPIServer, []labels.Requirement{}); err != nil {
return nil
return err
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type coreClientInterface interface {
getNodeRAM(nodesNames []string) (map[string]resource.Quantity, map[string]api.TimeInfo, error)
}

// GetPodMetrics implements the api.MetricsProvider interface. It translate data from getPodMetrics to the new api.
func (p *CoreProvider) GetPodMetrics(pods ...*metav1.PartialObjectMetadata) ([]metrics.PodMetrics, error) {
resMetrics := make([]metrics.PodMetrics, 0, len(pods))

Expand Down Expand Up @@ -90,6 +91,7 @@ func (p *CoreProvider) GetPodMetrics(pods ...*metav1.PartialObjectMetadata) ([]m
return resMetrics, nil
}

// GetNodeMetrics implements the api.MetricsProvider interface. It translate data from getNodeMetrics to the new api.
func (p *CoreProvider) GetNodeMetrics(nodes ...*corev1.Node) ([]metrics.NodeMetrics, error) {
resMetrics := make([]metrics.NodeMetrics, 0, len(nodes))
if len(nodes) == 0 {
Expand Down Expand Up @@ -124,7 +126,6 @@ func (p *CoreProvider) GetNodeMetrics(nodes ...*corev1.Node) ([]metrics.NodeMetr
return resMetrics, nil
}

// GetPodMetrics implements the api.MetricsProvider interface.
// If metrics from i-th pod are not present, ContainerMetrics[i] will be nil and TimeInfo[i] will be default TimeInfo value.
func (p *CoreProvider) getPodMetrics(pods ...apitypes.NamespacedName) ([]api.TimeInfo, [][]metrics.ContainerMetrics, error) {
timeInfo := make([]api.TimeInfo, len(pods))
Expand Down Expand Up @@ -182,7 +183,6 @@ func (p *CoreProvider) getPodMetrics(pods ...apitypes.NamespacedName) ([]api.Tim
return timeInfo, coreMetrics, nil
}

// GetNodeMetrics implements the api.MetricsProvider interface.
// If metrics from i-th node are not present, ResourceList[i] will be nil and TimeInfo[i] will be default TimeInfo value.
func (p *CoreProvider) getNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1.ResourceList, error) {
timeInfo := make([]api.TimeInfo, len(nodes))
Expand Down Expand Up @@ -225,10 +225,12 @@ func (p *CoreProvider) getNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1
return timeInfo, coreMetrics, nil
}

// TestGetPodMetrics is only for testing purpose.
func (p *CoreProvider) TestGetPodMetrics(pods ...apitypes.NamespacedName) ([]api.TimeInfo, [][]metrics.ContainerMetrics, error) {
return p.getPodMetrics(pods...)
}

// TestGetNodeMetrics is only for testing purpose.
func (p *CoreProvider) TestGetNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1.ResourceList, error) {
return p.getNodeMetrics(nodes...)
}

0 comments on commit b38bca9

Please sign in to comment.