Skip to content

Commit

Permalink
Fix TidbMonitor ClusterRef missing error in prometheus rule (pingcap#…
Browse files Browse the repository at this point in the history
…2746) (pingcap#2766)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Song Gao <disxiaofei@163.com>
  • Loading branch information
ti-srebot and Yisaer committed Jun 18, 2020
1 parent b2ec56d commit a710b21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/monitor/monitor/monitor_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func NewMonitorManager(
}

func (mm *MonitorManager) SyncMonitor(monitor *v1alpha1.TidbMonitor) error {

if monitor.DeletionTimestamp != nil {
return nil
}
if monitor.Spec.Clusters == nil || len(monitor.Spec.Clusters) < 1 {
err := fmt.Errorf("tm[%s/%s] does not configure the target tidbcluster", monitor.Namespace, monitor.Name)
return err
}
defaultTidbMonitor(monitor)
tcRef := monitor.Spec.Clusters[0]
if len(tcRef.Namespace) < 1 {
tcRef.Namespace = monitor.Namespace
Expand Down
9 changes: 9 additions & 0 deletions pkg/monitor/monitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,12 @@ func prometheusName(monitor *v1alpha1.TidbMonitor) string {
func grafanaName(monitor *v1alpha1.TidbMonitor) string {
return fmt.Sprintf("%s-grafana", monitor.Name)
}

func defaultTidbMonitor(monitor *v1alpha1.TidbMonitor) {
for id, tcRef := range monitor.Spec.Clusters {
if len(tcRef.Namespace) < 1 {
tcRef.Namespace = monitor.Namespace
}
monitor.Spec.Clusters[id] = tcRef
}
}

0 comments on commit a710b21

Please sign in to comment.