Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 0 additions & 10 deletions go/vt/vttablet/tabletserver/throttle/config/mysql_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ package config
// MySQLClusterConfigurationSettings has the settings for a specific MySQL cluster. It derives its information
// from MySQLConfigurationSettings
type MySQLClusterConfigurationSettings struct {
User string // override MySQLConfigurationSettings's, or leave empty to inherit those settings
Password string // override MySQLConfigurationSettings's, or leave empty to inherit those settings
MetricQuery string // override MySQLConfigurationSettings's, or leave empty to inherit those settings
CacheMillis int // override MySQLConfigurationSettings's, or leave empty to inherit those settings
ThrottleThreshold float64 // override MySQLConfigurationSettings's, or leave empty to inherit those settings
Expand All @@ -33,8 +31,6 @@ func (settings *MySQLClusterConfigurationSettings) postReadAdjustments() error {

// MySQLConfigurationSettings has the general configuration for all MySQL clusters
type MySQLConfigurationSettings struct {
User string
Password string
MetricQuery string
CacheMillis int // optional, if defined then probe result will be cached, and future probes may use cached value
ThrottleThreshold float64
Expand All @@ -59,12 +55,6 @@ func (settings *MySQLConfigurationSettings) postReadAdjustments() error {
if err := clusterSettings.postReadAdjustments(); err != nil {
return err
}
if clusterSettings.User == "" {
clusterSettings.User = settings.User
}
if clusterSettings.Password == "" {
clusterSettings.Password = settings.Password
}
if clusterSettings.MetricQuery == "" {
clusterSettings.MetricQuery = settings.MetricQuery
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

"github.com/patrickmn/go-cache"
metrics "github.com/rcrowley/go-metrics"

"vitess.io/vitess/go/vt/orchestrator/external/golib/sqlutils"
)

// MetricsQueryType indicates the type of metrics query on MySQL backend. See following.
Expand Down Expand Up @@ -118,44 +116,6 @@ func ReadThrottleMetric(probe *Probe, clusterName string, overrideGetMetricFunc
}()
}(mySQLThrottleMetric, started)

if overrideGetMetricFunc != nil {
mySQLThrottleMetric = overrideGetMetricFunc()
return cacheMySQLThrottleMetric(probe, mySQLThrottleMetric)
}

dbURI := probe.GetDBUri("information_schema")
db, fromCache, err := sqlutils.GetDB(dbURI)

if err != nil {
mySQLThrottleMetric.Err = err
return mySQLThrottleMetric
}
if !fromCache {
db.SetMaxOpenConns(maxPoolConnections)
db.SetMaxIdleConns(maxIdleConnections)
}
metricsQueryType := GetMetricsQueryType(probe.MetricQuery)
switch metricsQueryType {
case MetricsQueryTypeSelect:
mySQLThrottleMetric.Err = db.QueryRow(probe.MetricQuery).Scan(&mySQLThrottleMetric.Value)
return cacheMySQLThrottleMetric(probe, mySQLThrottleMetric)
case MetricsQueryTypeShowGlobal:
var variableName string // just a placeholder
mySQLThrottleMetric.Err = db.QueryRow(probe.MetricQuery).Scan(&variableName, &mySQLThrottleMetric.Value)
return cacheMySQLThrottleMetric(probe, mySQLThrottleMetric)
case MetricsQueryTypeDefault:
mySQLThrottleMetric.Err = sqlutils.QueryRowsMap(db, `show slave status`, func(m sqlutils.RowMap) error {
IOThreadRunning := m.GetString("Slave_IO_Running")
SQLThreadRunning := m.GetString("Slave_SQL_Running")
replicationLagSeconds := m.GetNullInt64("Seconds_Behind_Master")
if !replicationLagSeconds.Valid {
return fmt.Errorf("replication not running; Slave_IO_Running=%+v, Slave_SQL_Running=%+v", IOThreadRunning, SQLThreadRunning)
}
mySQLThrottleMetric.Value = float64(replicationLagSeconds.Int64)
return nil
})
return cacheMySQLThrottleMetric(probe, mySQLThrottleMetric)
}
mySQLThrottleMetric.Err = fmt.Errorf("Unsupported metrics query type: %s", probe.MetricQuery)
return mySQLThrottleMetric
mySQLThrottleMetric = overrideGetMetricFunc()
return cacheMySQLThrottleMetric(probe, mySQLThrottleMetric)
}
35 changes: 1 addition & 34 deletions go/vt/vttablet/tabletserver/throttle/mysql/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ package mysql

import (
"fmt"
"net"
)

const maxPoolConnections = 3
const maxIdleConnections = 3
const timeoutMillis = 1000

// Probe is the minimal configuration required to connect to a MySQL server
type Probe struct {
Key InstanceKey
User string
Password string
MetricQuery string
TabletHost string
TabletPort int
Expand Down Expand Up @@ -51,38 +44,12 @@ func NewProbe() *Probe {
return config
}

// DuplicateCredentials creates a new connection config with given key and with same credentials as this config
func (p *Probe) DuplicateCredentials(key InstanceKey) *Probe {
config := &Probe{
Key: key,
User: p.User,
Password: p.Password,
}
return config
}

// Duplicate duplicates this probe, including credentials
func (p *Probe) Duplicate() *Probe {
return p.DuplicateCredentials(p.Key)
}

// String returns a human readable string of this struct
func (p *Probe) String() string {
return fmt.Sprintf("%s, user=%s", p.Key.DisplayString(), p.User)
return fmt.Sprintf("%s, tablet=%s:%d", p.Key.DisplayString(), p.TabletHost, p.TabletPort)
}

// Equals checks if this probe has same instance key as another
func (p *Probe) Equals(other *Probe) bool {
return p.Key.Equals(&other.Key)
}

// GetDBUri returns the DB URI for the mysql server indicated by this probe
func (p *Probe) GetDBUri(databaseName string) string {
hostname := p.Key.Hostname
var ip = net.ParseIP(hostname)
if (ip != nil) && (ip.To4() == nil) {
// Wrap IPv6 literals in square brackets
hostname = fmt.Sprintf("[%s]", hostname)
}
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?interpolateParams=true&charset=utf8mb4,utf8,latin1&timeout=%dms", p.User, p.Password, hostname, p.Key.Port, databaseName, timeoutMillis)
}
28 changes: 0 additions & 28 deletions go/vt/vttablet/tabletserver/throttle/mysql/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,4 @@ func TestNewProbe(t *testing.T) {
c := NewProbe()
assert.Equal(t, "", c.Key.Hostname)
assert.Equal(t, 0, c.Key.Port)
assert.Equal(t, "", c.User)
assert.Equal(t, "", c.Password)
}

func TestDuplicateCredentials(t *testing.T) {
c := NewProbe()
c.Key = InstanceKey{Hostname: "myhost", Port: 3306}
c.User = "gromit"
c.Password = "penguin"

dup := c.DuplicateCredentials(InstanceKey{Hostname: "otherhost", Port: 3310})
assert.Equal(t, "otherhost", dup.Key.Hostname)
assert.Equal(t, 3310, dup.Key.Port)
assert.Equal(t, "gromit", dup.User)
assert.Equal(t, "penguin", dup.Password)
}

func TestDuplicate(t *testing.T) {
c := NewProbe()
c.Key = InstanceKey{Hostname: "myhost", Port: 3306}
c.User = "gromit"
c.Password = "penguin"

dup := c.Duplicate()
assert.Equal(t, "myhost", dup.Key.Hostname)
assert.Equal(t, 3306, dup.Key.Port)
assert.Equal(t, "gromit", dup.User)
assert.Equal(t, "penguin", dup.Password)
}
Loading