fix: byHost realTime metrics API (#17681)

This commit is contained in:
jiuker 2023-07-19 14:50:30 +08:00 committed by GitHub
parent 6426b74770
commit a99cd825ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 3 deletions

View File

@ -19,6 +19,7 @@ package cmd
import ( import (
"context" "context"
"net/http"
"time" "time"
"github.com/minio/madmin-go/v3" "github.com/minio/madmin-go/v3"
@ -38,8 +39,14 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
return return
} }
byHostName := globalMinioAddr
if len(opts.hosts) > 0 { if len(opts.hosts) > 0 {
if _, ok := opts.hosts[globalMinioAddr]; !ok { server := getLocalServerProperty(globalEndpoints, &http.Request{
Host: globalLocalNodeName,
})
if _, ok := opts.hosts[server.Endpoint]; ok {
byHostName = server.Endpoint
} else {
return return
} }
} }
@ -85,8 +92,8 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
// Add types... // Add types...
// ByHost is a shallow reference, so careful about sharing. // ByHost is a shallow reference, so careful about sharing.
m.ByHost = map[string]madmin.Metrics{globalMinioAddr: m.Aggregated} m.ByHost = map[string]madmin.Metrics{byHostName: m.Aggregated}
m.Hosts = append(m.Hosts, globalMinioAddr) m.Hosts = append(m.Hosts, byHostName)
return m return m
} }

View File

@ -214,6 +214,9 @@ func (client *peerRESTClient) GetMetrics(ctx context.Context, t madmin.MetricTyp
for disk := range opts.disks { for disk := range opts.disks {
values.Set(peerRESTDisk, disk) values.Set(peerRESTDisk, disk)
} }
for host := range opts.hosts {
values.Add(peerRESTHost, host)
}
values.Set(peerRESTJobID, opts.jobID) values.Set(peerRESTJobID, opts.jobID)
values.Set(peerRESTDepID, opts.depID) values.Set(peerRESTDepID, opts.depID)

View File

@ -99,6 +99,7 @@ const (
peerRESTStorageClass = "storage-class" peerRESTStorageClass = "storage-class"
peerRESTMetricsTypes = "types" peerRESTMetricsTypes = "types"
peerRESTDisk = "disk" peerRESTDisk = "disk"
peerRESTHost = "host"
peerRESTJobID = "job-id" peerRESTJobID = "job-id"
peerRESTDepID = "depID" peerRESTDepID = "depID"
peerRESTStartRebalance = "start-rebalance" peerRESTStartRebalance = "start-rebalance"

View File

@ -453,6 +453,12 @@ func (s *peerRESTServer) GetMetricsHandler(w http.ResponseWriter, r *http.Reques
for _, disk := range r.Form[peerRESTDisk] { for _, disk := range r.Form[peerRESTDisk] {
diskMap[disk] = struct{}{} diskMap[disk] = struct{}{}
} }
hostMap := make(map[string]struct{})
for _, host := range r.Form[peerRESTHost] {
hostMap[host] = struct{}{}
}
jobID := r.Form.Get(peerRESTJobID) jobID := r.Form.Get(peerRESTJobID)
depID := r.Form.Get(peerRESTDepID) depID := r.Form.Get(peerRESTDepID)
@ -461,6 +467,7 @@ func (s *peerRESTServer) GetMetricsHandler(w http.ResponseWriter, r *http.Reques
info := collectLocalMetrics(types, collectMetricsOpts{ info := collectLocalMetrics(types, collectMetricsOpts{
disks: diskMap, disks: diskMap,
hosts: hostMap,
jobID: jobID, jobID: jobID,
depID: depID, depID: depID,
}) })