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

Commit 4a32462

Browse files
authored
Merge pull request #1850 from AltSchool/refactor/factor-out-common-code
Code refactoring and simplification
2 parents 02692f8 + 42906f1 commit 4a32462

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

metrics/sources/kubelet/kubelet_client.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,33 +130,35 @@ type statsRequest struct {
130130
Subcontainers bool `json:"subcontainers,omitempty"`
131131
}
132132

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

141+
func (self *KubeletClient) getUrl(host Host, path string) string {
140142
url := url.URL{
141-
Scheme: scheme,
143+
Scheme: self.getScheme(),
142144
Host: host.String(),
143-
Path: "/stats/container/",
145+
Path: path,
144146
}
145147

146-
return self.getAllContainers(url.String(), start, end)
148+
return url.String()
149+
}
150+
151+
// Get stats for all non-Kubernetes containers.
152+
func (self *KubeletClient) GetAllRawContainers(host Host, start, end time.Time) ([]cadvisor.ContainerInfo, error) {
153+
url := self.getUrl(host, "/stats/container/")
154+
155+
return self.getAllContainers(url, start, end)
147156
}
148157

149158
func (self *KubeletClient) GetSummary(host Host) (*stats.Summary, error) {
150-
url := url.URL{
151-
Scheme: "http",
152-
Host: host.String(),
153-
Path: "/stats/summary/",
154-
}
155-
if self.config != nil && self.config.EnableHttps {
156-
url.Scheme = "https"
157-
}
159+
url := self.getUrl(host, "/stats/summary/")
158160

159-
req, err := http.NewRequest("GET", url.String(), nil)
161+
req, err := http.NewRequest("GET", url, nil)
160162
if err != nil {
161163
return nil, err
162164
}

0 commit comments

Comments
 (0)