refactor: Rename metrics-port to management-port (#1012)

Signed-off-by: Craig Pastro <craig.pastro@gmail.com>
This commit is contained in:
Craig Pastro 2023-11-16 12:08:57 -08:00 committed by GitHub
parent deec49e99e
commit 5635e38703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 48 deletions

View File

@ -60,7 +60,7 @@ type SourceConfig struct {
// Config is the configuration structure derived from startup arguments.
type Config struct {
MetricExporter string
MetricsPort uint16
ManagementPort uint16
OtelCollectorURI string
ServiceCertPath string
ServiceKeyPath string
@ -133,14 +133,14 @@ func FromConfig(logger *logger.Logger, version string, config Config) (*Runtime,
Evaluator: evaluator,
Service: connectService,
ServiceConfig: service.Configuration{
Port: config.ServicePort,
MetricsPort: config.MetricsPort,
ServiceName: svcName,
KeyPath: config.ServiceKeyPath,
CertPath: config.ServiceCertPath,
SocketPath: config.ServiceSocketPath,
CORS: config.CORS,
Options: telemetry.BuildConnectOptions(telCfg),
Port: config.ServicePort,
ManagementPort: config.ManagementPort,
ServiceName: svcName,
KeyPath: config.ServiceKeyPath,
CertPath: config.ServiceCertPath,
SocketPath: config.ServiceSocketPath,
CORS: config.CORS,
Options: telemetry.BuildConnectOptions(telCfg),
},
SyncImpl: iSyncs,
}, nil

View File

@ -200,7 +200,7 @@ func (s *ConnectService) startServer(svcConf service.Configuration) error {
}
func (s *ConnectService) startMetricsServer(svcConf service.Configuration) error {
s.logger.Info(fmt.Sprintf("metrics and probes listening at %d", svcConf.MetricsPort))
s.logger.Info(fmt.Sprintf("metrics and probes listening at %d", svcConf.ManagementPort))
grpc := grpc.NewServer()
grpc_health_v1.RegisterHealthServer(grpc, health.NewServer())
@ -230,7 +230,7 @@ func (s *ConnectService) startMetricsServer(svcConf service.Configuration) error
s.metricsServerMtx.Lock()
s.metricsServer = &http.Server{
Addr: fmt.Sprintf(":%d", svcConf.MetricsPort),
Addr: fmt.Sprintf(":%d", svcConf.ManagementPort),
ReadHeaderTimeout: 3 * time.Second,
Handler: h2c.NewHandler(handler, &http2.Server{}), // we need to use h2c to support plaintext HTTP2
}

View File

@ -25,7 +25,7 @@ type ReadinessProbe func() bool
type Configuration struct {
ReadinessProbe ReadinessProbe
Port uint16
MetricsPort uint16
ManagementPort uint16
ServiceName string
CertPath string
KeyPath string

View File

@ -105,7 +105,7 @@ func (s *Server) startServer() error {
}
func (s *Server) startMetricsServer() error {
s.Logger.Info(fmt.Sprintf("binding metrics to %d", s.config.MetricsPort))
s.Logger.Info(fmt.Sprintf("binding metrics to %d", s.config.ManagementPort))
grpc := grpc.NewServer()
grpc_health_v1.RegisterHealthServer(grpc, health.NewServer())
@ -134,7 +134,7 @@ func (s *Server) startMetricsServer() error {
})
s.metricsServer = &http.Server{
Addr: fmt.Sprintf(":%d", s.config.MetricsPort),
Addr: fmt.Sprintf(":%d", s.config.ManagementPort),
ReadHeaderTimeout: 3 * time.Second,
Handler: h2c.NewHandler(handler, &http2.Server{}), // we need to use h2c to support plaintext HTTP2
}

View File

@ -15,9 +15,10 @@ flagd start [flags]
-C, --cors-origin strings CORS allowed origins, * will allow all origins
-e, --evaluator string DEPRECATED: Set an evaluator e.g. json, yaml/yml.Please note that yaml/yml and json evaluations work the same (yaml/yml files are converted to json internally) (default "json")
-h, --help help for start
-z, --log-format string Set the logging format, e.g. console or json (default "console")
-z, --log-format string Set the logging format, e.g. console or json (default "console")
-m, --management-port int32 Port for management operations (default 8014)
-t, --metrics-exporter string Set the metrics exporter. Default(if unset) is Prometheus. Can be override to otel - OpenTelemetry metric exporter. Overriding to otel require otelCollectorURI to be present
-m, --metrics-port int32 Port to serve metrics on (default 8014)
--metrics-port int32 DEPRECATED: Superseded by --management-port. (default 8014)
-o, --otel-collector-uri string Set the grpc URI of the OpenTelemetry collector for flagd runtime. If unset, the collector setup will be ignored and traces will not be exported.
-p, --port int32 Port to listen on (default 8013)
-c, --server-cert-path string Server side tls certificate path

View File

@ -10,14 +10,14 @@ description: monitoring and telemetry flagd and flagd providers
Flagd exposes HTTP liveness and readiness probes.
These probes can be used for K8s deployments.
With default start-up configurations, these probes are exposed on the metrics port (default: 8014) at the following URLs,
With default start-up configurations, these probes are exposed on the management port (default: 8014) at the following URLs,
- Liveness: <http://localhost:8014/healthz>
- Readiness: <http://localhost:8014/readyz>
### gRPC
Flagd exposes a [standard gRPC liveness check](https://github.com/grpc/grpc/blob/master/doc/health-checking.md) on the metrics port (default: 8014).
Flagd exposes a [standard gRPC liveness check](https://github.com/grpc/grpc/blob/master/doc/health-checking.md) on the management port (default: 8014).
### Definition of Liveness

View File

@ -63,14 +63,14 @@ sources:
`FeatureFlagSource` further allows to provide configurations to the injected flagd sidecar.
Table given below is non-exhaustive list of overriding options,
| Configuration | Explanation | Default |
|---------------|-------------------------------|----------------------------|
| port | Flag evaluation endpoint port | 8013 |
| metricsPort | Metrics port | 8014 |
| evaluator | Evaluator to use | json |
| image | flagD image | ghcr.io/open-feature/flagd |
| tag | flagD image tag | Latest tag |
| probesEnabled | Enable/Disable health probes | true |
| Configuration | Explanation | Default |
|----------------|-------------------------------|----------------------------|
| port | Flag evaluation endpoint port | 8013 |
| managementPort | Management port | 8014 |
| evaluator | Evaluator to use | json |
| image | flagD image | ghcr.io/open-feature/flagd |
| tag | flagD image tag | Latest tag |
| probesEnabled | Enable/Disable health probes | true |
## Merging of configurations
@ -95,7 +95,7 @@ kind: FeatureFlagSource
metadata:
name: flag-source-sample
spec:
metricsPort: 8080
managementPort: 8080
Port: 80
evaluator: json
image: my-custom-sidecar-image
@ -142,7 +142,7 @@ kind: FeatureFlagSource
metadata:
name: config-A
spec:
metricsPort: 8080
managementPort: 8080
tag: latest
```
@ -162,7 +162,7 @@ Results in the following configuration:
```yaml
spec:
metricsPort: 8080
managementPort: 8080
port: 8000
tag: main
```

View File

@ -22,9 +22,11 @@ import (
// start
const (
logFormatFlagName = "log-format"
metricsPortFlagName = "metrics-port"
portFlagName = "port"
logFormatFlagName = "log-format"
metricsPortFlagName = "metrics-port" // deprecated
managementPortFlagName = "management-port"
portFlagName = "port"
defaultManagementPort = 8016
)
func init() {
@ -32,11 +34,13 @@ func init() {
// allows environment variables to use _ instead of -
flags.Int32P(portFlagName, "p", 8015, "Port to listen on")
flags.Int32P(metricsPortFlagName, "m", 8016, "Metrics port to listen on")
flags.StringP(logFormatFlagName, "z", "console", "Set the logging format, e.g. console or json ")
flags.Int32(metricsPortFlagName, defaultManagementPort, "DEPRECATED: Superseded by --management-port.")
flags.Int32P(managementPortFlagName, "m", defaultManagementPort, "Management port")
flags.StringP(logFormatFlagName, "z", "console", "Set the logging format, e.g. console or json")
_ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName))
_ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName))
_ = viper.BindPFlag(managementPortFlagName, flags.Lookup(managementPortFlagName))
_ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName))
}
@ -60,14 +64,29 @@ var startCmd = &cobra.Command{
}
logger := logger.NewLogger(l, Debug)
if viper.GetUint16(metricsPortFlagName) != defaultManagementPort {
logger.Warn("DEPRECATED: The --metrics-port flag has been deprecated and is superseded by --management-port.")
}
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
syncStore := syncStore.NewSyncStore(ctx, logger)
s := syncServer.NewServer(logger, syncStore)
// If --management-port is set use that value. If not and
// --metrics-port is set use that value. Otherwise use the default
// value.
managementPort := uint16(defaultManagementPort)
if viper.GetUint16(managementPortFlagName) != defaultManagementPort {
managementPort = viper.GetUint16(managementPortFlagName)
} else if viper.GetUint16(metricsPortFlagName) != defaultManagementPort {
managementPort = viper.GetUint16(metricsPortFlagName)
}
cfg := service.Configuration{
ReadinessProbe: func() bool { return true },
Port: viper.GetUint16(portFlagName),
MetricsPort: viper.GetUint16(metricsPortFlagName),
ManagementPort: managementPort,
}
errChan := make(chan error, 1)

View File

@ -19,7 +19,8 @@ const (
evaluatorFlagName = "evaluator"
logFormatFlagName = "log-format"
metricsExporter = "metrics-exporter"
metricsPortFlagName = "metrics-port"
metricsPortFlagName = "metrics-port" // deprecated
managementPortFlagName = "management-port"
otelCollectorURI = "otel-collector-uri"
portFlagName = "port"
providerArgsFlagName = "sync-provider-args"
@ -31,8 +32,8 @@ const (
uriFlagName = "uri"
docsLinkConfiguration = "https://flagd.dev/reference/flagd-cli/flagd_start/"
defaultServicePort = 8013
defaultMetricsPort = 8014
defaultServicePort = 8013
defaultManagementPort = 8014
)
func init() {
@ -41,7 +42,8 @@ func init() {
// allows environment variables to use _ instead of -
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) // sync-provider-args becomes SYNC_PROVIDER_ARGS
viper.SetEnvPrefix("FLAGD") // port becomes FLAGD_PORT
flags.Int32P(metricsPortFlagName, "m", defaultMetricsPort, "Port to serve metrics on")
flags.Int32(metricsPortFlagName, defaultManagementPort, "DEPRECATED: Superseded by --management-port.")
flags.Int32P(managementPortFlagName, "m", defaultManagementPort, "Port for management operations")
flags.Int32P(portFlagName, "p", defaultServicePort, "Port to listen on")
flags.StringP(socketPathFlagName, "d", "", "Flagd socket path. "+
"With grpc the service will become available on this address. "+
@ -70,7 +72,7 @@ func init() {
"2 required fields, uri (string) and provider (string). Documentation for this object: "+
"https://github.com/open-feature/flagd/blob/main/docs/configuration/configuration.md#sync-provider-customisation",
)
flags.StringP(logFormatFlagName, "z", "console", "Set the logging format, e.g. console or json ")
flags.StringP(logFormatFlagName, "z", "console", "Set the logging format, e.g. console or json")
flags.StringP(metricsExporter, "t", "", "Set the metrics exporter. Default(if unset) is Prometheus."+
" Can be override to otel - OpenTelemetry metric exporter. Overriding to otel require otelCollectorURI to"+
" be present")
@ -83,6 +85,7 @@ func init() {
_ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName))
_ = viper.BindPFlag(metricsExporter, flags.Lookup(metricsExporter))
_ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName))
_ = viper.BindPFlag(managementPortFlagName, flags.Lookup(managementPortFlagName))
_ = viper.BindPFlag(otelCollectorURI, flags.Lookup(otelCollectorURI))
_ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName))
_ = viper.BindPFlag(providerArgsFlagName, flags.Lookup(providerArgsFlagName))
@ -132,6 +135,11 @@ var startCmd = &cobra.Command{
docsLinkConfiguration)
}
if viper.GetUint16(metricsPortFlagName) != defaultManagementPort {
rtLogger.Warn("DEPRECATED: The --metrics-port flag has been deprecated, see: " +
docsLinkConfiguration)
}
syncProviders, err := runtime.ParseSyncProviderURIs(viper.GetStringSlice(uriFlagName))
if err != nil {
log.Fatal(err)
@ -151,16 +159,21 @@ var startCmd = &cobra.Command{
}
syncProviders = append(syncProviders, syncProvidersFromConfig...)
// If --management-port is set use that value. If not and
// --metrics-port is set use that value. Otherwise use the default
// value.
managementPort := uint16(defaultManagementPort)
if viper.GetUint16(managementPortFlagName) != defaultManagementPort {
managementPort = viper.GetUint16(managementPortFlagName)
} else if viper.GetUint16(metricsPortFlagName) != defaultManagementPort {
managementPort = viper.GetUint16(metricsPortFlagName)
}
// Build Runtime -----------------------------------------------------------
rt, err := runtime.FromConfig(logger, Version, runtime.Config{
CORS: viper.GetStringSlice(corsFlagName),
MetricExporter: viper.GetString(metricsExporter),
MetricsPort: getPortValueOrDefault(
metricsPortFlagName,
viper.GetUint16(metricsPortFlagName),
defaultMetricsPort,
rtLogger,
),
CORS: viper.GetStringSlice(corsFlagName),
MetricExporter: viper.GetString(metricsExporter),
ManagementPort: managementPort,
OtelCollectorURI: viper.GetString(otelCollectorURI),
ServiceCertPath: viper.GetString(serverCertPathFlagName),
ServiceKeyPath: viper.GetString(serverKeyPathFlagName),