Skip to content

Commit

Permalink
instance key -> tablet alias
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Oct 4, 2023
1 parent 6c728ff commit 23a1872
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 279 deletions.
8 changes: 4 additions & 4 deletions go/vt/vttablet/tabletserver/throttle/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func aggregateMySQLProbes(
ctx context.Context,
probes mysql.Probes,
clusterName string,
instanceResultsMap mysql.InstanceMetricResultMap,
tabletResultsMap mysql.TabletResultMap,
ignoreHostsCount int,
IgnoreDialTCPErrors bool,
ignoreHostsThreshold float64,
Expand All @@ -27,12 +27,12 @@ func aggregateMySQLProbes(
// so it's safe to iterate it
probeValues := []float64{}
for _, probe := range probes {
instanceMetricResult, ok := instanceResultsMap[mysql.GetClusterInstanceKey(clusterName, &probe.Key)]
tabletMetricResult, ok := tabletResultsMap[mysql.GetClusterTablet(clusterName, probe.Alias)]
if !ok {
return base.NoMetricResultYet
}

value, err := instanceMetricResult.Get()
value, err := tabletMetricResult.Get()
if err != nil {
if IgnoreDialTCPErrors && base.IsDialTCPError(err) {
continue
Expand All @@ -42,7 +42,7 @@ func aggregateMySQLProbes(
ignoreHostsCount = ignoreHostsCount - 1
continue
}
return instanceMetricResult
return tabletMetricResult
}

// No error
Expand Down
98 changes: 0 additions & 98 deletions go/vt/vttablet/tabletserver/throttle/mysql/instance_key.go

This file was deleted.

66 changes: 0 additions & 66 deletions go/vt/vttablet/tabletserver/throttle/mysql/instance_key_test.go

This file was deleted.

20 changes: 10 additions & 10 deletions go/vt/vttablet/tabletserver/throttle/mysql/mysql_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import (
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base"
)

// ClusterInstanceKey combines a cluster name with an instance key
type ClusterInstanceKey struct {
// ClusterTablet combines a cluster name with a tablet alias
type ClusterTablet struct {
ClusterName string
Key InstanceKey
Alias string
}

// GetClusterInstanceKey creates a ClusterInstanceKey object
func GetClusterInstanceKey(clusterName string, key *InstanceKey) ClusterInstanceKey {
return ClusterInstanceKey{ClusterName: clusterName, Key: *key}
// GetClusterTablet creates a GetClusterTablet object
func GetClusterTablet(clusterName string, alias string) ClusterTablet {
return ClusterTablet{ClusterName: clusterName, Alias: alias}
}

// InstanceMetricResultMap maps a cluster-instance to a result
type InstanceMetricResultMap map[ClusterInstanceKey]base.MetricResult
// TabletResultMap maps a cluster-tablet to a result
type TabletResultMap map[ClusterTablet]base.MetricResult

// Inventory has the operational data about probes, their metrics, and relevant configuration
type Inventory struct {
ClustersProbes map[string](Probes)
IgnoreHostsCount map[string]int
IgnoreHostsThreshold map[string]float64
InstanceKeyMetrics InstanceMetricResultMap
TabletMetrics TabletResultMap
}

// NewInventory creates a Inventory
Expand All @@ -38,7 +38,7 @@ func NewInventory() *Inventory {
ClustersProbes: make(map[string](Probes)),
IgnoreHostsCount: make(map[string]int),
IgnoreHostsThreshold: make(map[string]float64),
InstanceKeyMetrics: make(map[ClusterInstanceKey]base.MetricResult),
TabletMetrics: make(map[ClusterTablet]base.MetricResult),
}
return inventory
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
var mysqlMetricCache = cache.New(cache.NoExpiration, 10*time.Second)

func getMySQLMetricCacheKey(probe *Probe) string {
return fmt.Sprintf("%s:%s", probe.Key, probe.MetricQuery)
return fmt.Sprintf("%s:%s", probe.Alias, probe.MetricQuery)
}

func cacheMySQLThrottleMetric(probe *Probe, mySQLThrottleMetric *MySQLThrottleMetric) *MySQLThrottleMetric {
Expand Down Expand Up @@ -71,10 +71,10 @@ func GetMetricsQueryType(query string) MetricsQueryType {
return MetricsQueryTypeUnknown
}

// MySQLThrottleMetric has the probed metric for a mysql instance
// MySQLThrottleMetric has the probed metric for a tablet
type MySQLThrottleMetric struct { // nolint:revive
ClusterName string
Key InstanceKey
Alias string
Value float64
Err error
}
Expand All @@ -84,9 +84,9 @@ func NewMySQLThrottleMetric() *MySQLThrottleMetric {
return &MySQLThrottleMetric{Value: 0}
}

// GetClusterInstanceKey returns the ClusterInstanceKey part of the metric
func (metric *MySQLThrottleMetric) GetClusterInstanceKey() ClusterInstanceKey {
return GetClusterInstanceKey(metric.ClusterName, &metric.Key)
// GetClusterTablet returns the ClusterTablet part of the metric
func (metric *MySQLThrottleMetric) GetClusterTablet() ClusterTablet {
return GetClusterTablet(metric.ClusterName, metric.Alias)
}

// Get implements MetricResult
Expand All @@ -105,7 +105,7 @@ func ReadThrottleMetric(probe *Probe, clusterName string, overrideGetMetricFunc
started := time.Now()
mySQLThrottleMetric = NewMySQLThrottleMetric()
mySQLThrottleMetric.ClusterName = clusterName
mySQLThrottleMetric.Key = probe.Key
mySQLThrottleMetric.Alias = probe.Alias

defer func(metric *MySQLThrottleMetric, started time.Time) {
go func() {
Expand Down
20 changes: 6 additions & 14 deletions go/vt/vttablet/tabletserver/throttle/mysql/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Probe is the minimal configuration required to connect to a MySQL server
type Probe struct {
Key InstanceKey
Alias string
MetricQuery string
Tablet *topodatapb.Tablet
TabletHost string
Expand All @@ -23,15 +23,15 @@ type Probe struct {
QueryInProgress int64
}

// Probes maps instances to probe(s)
type Probes map[InstanceKey](*Probe)
// Probes maps tablet aliases to probe(s)
type Probes map[string](*Probe)

// ClusterProbes has the probes for a specific cluster
type ClusterProbes struct {
ClusterName string
IgnoreHostsCount int
IgnoreHostsThreshold float64
InstanceProbes Probes
TabletProbes Probes
}

// NewProbes creates Probes
Expand All @@ -41,18 +41,10 @@ func NewProbes() Probes {

// NewProbe creates Probe
func NewProbe() *Probe {
config := &Probe{
Key: InstanceKey{},
}
return config
return &Probe{}
}

// String returns a human readable string of this struct
func (p *Probe) String() string {
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)
return fmt.Sprintf("%s, tablet=%s:%d", p.Alias, p.TabletHost, p.TabletPort)
}
3 changes: 1 addition & 2 deletions go/vt/vttablet/tabletserver/throttle/mysql/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ import (

func TestNewProbe(t *testing.T) {
c := NewProbe()
assert.Equal(t, "", c.Key.Hostname)
assert.Equal(t, 0, c.Key.Port)
assert.Equal(t, "", c.Alias)
}
Loading

0 comments on commit 23a1872

Please sign in to comment.