refactor: Rename metrics-port to management-port (#1012)
Signed-off-by: Craig Pastro <craig.pastro@gmail.com>
This commit is contained in:
parent
deec49e99e
commit
5635e38703
|
|
@ -60,7 +60,7 @@ type SourceConfig struct {
|
||||||
// Config is the configuration structure derived from startup arguments.
|
// Config is the configuration structure derived from startup arguments.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
MetricExporter string
|
MetricExporter string
|
||||||
MetricsPort uint16
|
ManagementPort uint16
|
||||||
OtelCollectorURI string
|
OtelCollectorURI string
|
||||||
ServiceCertPath string
|
ServiceCertPath string
|
||||||
ServiceKeyPath string
|
ServiceKeyPath string
|
||||||
|
|
@ -134,7 +134,7 @@ func FromConfig(logger *logger.Logger, version string, config Config) (*Runtime,
|
||||||
Service: connectService,
|
Service: connectService,
|
||||||
ServiceConfig: service.Configuration{
|
ServiceConfig: service.Configuration{
|
||||||
Port: config.ServicePort,
|
Port: config.ServicePort,
|
||||||
MetricsPort: config.MetricsPort,
|
ManagementPort: config.ManagementPort,
|
||||||
ServiceName: svcName,
|
ServiceName: svcName,
|
||||||
KeyPath: config.ServiceKeyPath,
|
KeyPath: config.ServiceKeyPath,
|
||||||
CertPath: config.ServiceCertPath,
|
CertPath: config.ServiceCertPath,
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ func (s *ConnectService) startServer(svcConf service.Configuration) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ConnectService) startMetricsServer(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 := grpc.NewServer()
|
||||||
grpc_health_v1.RegisterHealthServer(grpc, health.NewServer())
|
grpc_health_v1.RegisterHealthServer(grpc, health.NewServer())
|
||||||
|
|
@ -230,7 +230,7 @@ func (s *ConnectService) startMetricsServer(svcConf service.Configuration) error
|
||||||
|
|
||||||
s.metricsServerMtx.Lock()
|
s.metricsServerMtx.Lock()
|
||||||
s.metricsServer = &http.Server{
|
s.metricsServer = &http.Server{
|
||||||
Addr: fmt.Sprintf(":%d", svcConf.MetricsPort),
|
Addr: fmt.Sprintf(":%d", svcConf.ManagementPort),
|
||||||
ReadHeaderTimeout: 3 * time.Second,
|
ReadHeaderTimeout: 3 * time.Second,
|
||||||
Handler: h2c.NewHandler(handler, &http2.Server{}), // we need to use h2c to support plaintext HTTP2
|
Handler: h2c.NewHandler(handler, &http2.Server{}), // we need to use h2c to support plaintext HTTP2
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ type ReadinessProbe func() bool
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
ReadinessProbe ReadinessProbe
|
ReadinessProbe ReadinessProbe
|
||||||
Port uint16
|
Port uint16
|
||||||
MetricsPort uint16
|
ManagementPort uint16
|
||||||
ServiceName string
|
ServiceName string
|
||||||
CertPath string
|
CertPath string
|
||||||
KeyPath string
|
KeyPath string
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ func (s *Server) startServer() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) startMetricsServer() 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 := grpc.NewServer()
|
||||||
grpc_health_v1.RegisterHealthServer(grpc, health.NewServer())
|
grpc_health_v1.RegisterHealthServer(grpc, health.NewServer())
|
||||||
|
|
@ -134,7 +134,7 @@ func (s *Server) startMetricsServer() error {
|
||||||
})
|
})
|
||||||
|
|
||||||
s.metricsServer = &http.Server{
|
s.metricsServer = &http.Server{
|
||||||
Addr: fmt.Sprintf(":%d", s.config.MetricsPort),
|
Addr: fmt.Sprintf(":%d", s.config.ManagementPort),
|
||||||
ReadHeaderTimeout: 3 * time.Second,
|
ReadHeaderTimeout: 3 * time.Second,
|
||||||
Handler: h2c.NewHandler(handler, &http2.Server{}), // we need to use h2c to support plaintext HTTP2
|
Handler: h2c.NewHandler(handler, &http2.Server{}), // we need to use h2c to support plaintext HTTP2
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ flagd start [flags]
|
||||||
-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")
|
-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
|
-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
|
-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.
|
-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)
|
-p, --port int32 Port to listen on (default 8013)
|
||||||
-c, --server-cert-path string Server side tls certificate path
|
-c, --server-cert-path string Server side tls certificate path
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@ description: monitoring and telemetry flagd and flagd providers
|
||||||
|
|
||||||
Flagd exposes HTTP liveness and readiness probes.
|
Flagd exposes HTTP liveness and readiness probes.
|
||||||
These probes can be used for K8s deployments.
|
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>
|
- Liveness: <http://localhost:8014/healthz>
|
||||||
- Readiness: <http://localhost:8014/readyz>
|
- Readiness: <http://localhost:8014/readyz>
|
||||||
|
|
||||||
### gRPC
|
### 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
|
### Definition of Liveness
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,9 @@ sources:
|
||||||
Table given below is non-exhaustive list of overriding options,
|
Table given below is non-exhaustive list of overriding options,
|
||||||
|
|
||||||
| Configuration | Explanation | Default |
|
| Configuration | Explanation | Default |
|
||||||
|---------------|-------------------------------|----------------------------|
|
|----------------|-------------------------------|----------------------------|
|
||||||
| port | Flag evaluation endpoint port | 8013 |
|
| port | Flag evaluation endpoint port | 8013 |
|
||||||
| metricsPort | Metrics port | 8014 |
|
| managementPort | Management port | 8014 |
|
||||||
| evaluator | Evaluator to use | json |
|
| evaluator | Evaluator to use | json |
|
||||||
| image | flagD image | ghcr.io/open-feature/flagd |
|
| image | flagD image | ghcr.io/open-feature/flagd |
|
||||||
| tag | flagD image tag | Latest tag |
|
| tag | flagD image tag | Latest tag |
|
||||||
|
|
@ -95,7 +95,7 @@ kind: FeatureFlagSource
|
||||||
metadata:
|
metadata:
|
||||||
name: flag-source-sample
|
name: flag-source-sample
|
||||||
spec:
|
spec:
|
||||||
metricsPort: 8080
|
managementPort: 8080
|
||||||
Port: 80
|
Port: 80
|
||||||
evaluator: json
|
evaluator: json
|
||||||
image: my-custom-sidecar-image
|
image: my-custom-sidecar-image
|
||||||
|
|
@ -142,7 +142,7 @@ kind: FeatureFlagSource
|
||||||
metadata:
|
metadata:
|
||||||
name: config-A
|
name: config-A
|
||||||
spec:
|
spec:
|
||||||
metricsPort: 8080
|
managementPort: 8080
|
||||||
tag: latest
|
tag: latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -162,7 +162,7 @@ Results in the following configuration:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
spec:
|
spec:
|
||||||
metricsPort: 8080
|
managementPort: 8080
|
||||||
port: 8000
|
port: 8000
|
||||||
tag: main
|
tag: main
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,10 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
logFormatFlagName = "log-format"
|
logFormatFlagName = "log-format"
|
||||||
metricsPortFlagName = "metrics-port"
|
metricsPortFlagName = "metrics-port" // deprecated
|
||||||
|
managementPortFlagName = "management-port"
|
||||||
portFlagName = "port"
|
portFlagName = "port"
|
||||||
|
defaultManagementPort = 8016
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -32,11 +34,13 @@ func init() {
|
||||||
|
|
||||||
// allows environment variables to use _ instead of -
|
// allows environment variables to use _ instead of -
|
||||||
flags.Int32P(portFlagName, "p", 8015, "Port to listen on")
|
flags.Int32P(portFlagName, "p", 8015, "Port to listen on")
|
||||||
flags.Int32P(metricsPortFlagName, "m", 8016, "Metrics port to listen on")
|
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")
|
flags.StringP(logFormatFlagName, "z", "console", "Set the logging format, e.g. console or json")
|
||||||
|
|
||||||
_ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName))
|
_ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName))
|
||||||
_ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName))
|
_ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName))
|
||||||
|
_ = viper.BindPFlag(managementPortFlagName, flags.Lookup(managementPortFlagName))
|
||||||
_ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName))
|
_ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,14 +64,29 @@ var startCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
logger := logger.NewLogger(l, Debug)
|
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)
|
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
syncStore := syncStore.NewSyncStore(ctx, logger)
|
syncStore := syncStore.NewSyncStore(ctx, logger)
|
||||||
s := syncServer.NewServer(logger, syncStore)
|
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{
|
cfg := service.Configuration{
|
||||||
ReadinessProbe: func() bool { return true },
|
ReadinessProbe: func() bool { return true },
|
||||||
Port: viper.GetUint16(portFlagName),
|
Port: viper.GetUint16(portFlagName),
|
||||||
MetricsPort: viper.GetUint16(metricsPortFlagName),
|
ManagementPort: managementPort,
|
||||||
}
|
}
|
||||||
|
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ const (
|
||||||
evaluatorFlagName = "evaluator"
|
evaluatorFlagName = "evaluator"
|
||||||
logFormatFlagName = "log-format"
|
logFormatFlagName = "log-format"
|
||||||
metricsExporter = "metrics-exporter"
|
metricsExporter = "metrics-exporter"
|
||||||
metricsPortFlagName = "metrics-port"
|
metricsPortFlagName = "metrics-port" // deprecated
|
||||||
|
managementPortFlagName = "management-port"
|
||||||
otelCollectorURI = "otel-collector-uri"
|
otelCollectorURI = "otel-collector-uri"
|
||||||
portFlagName = "port"
|
portFlagName = "port"
|
||||||
providerArgsFlagName = "sync-provider-args"
|
providerArgsFlagName = "sync-provider-args"
|
||||||
|
|
@ -32,7 +33,7 @@ const (
|
||||||
docsLinkConfiguration = "https://flagd.dev/reference/flagd-cli/flagd_start/"
|
docsLinkConfiguration = "https://flagd.dev/reference/flagd-cli/flagd_start/"
|
||||||
|
|
||||||
defaultServicePort = 8013
|
defaultServicePort = 8013
|
||||||
defaultMetricsPort = 8014
|
defaultManagementPort = 8014
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -41,7 +42,8 @@ func init() {
|
||||||
// allows environment variables to use _ instead of -
|
// allows environment variables to use _ instead of -
|
||||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) // sync-provider-args becomes SYNC_PROVIDER_ARGS
|
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) // sync-provider-args becomes SYNC_PROVIDER_ARGS
|
||||||
viper.SetEnvPrefix("FLAGD") // port becomes FLAGD_PORT
|
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.Int32P(portFlagName, "p", defaultServicePort, "Port to listen on")
|
||||||
flags.StringP(socketPathFlagName, "d", "", "Flagd socket path. "+
|
flags.StringP(socketPathFlagName, "d", "", "Flagd socket path. "+
|
||||||
"With grpc the service will become available on this address. "+
|
"With grpc the service will become available on this address. "+
|
||||||
|
|
@ -83,6 +85,7 @@ func init() {
|
||||||
_ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName))
|
_ = viper.BindPFlag(logFormatFlagName, flags.Lookup(logFormatFlagName))
|
||||||
_ = viper.BindPFlag(metricsExporter, flags.Lookup(metricsExporter))
|
_ = viper.BindPFlag(metricsExporter, flags.Lookup(metricsExporter))
|
||||||
_ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName))
|
_ = viper.BindPFlag(metricsPortFlagName, flags.Lookup(metricsPortFlagName))
|
||||||
|
_ = viper.BindPFlag(managementPortFlagName, flags.Lookup(managementPortFlagName))
|
||||||
_ = viper.BindPFlag(otelCollectorURI, flags.Lookup(otelCollectorURI))
|
_ = viper.BindPFlag(otelCollectorURI, flags.Lookup(otelCollectorURI))
|
||||||
_ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName))
|
_ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName))
|
||||||
_ = viper.BindPFlag(providerArgsFlagName, flags.Lookup(providerArgsFlagName))
|
_ = viper.BindPFlag(providerArgsFlagName, flags.Lookup(providerArgsFlagName))
|
||||||
|
|
@ -132,6 +135,11 @@ var startCmd = &cobra.Command{
|
||||||
docsLinkConfiguration)
|
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))
|
syncProviders, err := runtime.ParseSyncProviderURIs(viper.GetStringSlice(uriFlagName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
@ -151,16 +159,21 @@ var startCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
syncProviders = append(syncProviders, syncProvidersFromConfig...)
|
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 -----------------------------------------------------------
|
// Build Runtime -----------------------------------------------------------
|
||||||
rt, err := runtime.FromConfig(logger, Version, runtime.Config{
|
rt, err := runtime.FromConfig(logger, Version, runtime.Config{
|
||||||
CORS: viper.GetStringSlice(corsFlagName),
|
CORS: viper.GetStringSlice(corsFlagName),
|
||||||
MetricExporter: viper.GetString(metricsExporter),
|
MetricExporter: viper.GetString(metricsExporter),
|
||||||
MetricsPort: getPortValueOrDefault(
|
ManagementPort: managementPort,
|
||||||
metricsPortFlagName,
|
|
||||||
viper.GetUint16(metricsPortFlagName),
|
|
||||||
defaultMetricsPort,
|
|
||||||
rtLogger,
|
|
||||||
),
|
|
||||||
OtelCollectorURI: viper.GetString(otelCollectorURI),
|
OtelCollectorURI: viper.GetString(otelCollectorURI),
|
||||||
ServiceCertPath: viper.GetString(serverCertPathFlagName),
|
ServiceCertPath: viper.GetString(serverCertPathFlagName),
|
||||||
ServiceKeyPath: viper.GetString(serverKeyPathFlagName),
|
ServiceKeyPath: viper.GetString(serverKeyPathFlagName),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue