fix ipv6 startup fail #81870 (#87108)

* fix ipv6 startup fail #81870

* ipv6 startup fail

* ipv6 startup fail
This commit is contained in:
jackyin 2024-05-07 02:17:03 +08:00 committed by GitHub
parent fae9bfccb2
commit ba8b4bde3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -11,9 +11,12 @@ import (
"github.com/grafana/grafana/pkg/setting"
)
func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o *options.Options) {
func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o *options.Options) error {
defaultLogLevel := 0
ip := net.ParseIP(cfg.HTTPAddr)
if ip == nil {
return fmt.Errorf("invalid IP address: %s", cfg.HTTPAddr)
}
apiURL := cfg.AppURL
port, err := strconv.Atoi(cfg.HTTPPort)
if err != nil {
@ -27,7 +30,7 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o
apiURL = fmt.Sprintf("https://%s:%d", ip, port)
}
host := fmt.Sprintf("%s:%d", ip, port)
host := net.JoinHostPort(cfg.HTTPAddr, strconv.Itoa(port))
apiserverCfg := cfg.SectionWithEnvOverrides("grafana-apiserver")
@ -54,4 +57,5 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o
o.ExtraOptions.ExternalAddress = host
o.ExtraOptions.APIURL = apiURL
o.ExtraOptions.Verbosity = apiserverCfg.Key("log_level").MustInt(defaultLogLevel)
return nil
}

View File

@ -212,7 +212,10 @@ func (s *service) start(ctx context.Context) error {
}
o := grafanaapiserveroptions.NewOptions(Codecs.LegacyCodec(groupVersions...))
applyGrafanaConfig(s.cfg, s.features, o)
err := applyGrafanaConfig(s.cfg, s.features, o)
if err != nil {
return err
}
if errs := o.Validate(); len(errs) != 0 {
// TODO: handle multiple errors
@ -286,7 +289,7 @@ func (s *service) start(ctx context.Context) error {
}
// Add OpenAPI specs for each group+version
err := builder.SetupConfig(
err = builder.SetupConfig(
Scheme,
serverConfig,
builders,