Skip to content

Commit de77b90

Browse files
committed
Add auth-type as a metric we collect
Signed-off-by: Felix Yuan <[email protected]>
1 parent 6ecb3e5 commit de77b90

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Diff for: collector.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ var (
110110
}
111111

112112
configMap = map[string]*(prometheus.Desc){
113+
"auth_type": prometheus.NewDesc(
114+
prometheus.BuildFQName(namespace, "config", "authorization_type"),
115+
"Config maximum number of client connections", []string{"method"}, nil),
113116
"max_client_conn": prometheus.NewDesc(
114117
prometheus.BuildFQName(namespace, "config", "max_client_connections"),
115118
"Config maximum number of client connections", nil, nil),
@@ -223,11 +226,14 @@ func queryShowConfig(ch chan<- prometheus.Metric, db *sql.DB, logger *slog.Logge
223226
}
224227

225228
value, err := strconv.ParseFloat(string(values), 64)
229+
labelValues := []string{}
226230
if err != nil {
227-
return fmt.Errorf("error parsing SHOW CONFIG column: %v, error: %w ", key, err)
231+
// We couldn't parse the value as a float, so treat it as a string
232+
value = 1.0
233+
labelValues = append(labelValues, string(values))
228234
}
229235
if metric, ok := configMap[key]; ok {
230-
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, value)
236+
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, value, labelValues...)
231237
} else {
232238
logger.Debug("SHOW CONFIG unknown config", "config", key)
233239
}

Diff for: collector_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func TestQueryShowConfig(t *testing.T) {
118118
expected := []MetricResult{
119119
{labels: labelMap{}, metricType: dto.MetricType_GAUGE, value: 1900},
120120
{labels: labelMap{}, metricType: dto.MetricType_GAUGE, value: 100},
121+
{labels: labelMap{"method": "md5"}, metricType: dto.MetricType_GAUGE, value: 1},
121122
}
122123
convey.Convey("Metrics comparison", t, func() {
123124
for _, expect := range expected {

0 commit comments

Comments
 (0)