fix: inconsistent metric types in mysql (#9403)
This commit is contained in:
parent
d9b202a41b
commit
4194e54ceb
|
|
@ -21,6 +21,10 @@ func ParseInt(value sql.RawBytes) (interface{}, error) {
|
||||||
return v, err
|
return v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseUint(value sql.RawBytes) (interface{}, error) {
|
||||||
|
return strconv.ParseUint(string(value), 10, 64)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseBoolAsInteger(value sql.RawBytes) (interface{}, error) {
|
func ParseBoolAsInteger(value sql.RawBytes) (interface{}, error) {
|
||||||
if bytes.EqualFold(value, []byte("YES")) || bytes.EqualFold(value, []byte("ON")) {
|
if bytes.EqualFold(value, []byte("YES")) || bytes.EqualFold(value, []byte("ON")) {
|
||||||
return int64(1), nil
|
return int64(1), nil
|
||||||
|
|
@ -29,6 +33,10 @@ func ParseBoolAsInteger(value sql.RawBytes) (interface{}, error) {
|
||||||
return int64(0), nil
|
return int64(0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseString(value sql.RawBytes) (interface{}, error) {
|
||||||
|
return string(value), nil
|
||||||
|
}
|
||||||
|
|
||||||
func ParseGTIDMode(value sql.RawBytes) (interface{}, error) {
|
func ParseGTIDMode(value sql.RawBytes) (interface{}, error) {
|
||||||
// https://dev.mysql.com/doc/refman/8.0/en/replication-mode-change-online-concepts.html
|
// https://dev.mysql.com/doc/refman/8.0/en/replication-mode-change-online-concepts.html
|
||||||
v := string(value)
|
v := string(value)
|
||||||
|
|
@ -58,6 +66,9 @@ func ParseValue(value sql.RawBytes) (interface{}, error) {
|
||||||
if val, err := strconv.ParseInt(string(value), 10, 64); err == nil {
|
if val, err := strconv.ParseInt(string(value), 10, 64); err == nil {
|
||||||
return val, nil
|
return val, nil
|
||||||
}
|
}
|
||||||
|
if val, err := strconv.ParseUint(string(value), 10, 64); err == nil {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
if val, err := strconv.ParseFloat(string(value), 64); err == nil {
|
if val, err := strconv.ParseFloat(string(value), 64); err == nil {
|
||||||
return val, nil
|
return val, nil
|
||||||
}
|
}
|
||||||
|
|
@ -70,12 +81,29 @@ func ParseValue(value sql.RawBytes) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var GlobalStatusConversions = map[string]ConversionFunc{
|
var GlobalStatusConversions = map[string]ConversionFunc{
|
||||||
"ssl_ctx_verify_depth": ParseInt,
|
"innodb_available_undo_logs": ParseUint,
|
||||||
"ssl_verify_depth": ParseInt,
|
"innodb_buffer_pool_pages_misc": ParseUint,
|
||||||
|
"innodb_data_pending_fsyncs": ParseUint,
|
||||||
|
"ssl_ctx_verify_depth": ParseUint,
|
||||||
|
"ssl_verify_depth": ParseUint,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
|
||||||
|
// see https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html
|
||||||
var GlobalVariableConversions = map[string]ConversionFunc{
|
var GlobalVariableConversions = map[string]ConversionFunc{
|
||||||
"gtid_mode": ParseGTIDMode,
|
"delay_key_write": ParseString, // ON, OFF, ALL
|
||||||
|
"enforce_gtid_consistency": ParseString, // ON, OFF, WARN
|
||||||
|
"event_scheduler": ParseString, // YES, NO, DISABLED
|
||||||
|
"gtid_mode": ParseGTIDMode,
|
||||||
|
"have_openssl": ParseBoolAsInteger, // alias for have_ssl
|
||||||
|
"have_ssl": ParseBoolAsInteger, // YES, DISABLED
|
||||||
|
"have_symlink": ParseBoolAsInteger, // YES, NO, DISABLED
|
||||||
|
"session_track_gtids": ParseString,
|
||||||
|
"session_track_transaction_info": ParseString,
|
||||||
|
"slave_skip_errors": ParseString,
|
||||||
|
"ssl_fips_mode": ParseString,
|
||||||
|
"transaction_write_set_extraction": ParseString,
|
||||||
|
"use_secondary_engine": ParseString,
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertGlobalStatus(key string, value sql.RawBytes) (interface{}, error) {
|
func ConvertGlobalStatus(key string, value sql.RawBytes) (interface{}, error) {
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@ func TestConvertGlobalStatus(t *testing.T) {
|
||||||
name: "default",
|
name: "default",
|
||||||
key: "ssl_ctx_verify_depth",
|
key: "ssl_ctx_verify_depth",
|
||||||
value: []byte("0"),
|
value: []byte("0"),
|
||||||
expected: int64(0),
|
expected: uint64(0),
|
||||||
expectedErr: nil,
|
expectedErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "overflow int64",
|
name: "overflow int64",
|
||||||
key: "ssl_ctx_verify_depth",
|
key: "ssl_ctx_verify_depth",
|
||||||
value: []byte("18446744073709551615"),
|
value: []byte("18446744073709551615"),
|
||||||
expected: int64(9223372036854775807),
|
expected: uint64(18446744073709551615),
|
||||||
expectedErr: nil,
|
expectedErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue