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

Provide an example how to get errors from asynchronous write API #102

Closed
fafnirbcrow opened this issue Apr 24, 2020 · 5 comments · Fixed by #115
Closed

Provide an example how to get errors from asynchronous write API #102

fafnirbcrow opened this issue Apr 24, 2020 · 5 comments · Fixed by #115
Assignees
Milestone

Comments

@fafnirbcrow
Copy link

I was trying to upgrade my client from the v0.1.5 version we were previously using, however I am unsure how I am supposed to handle errors properly with the async writer functions.

In

func (w *writeApiImpl) WritePoint(point *Point) {

If the service returns an error, it gets returned to a logger. and that is it.

That logger seems to be an instance of

type Logger struct {

Which only does prints.

What is the expected method to identify and handle failures on data writes, and set up an automatic retry?

@vlastahajek
Copy link
Contributor

@fafnirbcrow , WriteApi contains the Errors() method, which returns channel for write errors.
You have to read this asynchronously, otherwise, it will block write procedure in case of an error occurs.

@fafnirbcrow
Copy link
Author

I believe I see, so something like?

func handleErrors(e chan error){
	for i := range e {
		fmt.Println(i.Error())
	}
}

go handleErrors(WriteApi.Errors())

Since its a generic error object, how would we know which of the writes failed? Or should the entire batch be retried since it will overwrite in the db?

@vlastahajek
Copy link
Contributor

You can't pair a received error and a batch now. Batches are automatically retried on server overload (server responds with defined error codes).

Asynchronous write API best suits for writing frequent, nonprecious, data, such as telemetry, system metrics monitoring, weather sensing, etc.

You can use synchronous write API if you need control over write errors.

@fafnirbcrow
Copy link
Author

That makes sense. Might I recommend that information be added to the documentation, including an example of error handling. It would be a useful inclusion for people like me who are trying to get a handle on flux still.

@vlastahajek vlastahajek changed the title Issues with Error handling Provide an example how to get errors from asynchronous write API Apr 27, 2020
@vlastahajek
Copy link
Contributor

Definitely. I was already planning to do so...

@vlastahajek vlastahajek self-assigned this Apr 27, 2020
@vlastahajek vlastahajek added this to the v1.2.0 milestone Apr 27, 2020
vlastahajek added a commit to bonitoo-io/influxdb-client-go that referenced this issue May 5, 2020
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 a pull request may close this issue.

2 participants