MCPcopy
hub / github.com/openfaas/faas / getFunctions

Method getFunctions

gateway/metrics/exporter.go:141–184  ·  view source on GitHub ↗
(endpointURL url.URL, namespace string)

Source from the content-addressed store, hash-verified

139}
140
141func (e *Exporter) getFunctions(endpointURL url.URL, namespace string) ([]types.FunctionStatus, error) {
142 timeout := 5 * time.Second
143 proxyClient := e.getHTTPClient(timeout)
144
145 endpointURL.Path = path.Join(endpointURL.Path, "/system/functions")
146 if len(namespace) > 0 {
147 q := endpointURL.Query()
148 q.Set("namespace", namespace)
149 endpointURL.RawQuery = q.Encode()
150 }
151
152 get, _ := http.NewRequest(http.MethodGet, endpointURL.String(), nil)
153 if e.credentials != nil {
154 get.SetBasicAuth(e.credentials.User, e.credentials.Password)
155 }
156
157 services := []types.FunctionStatus{}
158 res, err := proxyClient.Do(get)
159 if err != nil {
160 return services, err
161 }
162
163 var body []byte
164 if res.Body != nil {
165 defer res.Body.Close()
166
167 if b, err := io.ReadAll(res.Body); err != nil {
168 return services, err
169 } else {
170 body = b
171 }
172 }
173
174 if len(body) == 0 {
175 return services, fmt.Errorf("no response body from /system/functions")
176 }
177
178 if err := json.Unmarshal(body, &services); err != nil {
179 return services, fmt.Errorf("error unmarshalling response: %s, error: %s",
180 string(body), err)
181 }
182
183 return services, nil
184}
185
186func (e *Exporter) getNamespaces(endpointURL url.URL) ([]string, error) {
187 namespaces := []string{}

Callers 1

StartServiceWatcherMethod · 0.95

Calls 3

getHTTPClientMethod · 0.95
DoMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected