Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion go/vt/vttablet/tabletserver/repltracker/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,35 @@ import (
"sync"
"time"

querypb "vitess.io/vitess/go/vt/proto/query"

"vitess.io/vitess/go/stats"

"vitess.io/vitess/go/vt/mysqlctl"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"
)

var replicationLagGauges = stats.NewGaugesWithMultiLabels(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the vttablet metrics have the keyspace/shard dimensions because by definition a tablet belongs to only one keyspace/shard. This can be a simple gauge (NewGauge).
Also the name should include the units - replicationLagMs or replicationLagNs.
HeartbeatLag is being reported in nanoseconds so we should probably do the same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I renamed the gauge to replicationLagSec since we always assume the lag in seconds (e.g., we have SecondsBehindMaster and also cast the duration to sec on line 60)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes more sense than ns :)

"replicationLag",
"replication lag",
[]string{"Keyspace", "Shard"})

type poller struct {
mysqld mysqlctl.MysqlDaemon

mu sync.Mutex
lag time.Duration
timeRecorded time.Time

keyspace string
shard string
}

func (p *poller) InitDBConfig(mysqld mysqlctl.MysqlDaemon) {
func (p *poller) InitDBConfig(mysqld mysqlctl.MysqlDaemon, target querypb.Target) {
p.mysqld = mysqld
p.keyspace = target.Keyspace
p.shard = target.Shard
}

func (p *poller) Status() (time.Duration, error) {
Expand All @@ -55,5 +69,6 @@ func (p *poller) Status() (time.Duration, error) {

p.lag = time.Duration(status.SecondsBehindMaster) * time.Second
p.timeRecorded = time.Now()
replicationLagGauges.Set([]string{p.keyspace, p.shard}, p.lag.Milliseconds())
return p.lag, nil
}
6 changes: 5 additions & 1 deletion go/vt/vttablet/tabletserver/repltracker/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ import (
"testing"
"time"

querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"

"github.com/stretchr/testify/assert"

"vitess.io/vitess/go/vt/mysqlctl/fakemysqldaemon"
)

func TestPoller(t *testing.T) {
target := querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_REPLICA}
poller := &poller{}
mysqld := fakemysqldaemon.NewFakeMysqlDaemon(nil)
poller.InitDBConfig(mysqld)
poller.InitDBConfig(mysqld, target)

mysqld.ReplicationStatusError = errors.New("err")
_, err := poller.Status()
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/repltracker/repltracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewReplTracker(env tabletenv.Env, alias topodatapb.TabletAlias) *ReplTracke
func (rt *ReplTracker) InitDBConfig(target querypb.Target, mysqld mysqlctl.MysqlDaemon) {
rt.hw.InitDBConfig(target)
rt.hr.InitDBConfig(target)
rt.poller.InitDBConfig(mysqld)
rt.poller.InitDBConfig(mysqld, target)
}

// MakeMaster must be called if the tablet type becomes MASTER.
Expand Down