mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
The opencensus API changes between 0.6.0 and 0.9.0 (#980)
We get some useful features in later versions; update so as to not pin downstream consumers (extensions) to an older version.
This commit is contained in:
@@ -5,10 +5,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/stats"
|
||||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/tag"
|
||||
)
|
||||
|
||||
type RequestStateType int
|
||||
@@ -140,76 +138,44 @@ func (c *containerState) UpdateState(ctx context.Context, newState ContainerStat
|
||||
// update old state stats
|
||||
gaugeKey := containerGaugeKeys[oldState]
|
||||
if gaugeKey != "" {
|
||||
stats.Record(ctx, stats.FindMeasure(gaugeKey).(*stats.Int64Measure).M(-1))
|
||||
stats.Record(ctx, containerGaugeMeasures[oldState].M(-1))
|
||||
}
|
||||
|
||||
timeKey := containerTimeKeys[oldState]
|
||||
if timeKey != "" {
|
||||
stats.Record(ctx, stats.FindMeasure(timeKey).(*stats.Int64Measure).M(int64(now.Sub(before).Round(time.Millisecond))))
|
||||
stats.Record(ctx, containerTimeMeasures[oldState].M(int64(now.Sub(before).Round(time.Millisecond))))
|
||||
}
|
||||
|
||||
// update new state stats
|
||||
gaugeKey = containerGaugeKeys[newState]
|
||||
if gaugeKey != "" {
|
||||
stats.Record(ctx, stats.FindMeasure(gaugeKey).(*stats.Int64Measure).M(1))
|
||||
stats.Record(ctx, containerGaugeMeasures[newState].M(1))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
containerGaugeMeasures []*stats.Int64Measure
|
||||
containerTimeMeasures []*stats.Int64Measure
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO(reed): do we have to do this? the measurements will be tagged on the context, will they be propagated
|
||||
// or we have to white list them in the view for them to show up? test...
|
||||
appKey, err := tag.NewKey("fn_appname")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
pathKey, err := tag.NewKey("fn_path")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
for _, key := range containerGaugeKeys {
|
||||
containerGaugeMeasures = make([]*stats.Int64Measure, len(containerGaugeKeys))
|
||||
for i, key := range containerGaugeKeys {
|
||||
if key == "" { // leave nil intentionally, let it panic
|
||||
continue
|
||||
}
|
||||
measure, err := stats.Int64(key, "containers in state "+key, "")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
v, err := view.New(
|
||||
key,
|
||||
"containers in state "+key,
|
||||
[]tag.Key{appKey, pathKey},
|
||||
measure,
|
||||
view.Count(),
|
||||
)
|
||||
if err != nil {
|
||||
logrus.Fatalf("cannot create view: %v", err)
|
||||
}
|
||||
if err := v.Subscribe(); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
containerGaugeMeasures[i] = makeMeasure(key, "containers in state "+key, "", view.Count())
|
||||
}
|
||||
|
||||
for _, key := range containerTimeKeys {
|
||||
containerTimeMeasures = make([]*stats.Int64Measure, len(containerTimeKeys))
|
||||
|
||||
for i, key := range containerTimeKeys {
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
measure, err := stats.Int64(key, "time spent in container state "+key, "ms")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
v, err := view.New(
|
||||
key,
|
||||
"time spent in container state "+key,
|
||||
[]tag.Key{appKey, pathKey},
|
||||
measure,
|
||||
view.Distribution(),
|
||||
)
|
||||
if err != nil {
|
||||
logrus.Fatalf("cannot create view: %v", err)
|
||||
}
|
||||
if err := v.Subscribe(); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
containerTimeMeasures[i] = makeMeasure(key, "time spent in container state "+key, "ms", view.Distribution())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user