func Test_GetAllMetrics_API(t *testing.T) { a := assert.New(t) cassandra, context := newCassandraAPI(t) defer cleanAPI(t, cassandra) a.CheckError(cassandra.AddMetric(api.TaggedMetric{ "metric.a", api.ParseTagSet("foo=a"), }, context)) a.CheckError(cassandra.AddMetric(api.TaggedMetric{ "metric.a", api.ParseTagSet("foo=b"), }, context)) a.CheckError(cassandra.AddMetrics([]api.TaggedMetric{ { "metric.c", api.TagSet{ "bar": "cat", }, }, { "metric.d", api.TagSet{ "bar": "dog", }, }, { "metric.e", api.TagSet{ "bar": "cat", }, }, }, context)) keys, err := cassandra.GetAllMetrics(context) a.CheckError(err) sort.Sort(api.MetricKeys(keys)) a.Eq(keys, []api.MetricKey{"metric.a", "metric.c", "metric.d", "metric.e"}) a.CheckError(cassandra.AddMetric(api.TaggedMetric{ "metric.b", api.ParseTagSet("foo=c"), }, context)) a.CheckError(cassandra.AddMetric(api.TaggedMetric{ "metric.b", api.ParseTagSet("foo=c"), }, context)) keys, err = cassandra.GetAllMetrics(context) a.CheckError(err) sort.Sort(api.MetricKeys(keys)) a.Eq(keys, []api.MetricKey{"metric.a", "metric.b", "metric.c", "metric.d", "metric.e"}) }
// Execute of a DescribeAllCommand returns the list of all metrics. func (cmd *DescribeAllCommand) Execute(context ExecutionContext) (interface{}, error) { result, err := context.API.GetAllMetrics() if err == nil { sort.Sort(api.MetricKeys(result)) } return result, err }
func Test_GetAllMetrics(t *testing.T) { a := assert.New(t) db := newDatabase(t) if db == nil { return } defer cleanDatabase(t, db) a.CheckError(db.AddMetricName("metric.a", api.ParseTagSet("foo=a"))) a.CheckError(db.AddMetricName("metric.a", api.ParseTagSet("foo=b"))) keys, err := db.GetAllMetrics() a.CheckError(err) sort.Sort(api.MetricKeys(keys)) a.Eq(keys, []api.MetricKey{"metric.a"}) a.CheckError(db.AddMetricName("metric.b", api.ParseTagSet("foo=c"))) a.CheckError(db.AddMetricName("metric.b", api.ParseTagSet("foo=c"))) keys, err = db.GetAllMetrics() a.CheckError(err) sort.Sort(api.MetricKeys(keys)) a.Eq(keys, []api.MetricKey{"metric.a", "metric.b"}) }
// Execute of a DescribeAllCommand returns the list of all metrics. func (cmd *DescribeAllCommand) Execute(context ExecutionContext) (interface{}, error) { result, err := context.API.GetAllMetrics() if err == nil { filtered := make([]api.MetricKey, 0, len(result)) for _, row := range result { if cmd.matcher.regex.MatchString(string(row)) { filtered = append(filtered, row) } } sort.Sort(api.MetricKeys(filtered)) return filtered, nil } return nil, err }
// Execute of a DescribeAllCommand returns the list of all metrics. func (cmd *DescribeAllCommand) Execute(context ExecutionContext) (CommandResult, error) { result, err := context.MetricMetadataAPI.GetAllMetrics(api.MetricMetadataAPIContext{ Profiler: context.Profiler, }) if err == nil { filtered := make([]api.MetricKey, 0, len(result)) for _, row := range result { if cmd.matcher.regex.MatchString(string(row)) { filtered = append(filtered, row) } } sort.Sort(api.MetricKeys(filtered)) return CommandResult{ Body: filtered, Metadata: map[string]interface{}{ "count": len(filtered), }, }, nil } return CommandResult{}, err }