Skip to content

Support callbacks #26

@zikwall

Description

@zikwall

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    todosomething for future

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions