Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1850 from AltSchool/refactor/factor-out-common-code
Browse files Browse the repository at this point in the history
Code refactoring and simplification
  • Loading branch information
piosz authored Dec 7, 2017
2 parents 02692f8 + 42906f1 commit 4a32462
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions metrics/sources/kubelet/kubelet_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,35 @@ type statsRequest struct {
Subcontainers bool `json:"subcontainers,omitempty"`
}

// Get stats for all non-Kubernetes containers.
func (self *KubeletClient) GetAllRawContainers(host Host, start, end time.Time) ([]cadvisor.ContainerInfo, error) {
scheme := "http"
func (self *KubeletClient) getScheme() string {
if self.config != nil && self.config.EnableHttps {
scheme = "https"
return "https"
} else {
return "http"
}
}

func (self *KubeletClient) getUrl(host Host, path string) string {
url := url.URL{
Scheme: scheme,
Scheme: self.getScheme(),
Host: host.String(),
Path: "/stats/container/",
Path: path,
}

return self.getAllContainers(url.String(), start, end)
return url.String()
}

// Get stats for all non-Kubernetes containers.
func (self *KubeletClient) GetAllRawContainers(host Host, start, end time.Time) ([]cadvisor.ContainerInfo, error) {
url := self.getUrl(host, "/stats/container/")

return self.getAllContainers(url, start, end)
}

func (self *KubeletClient) GetSummary(host Host) (*stats.Summary, error) {
url := url.URL{
Scheme: "http",
Host: host.String(),
Path: "/stats/summary/",
}
if self.config != nil && self.config.EnableHttps {
url.Scheme = "https"
}
url := self.getUrl(host, "/stats/summary/")

req, err := http.NewRequest("GET", url.String(), nil)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4a32462

Please sign in to comment.