Skip to content

Commit

Permalink
Support Openshift specific gateway for fetching all the metric defini…
Browse files Browse the repository at this point in the history
…tions for all tenants
  • Loading branch information
burmanm committed Dec 14, 2017
1 parent fb10361 commit 3ec6f27
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions metrics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,36 @@ func (c *Client) Create(md MetricDefinition, o ...Modifier) (bool, error) {
return true, nil
}

// AllDefinitions fetches all metric definitions (for every tenant) from the server. Requires admin/service rights
func (c *Client) AllDefinitions(o ...Modifier) ([]*MetricDefinition, error) {
o = prepend(o, c.URL("GET", OpenshiftEndpoint()), AdminAuthentication(c.AdminToken))

r, err := c.Send(o...)
if err != nil {
return nil, err
}

defer r.Body.Close()

if r.StatusCode == http.StatusOK {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, err
}
md := []*MetricDefinition{}
if b != nil && len(b) > 0 {
if err = json.Unmarshal(b, &md); err != nil {
return nil, err
}
}
return md, err
} else if r.StatusCode > 399 {
return nil, c.parseErrorResponse(r)
}

return nil, nil
}

// Definitions fetches metric definitions from the server
func (c *Client) Definitions(o ...Modifier) ([]*MetricDefinition, error) {
o = prepend(o, c.URL("GET", TypeEndpoint(Generic)))
Expand Down Expand Up @@ -684,6 +714,13 @@ func (c *Client) createURL(e ...Endpoint) *url.URL {
return &mu
}

// OpenshiftEndpoint is a URL endpoint only available in the origin-metrics installation
func OpenshiftEndpoint() Endpoint {
return func(u *url.URL) {
addToURL(u, "openshift")
}
}

// TenantEndpoint is a URL endpoint to fetch tenant related information
func TenantEndpoint() Endpoint {
return func(u *url.URL) {
Expand Down

0 comments on commit 3ec6f27

Please sign in to comment.