-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
Add file emitter that writes event data file #67
Conversation
9858e56
to
3671f32
Compare
return 1 | ||
} | ||
return 0 | ||
} |
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.
SendMetrics
is the commandFunc
for the dolt command "dolt send-metrics". Looking for feedback on how to handle the error logging here. This also gets run in a separate process on all other dolt commands using os.exec
go/cmd/dolt/dolt.go
Outdated
// conn, _ := dEnv.GrpcConnWithCreds(hostAndPort, insecure, nil) | ||
|
||
// return events.NewGrpcEmitter(conn) | ||
// } | ||
|
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.
Commented this code out just during development while working on the FileEmitter
.
It seems like this function is used to handle the creation of the default emitter we want, based on the various emitters we've created?
Do we want the FileEmitter
to now be the default emitter we instantiate?
} | ||
} | ||
return nil | ||
} |
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.
Running the hidden command "send-metrics" on a new process for every other dolt command. This block does not run if the user types it in herself, since otherwise it would loop infinitely.
go/go.sum
Outdated
@@ -195,6 +195,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | |||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | |||
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= | |||
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | |||
github.com/liquidata-inc/dolt v0.9.8 h1:uup9UA59oSvYsqYd9A3zF0CFXUnF1qI8odE+Cxtn+pg= | |||
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20190710171053-b2883167103a h1:Z8uOEqaBW1a0vpu+S9MlWwiyIDrjtn9sZ/CCcs32e9s= | |||
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20190710171053-b2883167103a/go.mod h1:bXirMMsoAKR1OI9GTQJPGSyuwJlOseI9AFNAdpwRY2k= | |||
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0 h1:phMgajKClMUiIr+hF2LGt8KRuUa2Vd2GI1sNgHgSXoU= |
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'm not to sure how the go.sum
works yet, which makes me pretty nervous. I don't touch this file, but it seems to change at times automatically... Planning to look into this.
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.
go.sum works via witchcraft
empty = true | ||
} | ||
} | ||
} |
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.
Same code from the events server. Just changed the log extension variable to be evtDataExt
.
Will add the test file as well.
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 think this might be a bit of overkill and could result in a ton of send-metrics processes running when someone is working in offline mode. I think instead of watching the directory and looping as long and there are still files, you should just loop over all files until you have a failure to send, and then exit on first failure.
// should panic? | ||
panic(ErrEventsDataDir) | ||
} | ||
|
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.
Not sure if we should panic here? This panic would occur in the separate process.
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.
It's probably fine.
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.
Took a first pass on this review. Will dig a little deeper later today.
go/cmd/dolt/dolt.go
Outdated
@@ -128,11 +129,19 @@ func runMain() int { | |||
|
|||
dEnv := env.Load(context.TODO(), env.GetCurrentUserHomeDir, filesys.LocalFS, doltdb.LocalDirDoltDB) | |||
|
|||
if err := processEventsDir(args, dEnv); err != nil { | |||
// log err | |||
log.Fatal(err) |
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.
We shouldn't ever let metrics failures fail dolt commands.
go/go.sum
Outdated
@@ -195,6 +195,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | |||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | |||
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= | |||
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | |||
github.com/liquidata-inc/dolt v0.9.8 h1:uup9UA59oSvYsqYd9A3zF0CFXUnF1qI8odE+Cxtn+pg= | |||
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20190710171053-b2883167103a h1:Z8uOEqaBW1a0vpu+S9MlWwiyIDrjtn9sZ/CCcs32e9s= | |||
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20190710171053-b2883167103a/go.mod h1:bXirMMsoAKR1OI9GTQJPGSyuwJlOseI9AFNAdpwRY2k= | |||
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0 h1:phMgajKClMUiIr+hF2LGt8KRuUa2Vd2GI1sNgHgSXoU= |
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.
go.sum works via witchcraft
empty = true | ||
} | ||
} | ||
} |
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 think this might be a bit of overkill and could result in a ton of send-metrics processes running when someone is working in offline mode. I think instead of watching the directory and looping as long and there are still files, you should just loop over all files until you have a failure to send, and then exit on first failure.
go/libraries/events/event_flush.go
Outdated
// conn, _ := dEnv.GrpcConnWithCreds(hostAndPort, insecure, nil) | ||
|
||
// local grpc for dev | ||
hostAndPort := fmt.Sprintf("%s:%d", "localhost", 50051) |
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.
you can connect locally without having to hard code this. You can run these commands:
dolt config --global --add metrics.host localhost
dolt config --global --add metrics.port 50051
dolt config --global --add metrics.insecure true
in order to point your dolt cli at your local metrics server.
// should panic? | ||
panic(ErrEventsDataDir) | ||
} | ||
|
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.
It's probably fine.
177cfcd
to
1090c2e
Compare
|
||
if err := processEventsDir(args, dEnv); err != nil { | ||
log.Print(err) | ||
} | ||
}() |
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.
Update: This is no longer a log.Fatal
} | ||
|
||
return nil | ||
} |
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.
Much simpler implementation now using fs.Iter()
and the flush()
method.
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.
Looking pretty good. Couple more comments.
go/cmd/dolt/dolt.go
Outdated
cmd := exec.Command("dolt", commands.SendMetricsCommand) | ||
|
||
if err := cmd.Start(); err != nil { | ||
log.Print(err) |
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 think we should fail silently until a later date when we support a verbose logging mode.
go/libraries/events/event_flush.go
Outdated
return false | ||
} | ||
|
||
isFileValid, err := checkFilenameAndExt(data, path) |
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.
if isFileValid is false, and err is nil that means the file is corrupted. Retries on this file won't fix it, so we should go ahead and delete it.
return err | ||
} | ||
|
||
if _, err := f.Write(data); err != nil { |
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.
it's possible that Write will write less than the entire buffer. iohelp.WriteAll will take care of flushing the entire contents of data.
8c6f06c
to
0249669
Compare
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.
Just a couple things to fix before merging. But looks good.
go/cmd/dolt/dolt.go
Outdated
|
||
insecure, err := strconv.ParseBool(*insecureStr) | ||
if err := cmd.Start(); err != nil { | ||
log.Print(err) |
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.
disable logging until we have verbose mode.
go/libraries/events/event_flush.go
Outdated
isFileValid, err := egf.fbp.CheckingFunc(data, path) | ||
|
||
if isFileValid && err == nil { | ||
ctx, cnclFn := context.WithDeadline(context.Background(), time.Now().Add(time.Second+500*time.Millisecond)) |
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.
Since we are running in a new process we can up this to time.Minute
"google.golang.org/grpc" | ||
) | ||
|
||
var globalEvents []*eventsapi.ClientEvent |
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.
using a global will be problematic if 2 of these tests run concurrently. I'd make this a member of the TestClient
0249669
to
9f7e867
Compare
9f7e867
to
dba75f6
Compare
type TestClient struct { | ||
CES []*eventsapi.ClientEvent | ||
} | ||
|
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.
no longer using the global events slice.
// log.Print(err) | ||
return 1 | ||
} | ||
|
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.
logging commented out in both dolt.go
and send_metrics.go
go/libraries/events/event_flush.go
Outdated
if isFileValid && err == nil { | ||
ctx, cnclFn := context.WithDeadline(context.Background(), time.Now().Add(time.Minute)) | ||
defer cnclFn() | ||
|
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.
changed to time.Minute
…hod, tests in progress.
cfeb926
to
ecba41d
Compare
ecba41d
to
e4bf724
Compare
e4bf724
to
ce7a338
Compare
|
||
return &FileBackedProc{ed: eventsDataDir, namingFunc: nf, CheckingFunc: cf, LockPath: lp} | ||
} | ||
|
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.
This is the new implementation of the locking system. Instead of locking the entire events directory, I create a dolt.lock
file if it does not exist, then lock/unlock this file.
Added file emitter that saves event data to files, and a flush that parses the files and sends them to the grpc server.