mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: API stats and tags reoorganization (#1171)
Make sure we can apply extra tags if RegisterAPIViews() is provided with such tags. Deduplicate path/method/status and always apply these default tags to appropriate views.
This commit is contained in:
@@ -8,11 +8,16 @@ import (
|
||||
)
|
||||
|
||||
func CreateView(measure stats.Measure, agg *view.Aggregation, tagKeys []string) *view.View {
|
||||
keys := makeKeys(tagKeys)
|
||||
return CreateViewWithTags(measure, agg, keys)
|
||||
}
|
||||
|
||||
func CreateViewWithTags(measure stats.Measure, agg *view.Aggregation, tags []tag.Key) *view.View {
|
||||
return &view.View{
|
||||
Name: measure.Name(),
|
||||
Description: measure.Description(),
|
||||
Measure: measure,
|
||||
TagKeys: makeKeys(tagKeys),
|
||||
TagKeys: tags,
|
||||
Aggregation: agg,
|
||||
}
|
||||
}
|
||||
@@ -21,14 +26,18 @@ func MakeMeasure(name string, desc string, unit string) *stats.Int64Measure {
|
||||
return stats.Int64(name, desc, unit)
|
||||
}
|
||||
|
||||
func MakeKey(name string) tag.Key {
|
||||
key, err := tag.NewKey(name)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Fatalf("Cannot create tag %s", name)
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
func makeKeys(names []string) []tag.Key {
|
||||
tagKeys := make([]tag.Key, len(names))
|
||||
for i, name := range names {
|
||||
key, err := tag.NewKey(name)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
tagKeys[i] = key
|
||||
tagKeys[i] = MakeKey(name)
|
||||
}
|
||||
return tagKeys
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user