Skip to content

Commit

Permalink
DriverContext: Add the TaskGroup and the Job name
Browse files Browse the repository at this point in the history
Adding this fields to the DriverContext object, will allow us to pass
them to the drivers.

An use case for this, will be to emit tagged metrics in the drivers,
which contain all relevant information:
- Job
- TaskGroup
- Task
- ...

Ref: hashicorp#4185
  • Loading branch information
Javier Palomo Almena committed Apr 22, 2018
1 parent fb7e0c1 commit 3e6c343
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
29 changes: 17 additions & 12 deletions client/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,13 @@ type LogEventFn func(message string, args ...interface{})
// node attributes into a Driver without having to change the Driver interface
// each time we do it. Used in conjunction with Factory, above.
type DriverContext struct {
taskName string
allocID string
config *config.Config
logger *log.Logger
node *structs.Node
jobName string
taskGroupName string
taskName string
allocID string
config *config.Config
logger *log.Logger
node *structs.Node

emitEvent LogEventFn
}
Expand All @@ -278,15 +280,18 @@ func NewEmptyDriverContext() *DriverContext {
// This enables other packages to create DriverContexts but keeps the fields
// private to the driver. If we want to change this later we can gorename all of
// the fields in DriverContext.
func NewDriverContext(taskName, allocID string, config *config.Config, node *structs.Node,
func NewDriverContext(jobName, taskGroupName, taskName, allocID string,
config *config.Config, node *structs.Node,
logger *log.Logger, eventEmitter LogEventFn) *DriverContext {
return &DriverContext{
taskName: taskName,
allocID: allocID,
config: config,
node: node,
logger: logger,
emitEvent: eventEmitter,
jobName: jobName,
taskGroupName: taskGroupName,
taskName: taskName,
allocID: allocID,
config: config,
node: node,
logger: logger,
emitEvent: eventEmitter,
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func testDriverContexts(t *testing.T, task *structs.Task) *testContext {
emitter := func(m string, args ...interface{}) {
logger.Printf("[EVENT] "+m, args...)
}
driverCtx := NewDriverContext(task.Name, alloc.ID, cfg, cfg.Node, logger, emitter)
driverCtx := NewDriverContext(alloc.Job.Name, alloc.TaskGroup, task.Name, alloc.ID, cfg, cfg.Node, logger, emitter)

return &testContext{allocDir, driverCtx, execCtx, eb}
}
Expand Down
2 changes: 1 addition & 1 deletion client/fingerprint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (fm *FingerprintManager) setupFingerprinters(fingerprints []string) error {
// supported
func (fm *FingerprintManager) setupDrivers(drivers []string) error {
var availDrivers []string
driverCtx := driver.NewDriverContext("", "", fm.getConfig(), fm.getNode(), fm.logger, nil)
driverCtx := driver.NewDriverContext("", "", "", "", fm.getConfig(), fm.getNode(), fm.logger, nil)
for _, name := range drivers {

d, err := driver.NewDriver(name, driverCtx)
Expand Down
2 changes: 1 addition & 1 deletion client/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func (r *TaskRunner) createDriver() (driver.Driver, error) {
r.setState(structs.TaskStatePending, structs.NewTaskEvent(structs.TaskDriverMessage).SetDriverMessage(msg), false)
}

driverCtx := driver.NewDriverContext(r.task.Name, r.alloc.ID, r.config, r.config.Node, r.logger, eventEmitter)
driverCtx := driver.NewDriverContext(r.alloc.Job.Name, r.alloc.TaskGroup, r.task.Name, r.alloc.ID, r.config, r.config.Node, r.logger, eventEmitter)
d, err := driver.NewDriver(r.task.Driver, driverCtx)
if err != nil {
return nil, fmt.Errorf("failed to create driver '%s' for alloc %s: %v",
Expand Down

0 comments on commit 3e6c343

Please sign in to comment.