-
Notifications
You must be signed in to change notification settings - Fork 184
Add progress logs for job runs #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0f01db8
init
shreyas-goenka 83340b3
first version
shreyas-goenka f6c838e
modularize callbacks
shreyas-goenka 3901ede
use os.stderr to get fd
shreyas-goenka 7f889b9
Added some todos
shreyas-goenka 0853630
-
shreyas-goenka 985cb2b
added json tags
shreyas-goenka 3eae50b
Added progress format tests
shreyas-goenka 63c1617
added string test
shreyas-goenka c7f0dc4
Added runtime check for log level and log file for inplace
shreyas-goenka 0a53ffe
log progress events at log-file
shreyas-goenka 8da4ad1
remove todo
shreyas-goenka 2de0b67
implemented interface
shreyas-goenka 7c24766
remove flag
shreyas-goenka a622d28
added env var
shreyas-goenka 1d2f984
added autocompletE
shreyas-goenka 268e663
fake test to see actions
shreyas-goenka d70f901
fix failing test
shreyas-goenka 83e2d11
change event name
shreyas-goenka 03e367b
added writer function
shreyas-goenka c50834b
remove todo
shreyas-goenka 0c2aaaa
Added support for first event logging
shreyas-goenka 1969ee5
addressed comments
shreyas-goenka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package run | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/databricks/bricks/libs/flags" | ||
| "github.com/databricks/databricks-sdk-go/service/jobs" | ||
| ) | ||
|
|
||
| type JobProgressEvent struct { | ||
| Timestamp time.Time `json:"timestamp"` | ||
| JobId int64 `json:"job_id"` | ||
| RunId int64 `json:"run_id"` | ||
| RunName string `json:"run_name"` | ||
| State jobs.RunState `json:"state"` | ||
| RunPageURL string `json:"run_page_url"` | ||
| } | ||
|
|
||
| func (event *JobProgressEvent) String() string { | ||
| result := strings.Builder{} | ||
| result.WriteString(event.Timestamp.Format("2006-01-02 15:04:05")) | ||
| result.WriteString(" ") | ||
| result.WriteString(event.RunName) | ||
| result.WriteString(" ") | ||
| result.WriteString(event.State.LifeCycleState.String()) | ||
| if event.State.ResultState.String() != "" { | ||
| result.WriteString(" ") | ||
| result.WriteString(event.State.ResultState.String()) | ||
| } | ||
| result.WriteString(" ") | ||
| result.WriteString(event.State.StateMessage) | ||
| result.WriteString(" ") | ||
| result.WriteString(event.RunPageURL) | ||
| return result.String() | ||
| } | ||
|
|
||
| type JobProgressLogger struct { | ||
| Mode flags.ProgressLogFormat | ||
| prevState *jobs.RunState | ||
|
shreyas-goenka marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| func NewJobProgressLogger(mode flags.ProgressLogFormat, logLevel string, logFile string) (*JobProgressLogger, error) { | ||
| if mode == flags.ModeInplace && logLevel != "disabled" && logFile == "stderr" { | ||
| return nil, fmt.Errorf("inplace progress logging cannot be used when log-file is stderr") | ||
| } | ||
| return &JobProgressLogger{ | ||
| Mode: mode, | ||
| }, nil | ||
| } | ||
|
|
||
| func (l *JobProgressLogger) Log(event *JobProgressEvent) { | ||
| if l.prevState != nil && l.prevState.LifeCycleState == event.State.LifeCycleState && | ||
| l.prevState.ResultState == event.State.ResultState { | ||
| return | ||
| } | ||
| if l.prevState != nil && l.Mode == flags.ModeInplace { | ||
| fmt.Fprint(os.Stderr, "\033[1F]") | ||
| } | ||
| if l.Mode == flags.ModeJson { | ||
| b, err := json.MarshalIndent(event, "", " ") | ||
| if err != nil { | ||
| // we panic because there we cannot catch this in json.RunNowAndWait | ||
| panic(err) | ||
| } | ||
| fmt.Fprintln(os.Stderr, string(b)) | ||
| } else { | ||
| fmt.Fprintln(os.Stderr, event.String()) | ||
| } | ||
| l.prevState = &event.State | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package run | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/databricks/bricks/libs/flags" | ||
| "github.com/databricks/databricks-sdk-go/service/jobs" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestJobProgressEventString(t *testing.T) { | ||
| event := &JobProgressEvent{ | ||
| Timestamp: time.Date(0, 0, 0, 0, 0, 0, 0, &time.Location{}), | ||
| JobId: 123, | ||
| RunId: 456, | ||
| RunName: "run_name", | ||
| State: jobs.RunState{ | ||
| LifeCycleState: jobs.RunLifeCycleStateTerminated, | ||
| ResultState: jobs.RunResultStateSuccess, | ||
| StateMessage: "state_message", | ||
| }, | ||
| RunPageURL: "run_url", | ||
| } | ||
| assert.Equal(t, "-0001-11-30 00:00:00 run_name TERMINATED SUCCESS state_message run_url", event.String()) | ||
| } | ||
|
|
||
| func TestJobProgressEventLoggerErrorOnIncompatibleSettings(t *testing.T) { | ||
| _, err := NewJobProgressLogger(flags.ModeInplace, "info", "stderr") | ||
| assert.ErrorContains(t, err, "inplace progress logging cannot be used when log-file is stderr") | ||
| } | ||
|
|
||
| func TestInplaceJobsProgressLoggerCreatedWhenLoggingDisabled(t *testing.T) { | ||
| _, err := NewJobProgressLogger(flags.ModeInplace, "disabled", "stderr") | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestInplaceJobsProgressLoggerCreatedWhenLogFileIsNotStderr(t *testing.T) { | ||
| _, err := NewJobProgressLogger(flags.ModeInplace, "info", "stdout") | ||
| assert.NoError(t, err) | ||
| } |
This file contains hidden or 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,13 +1,20 @@ | ||
| package run | ||
|
|
||
| import flag "github.com/spf13/pflag" | ||
| import ( | ||
| "github.com/databricks/bricks/libs/flags" | ||
| flag "github.com/spf13/pflag" | ||
| ) | ||
|
|
||
| type Options struct { | ||
| Job JobOptions | ||
| Pipeline PipelineOptions | ||
| Job JobOptions | ||
| Pipeline PipelineOptions | ||
| ProgressFormat flags.ProgressLogFormat | ||
|
shreyas-goenka marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| func (o *Options) Define(fs *flag.FlagSet) { | ||
| o.Job.Define(fs) | ||
| o.Pipeline.Define(fs) | ||
|
|
||
| o.ProgressFormat = flags.NewProgressLogFormat() | ||
| fs.Var(&o.ProgressFormat, "progress-format", "format for progress logs (append, inplace, json)") | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a follow up this could be done in the progress logger itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally kept it outside incase we would like to log more information than what's being printed on stderr. For example we can decide to print the entire json blob even if the print mode is append just so more information is logged.
However, I think the right call is to simply just print the string even if the progress logger is printing json. We can decide to print more information if it seems useful later. It goes against making the log-file a dumping ground for everything, but I would rather avoid unnecessary clutter in our logs. WDYT?