Commit 8cd6e883 authored by Ben Kochie's avatar Ben Kochie

Merge pull request #125 from prometheus/superq/slave_connecting

Fix SLAVE STATUS "Connecting"
parents c67791b6 5bd3537f
......@@ -32,6 +32,10 @@ func parseStatus(data sql.RawBytes) (float64, bool) {
if bytes.Compare(data, []byte("No")) == 0 || bytes.Compare(data, []byte("OFF")) == 0 {
return 0, true
}
// SHOW SLAVE STATUS Slave_IO_Running can return "Connecting" which is a non-running state.
if bytes.Compare(data, []byte("Connecting")) == 0 {
return 0, true
}
if logNum := logRE.Find(data); logNum != nil {
value, err := strconv.ParseFloat(string(logNum), 64)
return value, err == nil
......
package collector
import (
"testing"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/smartystreets/goconvey/convey"
"gopkg.in/DATA-DOG/go-sqlmock.v1"
)
func TestScrapeSlaveStatus(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("error opening a stub database connection: %s", err)
}
defer db.Close()
columns := []string{"Master_Host", "Read_Master_Log_Pos", "Slave_IO_Running", "Slave_SQL_Running", "Seconds_Behind_Master"}
rows := sqlmock.NewRows(columns).
AddRow("127.0.0.1", "1", "Connecting", "Yes", "2")
mock.ExpectQuery(sanitizeQuery(slaveStatusQuery)).WillReturnRows(rows)
ch := make(chan prometheus.Metric)
go func() {
if err = ScrapeSlaveStatus(db, ch); err != nil {
t.Errorf("error calling function on test: %s", err)
}
close(ch)
}()
counterExpected := []MetricResult{
{labels: labelMap{}, value: 1, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 0, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 1, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 2, metricType: dto.MetricType_UNTYPED},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range counterExpected {
got := readMetric(<-ch)
convey.So(got, convey.ShouldResemble, expect)
}
})
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment