Skip to content

Commit

Permalink
Use dbversion as 5.7.0 when failing to retrive using query or parsing…
Browse files Browse the repository at this point in the history
… the query output
  • Loading branch information
sairaj18 committed Jan 3, 2025
1 parent 5f06db8 commit 4c7c043
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/metrics_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func asValue(value string) interface{} {
func getRawData(db dataSource) (map[string]interface{}, map[string]interface{}, string, error) {
dbVersion, err := collectDBVersion(db)
if err != nil {
return nil, nil, "", fmt.Errorf("metrics collection failed: error collecting version number: %w", err)
log.Warn(err.Error())
log.Warn("Assuming the mysql version to be less than 8.0 and proceeding further")
dbVersion = "5.7.0"
}

inventory, err := db.query(inventoryQuery)
Expand Down
28 changes: 28 additions & 0 deletions src/metrics_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,31 @@ func TestExtractSanitizedVersion(t *testing.T) {
})
}
}

func TestGetRawDataWithoutDBVersion(t *testing.T) {
database := testdb{
inventory: map[string]interface{}{
"key_cache_block_size": 10,
"key_buffer_size": 10,
"version_comment": "mysql",
"version": "5.7.0",
},
metrics: map[string]interface{}{},
replica: map[string]interface{}{},
version: map[string]interface{}{},
}
inventory, metrics, dbVersion, err := getRawData(database)
assert.Equal(t, "5.7.0", dbVersion)
if err != nil {
t.Error()
}
if metrics == nil {
t.Error()
}
if inventory == nil {
t.Error()
}
if dbVersion == "" {
t.Error()
}
}

0 comments on commit 4c7c043

Please sign in to comment.