Skip to content
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

Merged
merged 30 commits into from
Sep 11, 2019
Merged

Conversation

coffeegoddd
Copy link
Contributor

@coffeegoddd coffeegoddd commented Sep 3, 2019

Added file emitter that saves event data to files, and a flush that parses the files and sends them to the grpc server.

return 1
}
return 0
}
Copy link
Contributor Author

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

// conn, _ := dEnv.GrpcConnWithCreds(hostAndPort, insecure, nil)

// return events.NewGrpcEmitter(conn)
// }

Copy link
Contributor Author

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
}
Copy link
Contributor Author

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=
Copy link
Contributor Author

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.

Copy link
Contributor

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
}
}
}
Copy link
Contributor Author

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.

Copy link
Contributor

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)
}

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably fine.

Copy link
Contributor

@bheni bheni left a 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.

@@ -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)
Copy link
Contributor

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=
Copy link
Contributor

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
}
}
}
Copy link
Contributor

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.

// conn, _ := dEnv.GrpcConnWithCreds(hostAndPort, insecure, nil)

// local grpc for dev
hostAndPort := fmt.Sprintf("%s:%d", "localhost", 50051)
Copy link
Contributor

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)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably fine.

@coffeegoddd coffeegoddd force-pushed the db/file-emitter branch 4 times, most recently from 177cfcd to 1090c2e Compare September 4, 2019 00:37

if err := processEventsDir(args, dEnv); err != nil {
log.Print(err)
}
}()
Copy link
Contributor Author

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
}
Copy link
Contributor Author

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.

Copy link
Contributor

@bheni bheni left a 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.

cmd := exec.Command("dolt", commands.SendMetricsCommand)

if err := cmd.Start(); err != nil {
log.Print(err)
Copy link
Contributor

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.

return false
}

isFileValid, err := checkFilenameAndExt(data, path)
Copy link
Contributor

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 {
Copy link
Contributor

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.

@coffeegoddd coffeegoddd force-pushed the db/file-emitter branch 2 times, most recently from 8c6f06c to 0249669 Compare September 4, 2019 17:44
@coffeegoddd coffeegoddd changed the title [WIP] Add file emitter that writes event data file Add file emitter that writes event data file Sep 4, 2019
Copy link
Contributor

@bheni bheni left a 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.


insecure, err := strconv.ParseBool(*insecureStr)
if err := cmd.Start(); err != nil {
log.Print(err)
Copy link
Contributor

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.

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))
Copy link
Contributor

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
Copy link
Contributor

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

type TestClient struct {
CES []*eventsapi.ClientEvent
}

Copy link
Contributor Author

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
}

Copy link
Contributor Author

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

if isFileValid && err == nil {
ctx, cnclFn := context.WithDeadline(context.Background(), time.Now().Add(time.Minute))
defer cnclFn()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to time.Minute

@coffeegoddd coffeegoddd force-pushed the db/file-emitter branch 23 times, most recently from cfeb926 to ecba41d Compare September 11, 2019 18:26
@coffeegoddd coffeegoddd changed the base branch from bh/client-events to master September 11, 2019 18:43

return &FileBackedProc{ed: eventsDataDir, namingFunc: nf, CheckingFunc: cf, LockPath: lp}
}

Copy link
Contributor Author

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.

@coffeegoddd coffeegoddd merged commit b2f77fa into master Sep 11, 2019
@coffeegoddd coffeegoddd deleted the db/file-emitter branch September 11, 2019 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants