Skip to content

Commit

Permalink
optimize MetricsBindAddress to MetricsBindPort
Browse files Browse the repository at this point in the history
Signed-off-by: phoenixwu0229 <[email protected]>
  • Loading branch information
wutong6 committed Jan 9, 2025
1 parent d04fc8b commit 62ebd7f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion charts/hami/templates/scheduler/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ spec:
- --cert_file=/tls/tls.crt
- --key_file=/tls/tls.key
- --scheduler-name={{ .Values.schedulerName }}
- --metrics-bind-address={{ .Values.scheduler.metricsBindAddress }}
- --metrics-bind-port={{ .Values.scheduler.metricsBindPort }}
- --node-scheduler-policy={{ .Values.scheduler.defaultSchedulerPolicy.nodeSchedulerPolicy }}
- --gpu-scheduler-policy={{ .Values.scheduler.defaultSchedulerPolicy.gpuSchedulerPolicy }}
- --device-config-file=/device-config.yaml
Expand Down
2 changes: 1 addition & 1 deletion charts/hami/templates/scheduler/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
protocol: TCP
- name: monitor
port: {{ .Values.scheduler.service.monitorPort }}
targetPort: 9395
targetPort: {{ .Values.scheduler.metricsBindPort }}
nodePort: {{ .Values.scheduler.service.monitorPort }}
protocol: TCP
selector:
Expand Down
2 changes: 1 addition & 1 deletion charts/hami/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ scheduler:
defaultSchedulerPolicy:
nodeSchedulerPolicy: binpack
gpuSchedulerPolicy: spread
metricsBindAddress: ":9395"
metricsBindPort: 9395
livenessProbe: false
leaderElect: true
kubeScheduler:
Expand Down
4 changes: 2 additions & 2 deletions cmd/scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func init() {
rootCmd.Flags().Int32Var(&config.DefaultResourceNum, "default-gpu", 1, "default gpu to allocate")
rootCmd.Flags().StringVar(&config.NodeSchedulerPolicy, "node-scheduler-policy", util.NodeSchedulerPolicyBinpack.String(), "node scheduler policy")
rootCmd.Flags().StringVar(&config.GPUSchedulerPolicy, "gpu-scheduler-policy", util.GPUSchedulerPolicySpread.String(), "GPU scheduler policy")
rootCmd.Flags().StringVar(&config.MetricsBindAddress, "metrics-bind-address", ":9395", "The TCP address that the scheduler should bind to for serving prometheus metrics(e.g. 127.0.0.1:9395, :9395)")
rootCmd.Flags().StringVar(&config.MetricsBindPort, "metrics-bind-port", ":9395", "The port that the scheduler should bind to for serving prometheus metrics(e.g. 9395)")
rootCmd.Flags().StringToStringVar(&config.NodeLabelSelector, "node-label-selector", nil, "key=value pairs separated by commas")
rootCmd.PersistentFlags().AddGoFlagSet(device.GlobalFlagSet())
rootCmd.AddCommand(version.VersionCmd)
Expand All @@ -76,7 +76,7 @@ func start() {

// start monitor metrics
go sher.RegisterFromNodeAnnotations()
go initMetrics(config.MetricsBindAddress)
go initMetrics(config.MetricsBindPort)

// start http server
router := httprouter.New()
Expand Down
7 changes: 5 additions & 2 deletions cmd/scheduler/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"
"log"
"net"
"net/http"
"strings"

Expand Down Expand Up @@ -246,7 +247,7 @@ func NewClusterManager(zone string, reg prometheus.Registerer) *ClusterManager {
return c
}

func initMetrics(bindAddress string) {
func initMetrics(bindPort string) {
// Since we are dealing with custom Collector implementations, it might
// be a good idea to try it out with a pedantic registry.
klog.Info("Initializing metrics for scheduler")
Expand All @@ -257,5 +258,7 @@ func initMetrics(bindAddress string) {
NewClusterManager("vGPU", reg)

http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))
log.Fatal(http.ListenAndServe(bindAddress, nil))
addr := net.JoinHostPort("0.0.0.0", bindPort)
klog.Infof("Starting metrics server on %s", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}
6 changes: 3 additions & 3 deletions pkg/scheduler/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package config
import "github.com/Project-HAMi/HAMi/pkg/util"

var (
HTTPBind string
SchedulerName string
MetricsBindAddress string
HTTPBind string
SchedulerName string
MetricsBindPort string

DefaultMem int32
DefaultCores int32
Expand Down

0 comments on commit 62ebd7f

Please sign in to comment.