-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rule/metrics: optimize default metric labels for events and calls
- Loading branch information
James DeFelice
committed
Jun 14, 2017
1 parent
90fe8a5
commit 48ac237
Showing
14 changed files
with
165 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 28 additions & 4 deletions
32
api/v1/lib/extras/executor/eventrules/metrics_generated.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
package eventrules | ||
|
||
// go generate -import github.com/mesos/mesos-go/api/v1/lib/executor -type E:*executor.Event:&executor.Event{} -output metrics_generated.go | ||
// go generate -import github.com/mesos/mesos-go/api/v1/lib/executor -type E:*executor.Event:&executor.Event{} -type ET:executor.Event_Type -output metrics_generated.go | ||
// GENERATED CODE FOLLOWS; DO NOT EDIT. | ||
|
||
import ( | ||
"context" | ||
|
||
"strings" | ||
|
||
"github.com/mesos/mesos-go/api/v1/lib/extras/metrics" | ||
|
||
"github.com/mesos/mesos-go/api/v1/lib/executor" | ||
) | ||
|
||
func Metrics(harness metrics.Harness) Rule { | ||
// Labeler generates a set of strings that should be associated with metrics that are generated for the given event. | ||
type Labeler func(ctx context.Context, e *executor.Event) []string | ||
|
||
var defaultLabels = func() map[executor.Event_Type][]string { | ||
m := make(map[executor.Event_Type][]string) | ||
for k, v := range executor.Event_Type_name { | ||
m[executor.Event_Type(k)] = []string{strings.ToLower(v)} | ||
} | ||
return m | ||
}() | ||
|
||
func defaultLabeler(ctx context.Context, e *executor.Event) []string { | ||
return defaultLabels[e.GetType()] | ||
} | ||
|
||
// Metrics generates a Rule that invokes the given harness for each event, using the labels generated by the Labeler. | ||
// Panics if harness or labeler is nil. | ||
func Metrics(harness metrics.Harness, labeler Labeler) Rule { | ||
if harness == nil { | ||
panic("harness is a required parameter") | ||
} | ||
if labeler == nil { | ||
labeler = defaultLabeler | ||
} | ||
return func(ctx context.Context, e *executor.Event, err error, ch Chain) (context.Context, *executor.Event, error) { | ||
typename := strings.ToLower(e.GetType().String()) | ||
labels := labeler(ctx, e) | ||
harness(func() error { | ||
ctx, e, err = ch(ctx, e, err) | ||
return err | ||
}, typename) | ||
}, labels...) | ||
return ctx, e, err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 28 additions & 4 deletions
32
api/v1/lib/extras/scheduler/eventrules/metrics_generated.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
package eventrules | ||
|
||
// go generate -import github.com/mesos/mesos-go/api/v1/lib/scheduler -type E:*scheduler.Event:&scheduler.Event{} -output metrics_generated.go | ||
// go generate -import github.com/mesos/mesos-go/api/v1/lib/scheduler -type E:*scheduler.Event:&scheduler.Event{} -type ET:scheduler.Event_Type -output metrics_generated.go | ||
// GENERATED CODE FOLLOWS; DO NOT EDIT. | ||
|
||
import ( | ||
"context" | ||
|
||
"strings" | ||
|
||
"github.com/mesos/mesos-go/api/v1/lib/extras/metrics" | ||
|
||
"github.com/mesos/mesos-go/api/v1/lib/scheduler" | ||
) | ||
|
||
func Metrics(harness metrics.Harness) Rule { | ||
// Labeler generates a set of strings that should be associated with metrics that are generated for the given event. | ||
type Labeler func(ctx context.Context, e *scheduler.Event) []string | ||
|
||
var defaultLabels = func() map[scheduler.Event_Type][]string { | ||
m := make(map[scheduler.Event_Type][]string) | ||
for k, v := range scheduler.Event_Type_name { | ||
m[scheduler.Event_Type(k)] = []string{strings.ToLower(v)} | ||
} | ||
return m | ||
}() | ||
|
||
func defaultLabeler(ctx context.Context, e *scheduler.Event) []string { | ||
return defaultLabels[e.GetType()] | ||
} | ||
|
||
// Metrics generates a Rule that invokes the given harness for each event, using the labels generated by the Labeler. | ||
// Panics if harness or labeler is nil. | ||
func Metrics(harness metrics.Harness, labeler Labeler) Rule { | ||
if harness == nil { | ||
panic("harness is a required parameter") | ||
} | ||
if labeler == nil { | ||
labeler = defaultLabeler | ||
} | ||
return func(ctx context.Context, e *scheduler.Event, err error, ch Chain) (context.Context, *scheduler.Event, error) { | ||
typename := strings.ToLower(e.GetType().String()) | ||
labels := labeler(ctx, e) | ||
harness(func() error { | ||
ctx, e, err = ch(ctx, e, err) | ||
return err | ||
}, typename) | ||
}, labels...) | ||
return ctx, e, err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters