Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Update REST API responses to include Description, Unit, Dynamic, and
Browse files Browse the repository at this point in the history
DynamicElements for metrics returned from the metric catalog. This
includes setting dynamic elements of the metric namespace when the
metric is dynamic.
  • Loading branch information
geauxvirtual committed May 13, 2016
1 parent 783afb3 commit 1c09e2f
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions mgmt/rest/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,18 @@ func (s *Server) getMetricsFromTree(w http.ResponseWriter, r *http.Request, para
}

b := &rbody.MetricReturned{}
dyn, indexes := mt.Namespace().IsDynamic()
var dynamicElements []rbody.DynamicElement
if dyn {
dynamicElements = getDynamicElements(mt.Namespace(), indexes)
}
mb := &rbody.Metric{
Namespace: mt.Namespace().String(),
Version: mt.Version(),
Namespace: mt.Namespace().String(),
Version: mt.Version(),
Dynamic: dyn,
DynamicElements: dynamicElements,
Description: mt.Description(),
Unit: mt.Unit(),
LastAdvertisedTimestamp: mt.LastAdvertisedTime().Unix(),
Href: catalogedMetricURI(r.Host, mt),
}
Expand Down Expand Up @@ -144,10 +153,19 @@ func respondWithMetrics(host string, mets []core.CatalogedMetric, w http.Respons
Maximum: r.Maximum,
})
}
dyn, indexes := met.Namespace().IsDynamic()
var dynamicElements []rbody.DynamicElement
if dyn {
dynamicElements = getDynamicElements(met.Namespace(), indexes)
}
b = append(b, rbody.Metric{
Namespace: met.Namespace().String(),
Version: met.Version(),
LastAdvertisedTimestamp: met.LastAdvertisedTime().Unix(),
Description: met.Description(),
Dynamic: dyn,
DynamicElements: dynamicElements,
Unit: met.Unit(),
Policy: policies,
Href: catalogedMetricURI(host, met),
})
Expand All @@ -159,3 +177,16 @@ func respondWithMetrics(host string, mets []core.CatalogedMetric, w http.Respons
func catalogedMetricURI(host string, mt core.CatalogedMetric) string {
return fmt.Sprintf("%s://%s/v1/metrics%s?ver=%d", protocolPrefix, host, mt.Namespace().String(), mt.Version())
}

func getDynamicElements(ns core.Namespace, indexes []int) []rbody.DynamicElement {
elements := make([]rbody.DynamicElement, 0, len(indexes))
for _, v := range indexes {
e := ns.Element(v)
elements = append(elements, rbody.DynamicElement{
Index: v,
Name: e.Name,
Description: e.Description,
})
}
return elements
}

0 comments on commit 1c09e2f

Please sign in to comment.