Skip to content

Commit

Permalink
Merge branch 'release-1.0' into automated-cherry-pick-of-pingcap#898-…
Browse files Browse the repository at this point in the history
…upstream-release-1.0
  • Loading branch information
qiffang authored Dec 23, 2019
2 parents 49f5311 + beb2b27 commit 7aa642a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 23 deletions.
14 changes: 0 additions & 14 deletions charts/tidb-cluster/templates/config/_grafana-datasource.tpl

This file was deleted.

2 changes: 0 additions & 2 deletions charts/tidb-cluster/templates/monitor-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ data:
prometheus-config: |-
{{ tuple "config/_prometheus-config.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
{{- if .Values.monitor.grafana.create }}
datasource-config: |-
{{ tuple "config/_grafana-datasource.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
dashboard-config: |-
{{ tuple "config/_grafana-dashboard.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
{{- end }}
Expand Down
17 changes: 12 additions & 5 deletions charts/tidb-cluster/templates/monitor-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ spec:
env:
- name: GF_PROVISIONING_PATH
value: /grafana-dashboard-definitions/tidb
- name: GF_DATASOURCE_PATH
value: /etc/grafana/provisioning/datasources
- name: TIDB_CLUSTER_NAME
value: {{ template "cluster.name" . }}
- name: TIDB_ENABLE_BINLOG
Expand All @@ -70,6 +72,12 @@ spec:
value: /data
- name: TIDB_VERSION
value: {{ .Values.tidb.image }}
- name: GF_K8S_PROMETHEUS_URL
value: {{ .Values.monitor.initializer.config.K8S_PROMETHEUS_URL }}
- name: GF_TIDB_PROMETHEUS_URL
value: http://127.0.0.1:9090
- name: TIDB_CLUSTER_NAMESPACE
value: {{ .Release.Namespace }}
command:
- /bin/sh
- -c
Expand All @@ -88,6 +96,9 @@ spec:
readOnly: false
- name: monitor-data
mountPath: /data
- name: datasource
mountPath: /etc/grafana/provisioning/datasources
readOnly: false
resources:
{{ toYaml .Values.monitor.initializer.resources | indent 10 }}
containers:
Expand Down Expand Up @@ -212,11 +223,7 @@ spec:
- key: prometheus-config
path: prometheus.yml
{{- if .Values.monitor.grafana.create }}
- configMap:
name: {{ template "cluster.name" . }}-monitor
items:
- key: datasource-config
path: datasource.yaml
- emptyDir: {}
name: datasource
- configMap:
name: {{ template "cluster.name" . }}-monitor
Expand Down
4 changes: 3 additions & 1 deletion charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ monitor:
storage: 10Gi
initializer:
image: pingcap/tidb-monitor-initializer:v3.0.5
imagePullPolicy: IfNotPresent
imagePullPolicy: Always
config:
K8S_PROMETHEUS_URL: http://prometheus-k8s.monitoring.svc:9090
resources: {}
# limits:
# cpu: 50m
Expand Down
53 changes: 52 additions & 1 deletion tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,13 @@ func (oa *operatorActions) checkGrafanaData(clusterInfo *TidbClusterConfig) erro
values.Set("start", fmt.Sprintf("%d", start.Unix()))
values.Set("end", fmt.Sprintf("%d", end.Unix()))
values.Set("step", "30")
u := fmt.Sprintf("http://%s.%s.svc.cluster.local:3000/api/datasources/proxy/1/api/v1/query_range?%s", svcName, ns, values.Encode())

datasourceID, err := getDatasourceID(svcName, ns)
if err != nil {
return err
}

u := fmt.Sprintf("http://%s.%s.svc.cluster.local:3000/api/datasources/proxy/%d/api/v1/query_range?%s", svcName, ns, datasourceID, values.Encode())
req, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return err
Expand Down Expand Up @@ -1934,6 +1940,51 @@ func (oa *operatorActions) checkGrafanaData(clusterInfo *TidbClusterConfig) erro
return nil
}

func getDatasourceID(svcName, namespace string) (int, error) {
u := fmt.Sprintf("http://%s.%s.svc.cluster.local:3000/api/datasources", svcName, namespace)
req, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return 0, err
}

req.SetBasicAuth(grafanaUsername, grafanaPassword)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return 0, err
}
defer func() {
err := resp.Body.Close()
glog.Warning("close response failed", err)
}()

buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return 0, err
}

datasources := []struct {
Id int `json:"id"`
Name string `json:"name"`
}{}

if err := json.Unmarshal(buf, &datasources); err != nil {
return 0, err
}

for _, ds := range datasources {
if ds.Name == "tidb-cluster" {
return ds.Id, nil
}
}

return 0, pingcapErrors.New("not found tidb-cluster datasource")
}

func GetD(ns, tcName, databaseName, password string) string {
return fmt.Sprintf("root:%s@(%s-tidb.%s:4000)/%s?charset=utf8", password, tcName, ns, databaseName)
}

func getDSN(ns, tcName, databaseName, password string) string {
return fmt.Sprintf("root:%s@(%s-tidb.%s:4000)/%s?charset=utf8", password, tcName, ns, databaseName)
}
Expand Down

0 comments on commit 7aa642a

Please sign in to comment.