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

Support callbacks #26

Open
zikwall opened this issue Jun 11, 2022 · 0 comments
Open

Support callbacks #26

zikwall opened this issue Jun 11, 2022 · 0 comments
Labels
todo something for future

Comments

@zikwall
Copy link
Owner

zikwall commented Jun 11, 2022

Why? you can, for example, write metrics in Prometheus or organize your own custom processing.

Writer callbacks

// call after write to tmp buffer
func onWrite(view cx.View) {}
// call after write batch to Clickhouse
func onWriteClickhouse(view cx.View, count uint64) {}
// call if write to clickhouse return error
// if this function has called, then repeated attempts are not enabled
func onWriteClickhouseError(err error, batch *cx.Batch) {}

Retry callbacks

// call after batch push to retry queue
func onRetryPush() {}
// call after rerty successfully handle
func onRetryComplete(view cx.View, countAttempt uint8) {}
// call if retry batch fails
func onRetryFail(err error, batch *retry.Retry)

examples:

// note: there is a pseudocode

func onWriteClickhouse(view cx.View, count uint64) {
  prometheus.WithLabelValues("clickhouse", view.Table).Add(count)
}

func onWriteClickhouseError(err error, batch *cx.Batch) {
   // code
  prometheus.WithLabelValues("clickhouse", batch.View().Table, getErrorHumanableCode(err)).Inc()
  // save batch to athoner storange, for example file
  _ = failservice.Encode(batch).Write(ctx)
  // other code
}
@zikwall zikwall added the todo something for future label Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo something for future
Projects
None yet
Development

No branches or pull requests

1 participant