The kafka.ErrorCode type only provides a String function that converts it to a human-readable string description of the error. But I would like to get the actual error code constant name. The motivation is to use it as a low-cardinality and concise string for monitoring purposes (storing as InfluxDB tag) and thus be able to view/aggregate by various error codes in Grafana. (While the current implementation of ErrorCode.String may also have low cardinality, it is longer than I want for my purposes.) For example:
var code kafka.ErrorCode = kafka.ErrInvalidRequest
fmt.Println(code.Name())
would print either ErrInvalidRequest or INVALID_REQUEST (derived from RD_KAFKA_RESP_ERR_INVALID_REQUEST). I don't really have a preference on which one.
This could be accomplished by calling either rd_kafka_err2name to get the INVALID_REQUEST string. Or alternatively, code generate a Name function that contains a giant "switch" statement that returns the appropriate string (e.g. similar to the hand-written func (p Pill) String() string example at https://blog.golang.org/generate )
Description
The
kafka.ErrorCode
type only provides aString
function that converts it to a human-readable string description of the error. But I would like to get the actual error code constant name. The motivation is to use it as a low-cardinality and concise string for monitoring purposes (storing as InfluxDB tag) and thus be able to view/aggregate by various error codes in Grafana. (While the current implementation ofErrorCode.String
may also have low cardinality, it is longer than I want for my purposes.) For example:would print either
ErrInvalidRequest
orINVALID_REQUEST
(derived fromRD_KAFKA_RESP_ERR_INVALID_REQUEST
). I don't really have a preference on which one.This could be accomplished by calling either
rd_kafka_err2name
to get theINVALID_REQUEST
string. Or alternatively, code generate aName
function that contains a giant "switch" statement that returns the appropriate string (e.g. similar to the hand-writtenfunc (p Pill) String() string
example at https://blog.golang.org/generate )