func TestMetricSeparator(t *testing.T) { tc := getTestCases() Convey("Test namespace separator", t, func() { for _, c := range tc { Convey("namespace "+c.input.String(), func() { firstChar := stringutils.GetFirstChar(c.input.String()) So(firstChar, ShouldEqual, c.expected) }) } }) }
func getNamespace(mt *rbody.Metric) string { ns := mt.Namespace if mt.Dynamic { fc := stringutils.GetFirstChar(ns) slice := strings.Split(ns, fc) for _, v := range mt.DynamicElements { slice[v.Index+1] = "[" + v.Name + "]" } ns = strings.Join(slice, fc) } return ns }
func (c *CollectWorkflowMapNode) GetMetrics() []Metric { metrics := make([]Metric, len(c.Metrics)) i := 0 for k, v := range c.Metrics { // Identify the character to split on by peaking // at the first character of each metric. firstChar := stringutils.GetFirstChar(k) ns := strings.Trim(k, firstChar) metrics[i] = Metric{ namespace: strings.Split(ns, firstChar), version: v.Version_, } i++ } return metrics }
func (s *Server) getMetrics(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { ver := 0 // 0: get all metrics // If we are provided a parameter with the name 'ns' we need to // perform a query q := r.URL.Query() v := q.Get("ver") ns_query := q.Get("ns") if ns_query != "" { ver = 0 // 0: get all versions if v != "" { var err error ver, err = strconv.Atoi(v) if err != nil { respond(400, rbody.FromError(err), w) return } } // strip the leading char and split on the remaining. fc := stringutils.GetFirstChar(ns_query) ns := strings.Split(strings.TrimLeft(ns_query, fc), fc) if ns[len(ns)-1] == "*" { ns = ns[:len(ns)-1] } mets, err := s.mm.FetchMetrics(core.NewNamespace(ns...), ver) if err != nil { respond(404, rbody.FromError(err), w) return } respondWithMetrics(r.Host, mets, w) return } mets, err := s.mm.MetricCatalog() if err != nil { respond(500, rbody.FromError(err), w) return } respondWithMetrics(r.Host, mets, w) }
func parseNamespace(ns string) []string { fc := stringutils.GetFirstChar(ns) ns = strings.Trim(ns, fc) return strings.Split(ns, fc) }