Skip to content

Commit 4f63e97

Browse files
feat(serve): add short flag and env var for metrics port (#1616)
Add short flag -m for --metrics-port to improve discoverability. Add K8SGPT_METRICS_PORT environment variable support, consistent with other K8SGPT_* environment variables. This helps users who encounter port conflicts on the default metrics port (8081) when running k8sgpt serve with --mcp or other configurations. Signed-off-by: Three Foxes (in a Trenchcoat) <threefoxes53235@gmail.com> Signed-off-by: Three Foxes (in a Trenchcoat) <threefoxesyes3inatrenchcoat@gmail.com>
1 parent a56e478 commit 4f63e97

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

cmd/serve/serve.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ var ServeCmd = &cobra.Command{
203203
}()
204204
}
205205

206+
// Allow metrics port to be overridden by environment variable
207+
if envMetricsPort := os.Getenv("K8SGPT_METRICS_PORT"); envMetricsPort != "" && !cmd.Flags().Changed("metrics-port") {
208+
metricsPort = envMetricsPort
209+
}
210+
206211
server := k8sgptserver.Config{
207212
Backend: aiProvider.Name,
208213
Port: port,
@@ -234,7 +239,7 @@ var ServeCmd = &cobra.Command{
234239
func init() {
235240
// add flag for backend
236241
ServeCmd.Flags().StringVarP(&port, "port", "p", "8080", "Port to run the server on")
237-
ServeCmd.Flags().StringVarP(&metricsPort, "metrics-port", "", "8081", "Port to run the metrics-server on")
242+
ServeCmd.Flags().StringVarP(&metricsPort, "metrics-port", "m", "8081", "Port to run the metrics-server on (env: K8SGPT_METRICS_PORT)")
238243
ServeCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider")
239244
ServeCmd.Flags().BoolVarP(&enableHttp, "http", "", false, "Enable REST/http using gppc-gateway")
240245
ServeCmd.Flags().BoolVarP(&enableMCP, "mcp", "", false, "Enable Mission Control Protocol server")

0 commit comments

Comments
 (0)