Skip to content
This repository was archived by the owner on Jul 28, 2026. It is now read-only.

pkg/server: replace pkg/util/server with pkg/server - #1476

Merged
rfratto merged 12 commits into
grafana-cold-storage:mainfrom
rfratto:server-block-field-deprecation
Mar 10, 2022
Merged

pkg/server: replace pkg/util/server with pkg/server#1476
rfratto merged 12 commits into
grafana-cold-storage:mainfrom
rfratto:server-block-field-deprecation

Conversation

@rfratto

@rfratto rfratto commented Mar 9, 2022

Copy link
Copy Markdown
Contributor

pkg/server is a new top-level subsystem which exposes an HTTP and gRPC server. It was forked off of weaveworks/common/server with direct support for reloading settings we wish to keep as dynamic.

The following YAML fields are intended to be dynamically updatable:

  • server.log_level
  • server.log_format
  • server.http_tls_config
  • server.grpc_tls_config

Other fields are intended to be static and should only be set via command line flag. Their YAML counterparts are now DEPRECATED and will be removed in v0.26.0. As of this commit, reloading the config file will fail if a non-dynamic field has changed in the server block.

Closes #1336.
Closes #1156.

Flag changes

Many flag names corresponding to the server have changed. These will be documented as breaking changes over previous versions of the agent.

The following flags are NEW:

  • -server.http.enable-tls
  • -server.grpc.enable-tls
  • -server.http.address
  • -server.grpc.address

The -server.*-enable-tls flags must now be passed to enable TLS for HTTP and gRPC respectively. This is a change from the previous behavior of dynamically enabling TLS when a certificate pair is provided.

-server.http.address and -server.grpc.address are intended to be host:port addresses on which to listen for HTTP and gRPC traffic. They replace the -server.*-listen-address and -server.*-listen-port flags.

The following flags have been RENAMED:

  • -server.log.source-ips.enabled (renamed from -server.log-source-ips-enabled)
  • -server.log.source-ips.header (renamed from -server.log-source-ips-header)
  • -server.log.source-ips.regex (renamed from -server.log-source-ips-regex)
  • -server.http.network (renamed from -server.http-listen-network)
  • -server.http.conn-limit (renamed from -server.http-conn-limit)
  • -server.http.read-timeout (renamed from -server.http-read-timeout)
  • -server.http.write-timeout (renamed from -server.http-write-timeout)
  • -server.http.idle-timeout (renamed from -server.http-idle-timeout)
  • -server.grpc.network (renamed from -server.grpc-listen-network)
  • -server.grpc.conn-limit (renamed from -server.grpc-conn-limit)
  • -server.grpc.max-recv-msg-size-bytes (renamed from -server.grpc-max-recv-msg-size-bytes)
  • -server.grpc.max-send-msg-size-bytes (renamed from -server.grpc-max-send-msg-size-bytes)
  • -server.grpc.max-concurrent-streams (renamed from -server.grpc-max-concurrent-streams)

The following flags have been REMOVED:

  • -log.level (use server.log_level in the YAML instead)
  • -log.format (use server.log_format in the YAML instead)
  • -server.http-tls-cert-path (use server.http_tls_config in the YAML instead)
  • -server.http-tls-key-path (use server.http_tls_config in the YAML instead)
  • -server.http-tls-client-auth (use server.http_tls_config in the YAML instead)
  • -server.http-tls-ca-path (use server.http_tls_config in the YAML instead)
  • -server.grpc-tls-cert-path (use server.grpc_tls_config in the YAML instead)
  • -server.grpc-tls-key-path (use server.grpc_tls_config in the YAML instead)
  • -server.grpc-tls-client-auth (use server.grpc_tls_config in the YAML instead)
  • -server.grpc-tls-ca-path (use server.grpc_tls_config in the YAML instead)
  • -server.http-listen-address (use the -server.http.address flag instead)
  • -server.http-listen-port (use the -server.http.address flag instead)
  • -server.grpc-listen-address (use the -server.grpc.address flag instead)
  • -server.grpc-listen-port (use the -server.grpc.address flag instead)
  • -server.path-prefix (usage of this flag was never supported and would cause issues)

-server.path-prefix and the equivalent YAML field server.path_prefix have been removed. Setting this option would lead to undefined behavior for various parts of the agent. Being able to prepend an API prefix may return in the future if it is requested.

Flags not listed here are unchanged.

Other changes

All jsonnet and config file examples no longer use the deprecated field names.

Todo

  • CHANGELOG updated
  • Documentation added
  • Tests updated
  • Locally test to double-check that self-scraping still works

Comment thread pkg/server/flags.go
Comment on lines +115 to +160
// RegisterFlags registers flags for c to the given FlagSet.
func (f *Flags) RegisterFlags(fs *flag.FlagSet) {
d := DefaultFlags

fs.BoolVar(&f.RegisterInstrumentation, "server.register-instrumentation", d.RegisterInstrumentation, "Register the intrumentation handlers (e.g., /metrics)")
fs.DurationVar(&f.GracefulShutdownTimeout, "server.graceful-shutdown-timeout", d.GracefulShutdownTimeout, "Timeout for a graceful server shutdown")
fs.BoolVar(&f.LogSourceIPs, "server.log.source-ips.enabled", d.LogSourceIPs, "Log IP address of client for incoming requests")
fs.StringVar(&f.LogSourceIPsHeader, "server.log.source-ips.header", d.LogSourceIPsHeader, "Header field storing the source IPs. Only used if server.log-source-ips-enabled is true. Defaults to Forwarded, X-Real-IP, and X-Forwarded-For")
fs.StringVar(&f.LogSourceIPsRegex, "server.log.source-ips.regex", d.LogSourceIPsRegex, "Regex for matching the source IPs. Only used if server.log-source-ips-enabled is true. Defaults to Forwarded, X-Real-IP, and X-Forwarded-For") // TODO(rfratto): help text here seems wrong?

f.HTTP.RegisterFlags(fs)
f.GRPC.RegisterFlags(fs)
}

// RegisterFlags registers flags for c to the given FlagSet.
func (f *HTTPFlags) RegisterFlags(fs *flag.FlagSet) {
d := DefaultHTTPFlags

fs.BoolVar(&f.UseTLS, "server.http.enable-tls", d.UseTLS, "Enable TLS for the HTTP server.")
fs.StringVar(&f.ListenAddress, "server.http.address", d.ListenAddress, "HTTP server listen host:port. Takes precedence over YAML listen flags when set.")
fs.StringVar(&f.ListenNetwork, "server.http.network", d.ListenNetwork, "HTTP server listen network")
fs.IntVar(&f.ConnLimit, "server.http.conn-limit", d.ConnLimit, "Maximum number of simultaneous HTTP connections (0 = unlimited)")
fs.DurationVar(&f.ReadTimeout, "server.http.read-timeout", d.ReadTimeout, "HTTP server read timeout")
fs.DurationVar(&f.WriteTimeout, "server.http.write-timeout", d.WriteTimeout, "HTTP server write timeout")
fs.DurationVar(&f.IdleTimeout, "server.http.idle-timeout", d.IdleTimeout, "HTTP server idle timeout")
}

// RegisterFlags registers flags for c to the given FlagSet.
func (f *GRPCFlags) RegisterFlags(fs *flag.FlagSet) {
d := DefaultGRPCFlags

fs.BoolVar(&f.UseTLS, "server.grpc.enable-tls", d.UseTLS, "Enable TLS for the gRPC server.")
fs.StringVar(&f.ListenAddress, "server.grpc.address", d.ListenAddress, "gRPC server listen host:port. Takes precedence over YAML listen flags when set.")
fs.StringVar(&f.ListenNetwork, "server.grpc.network", d.ListenNetwork, "gRPC server listen network")
fs.IntVar(&f.ConnLimit, "server.grpc.conn-limit", d.ConnLimit, "Maximum number of simultaneous gRPC connections (0 = unlimited)")
fs.IntVar(&f.MaxRecvMsgSize, "server.grpc.max-recv-msg-size-bytes", d.MaxRecvMsgSize, "Maximum size in bytes for received gRPC messages")
fs.IntVar(&f.MaxSendMsgSize, "server.grpc.max-send-msg-size-bytes", d.MaxSendMsgSize, "Maximum size in bytes for send gRPC messages")
fs.UintVar(&f.MaxConcurrentStreams, "server.grpc.max-concurrent-streams", d.MaxConcurrentStreams, "Maximum number of concurrent gRPC streams (0 = unlimited)")
fs.DurationVar(&f.MaxConnectionIdle, "server.grpc.keepalive.max-connection-idle", d.MaxConnectionIdle, "Time to wait before closing idle gRPC connections")
fs.DurationVar(&f.MaxConnectionAge, "server.grpc.keepalive.max-connection-age", d.MaxConnectionAge, "Maximum age for any gRPC connection for a graceful shutdown")
fs.DurationVar(&f.MaxConnectionAgeGrace, "server.grpc.keepalive.max-connection-age-grace", d.MaxConnectionAgeGrace, "Grace period to forceibly close connections after a graceful shutdown starts")
fs.DurationVar(&f.KeepaliveTime, "server.grpc.keepalive.time", d.KeepaliveTime, "Frequency to send keepalive pings from the server")
fs.DurationVar(&f.KeepaliveTimeout, "server.grpc.keepalive.timeout", d.KeepaliveTimeout, "How long to wait for a keepalive pong before closing the connection")
fs.DurationVar(&f.MinTimeBetweenPings, "server.grpc.keepalive.min-time-between-pings", d.MinTimeBetweenPings, "Maximum frequency that clients may send pings at")
fs.BoolVar(&f.PingWithoutStreamAllowed, "server.grpc.keepalive.ping-without-stream-allowed", d.PingWithoutStreamAllowed, "Allow clients to send pings without having a gRPC stream")
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deliberately chose to not support the old flag names as "deprecated" here, instead opting for the hard breaking change of the flag names.

Should we support the old names too or leave it as-is?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pro-breaking them

@rfratto rfratto left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave myself a quick review, which is way easier to do on GitHub than it is locally.

One extra thing: I want to make sure that I run the integrations locally before I take it out of draft to make sure self-scraping still works for both v1 and v2 integrations. (I've tested this locally and everything still works w/r/t self-scraping)

Comment thread cmd/agent/main.go
Comment on lines -48 to -50
if cfg != nil {
cfg.Server.Log = cfgLogger
}

@rfratto rfratto Mar 9, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This isn't necessary anymore since pkg/server.New doesn't read a Log field like the old New function did.

Comment thread pkg/server/flags.go
- url: https://prometheus-us-central1.grafana.net/api/prom/push
basic_auth:
username: 12345
username: xyz

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattdurham I changed all the usernames to xyz as sample text since 12345 could be easily confused with the port number we tend to recommend.


# Any user defined arguments
CUSTOM_ARGS=""
CUSTOM_ARGS="-server.http.address=127.0.0.1:9090 -server.grpc.address=127.0.0.1:9091"

@rfratto rfratto Mar 9, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: These used to be set on the config file, so I've moved them to flags that can be overridden.

Comment thread packaging/windows/install_script.nsis Outdated
Comment thread pkg/integrations/manager.go Outdated
"-config.file=/var/lib/grafana-agent/config/agent.yml",
"-config.expand-env=true",
"-reload-port=8081",
"-server.http.address=0.0.0.0:8080",

@rfratto rfratto Mar 9, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This moves setting the port from hard-coded in the YAML file to hard-coded as an argument. The same change is made for the metrics pods.

We'll want to include in the upgrade guide that v0.24.0 of the operator will only be able to deploy agents from v0.24.0 onward, since this flag name is new.

Comment thread pkg/server/server.go Outdated
Comment thread pkg/server/flags.go Outdated
rfratto added 8 commits March 10, 2022 07:44
pkg/server is a new top-level subsystem which exposes an HTTP and gRPC
server. It was forked off of weaveworks/common/server with direct
support for reloading settings we wish to keep as dynamic.

The following YAML fields are intended to be dynamically updatable:

* server.log_level
* server.log_format
* server.http_tls_config
* server.grpc_tls_config

Other fields are intended to be static and should only be set via
command line flag. Their YAML counterparts are now DEPRECATED and will
be removed in v0.26.0. As of this commit, reloading the config file will
fail if a non-dynamic field has changed in the server block.

Closes grafana-cold-storage#1336.

Flag changes
------------

Many flag names corresponding to the server have changed.

The following flags are NEW:

* `-server.http.enable-tls`
* `-server.grpc.enable-tls`
* `-server.http.address`
* `-server.grpc.address`

The `-server.*-enable-tls` flags must now be passed to enable TLS for
HTTP and gRPC respectively. This is a change from the previous behavior
of dynamically enabling TLS when a certificate pair is provided.

`-server.http.address` and `-server.grpc.address` are intended to be
`host:port` addresses on which to listen for HTTP and gRPC traffic. They
replace the `-server.*-listen-address` and `-server.*-listen-port` flags.

The following flags have been RENAMED:

* `-server.log.source-ips.enabled` (renamed from `-server.log-source-ips-enabled`)
* `-server.log.source-ips.header` (renamed from `-server.log-source-ips-header`)
* `-server.log.source-ips.regex` (renamed from `-server.log-source-ips-regex`)
* `-server.http.network` (renamed from `-server.http-listen-network`)
* `-server.http.conn-limit` (renamed from `-server.http-conn-limit`)
* `-server.http.read-timeout` (renamed from `-server.http-read-timeout`)
* `-server.http.write-timeout` (renamed from `-server.http-write-timeout`)
* `-server.http.idle-timeout` (renamed from `-server.http-idle-timeout`)
* `-server.grpc.network` (renamed from `-server.grpc-listen-network`)
* `-server.grpc.conn-limit` (renamed from `-server.grpc-conn-limit`)
* `-server.grpc.max-recv-msg-size-bytes` (renamed from `-server.grpc-max-recv-msg-size-bytes`)
* `-server.grpc.max-send-msg-size-bytes` (renamed from `-server.grpc-max-send-msg-size-bytes`)
* `-server.grpc.max-concurrent-streams` (renamed from `-server.grpc-max-concurrent-streams`)

The following flags have been REMOVED:

* `-log.level` (use `server.log_level` in the YAML instead)
* `-log.format` (use `server.log_format` in the YAML instead)
* `-server.http-tls-cert-path` (use `server.http_tls_config` in the YAML instead)
* `-server.http-tls-key-path` (use `server.http_tls_config` in the YAML instead)
* `-server.http-tls-client-auth` (use `server.http_tls_config` in the YAML instead)
* `-server.http-tls-ca-path` (use `server.http_tls_config` in the YAML instead)
* `-server.grpc-tls-cert-path` (use `server.grpc_tls_config` in the YAML instead)
* `-server.grpc-tls-key-path` (use `server.grpc_tls_config` in the YAML instead)
* `-server.grpc-tls-client-auth` (use `server.grpc_tls_config` in the YAML instead)
* `-server.grpc-tls-ca-path` (use `server.grpc_tls_config` in the YAML instead)
* `-server.http-listen-address` (use the `-server.http.address` flag instead)
* `-server.http-listen-port` (use the `-server.http.address` flag instead)
* `-server.grpc-listen-address` (use the `-server.grpc.address` flag instead)
* `-server.grpc-listen-port` (use the `-server.grpc.address` flag instead)
* `-server.path-prefix` (usage of this flag was never supported and would cause issues)

`-server.path-prefix` and the equivalent YAML field `server.path_prefix`
have been removed. Setting this option would lead to undefined behavior
for various parts of the agent. Being able to prepend an API prefix may
return in the future if it is requested.

Flags not listed here are unchanged.

Other changes
-------------

All jsonnet and config file examples no longer use the deprecated field
names.
TODOs about documentation have been "documented" in the original commit
message, and updating user documentation is being tracked externally on
the PR.
@rfratto
rfratto force-pushed the server-block-field-deprecation branch from 34f1073 to ae1ed0f Compare March 10, 2022 12:45
@rfratto

rfratto commented Mar 10, 2022

Copy link
Copy Markdown
Contributor Author

I've updated the user documentation to reflect the changes here and this is ready for review now.

The biggest remaining question is if we want to use this opportunity to move away from the default :80 listen address (or maybe that can be a separate PR?)

@rfratto
rfratto marked this pull request as ready for review March 10, 2022 12:46
@rfratto
rfratto requested a review from mattdurham March 10, 2022 12:46
Comment thread CHANGELOG.md Outdated
Comment thread pkg/server/server.go

@mattdurham mattdurham left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall great, I think the windows installer looks odd though and unsure about using 80 has the default.

@rfratto
rfratto requested a review from mattdurham March 10, 2022 17:32
@rfratto rfratto added this to the v0.24.0 milestone Mar 10, 2022

@mattdurham mattdurham left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rfratto
rfratto merged commit b0c1e45 into grafana-cold-storage:main Mar 10, 2022
@rfratto
rfratto deleted the server-block-field-deprecation branch March 10, 2022 18:07
rfratto added a commit to rfratto/agent that referenced this pull request Mar 10, 2022
…1:12346

This commit changes the default listen addresses to be 127.0.0.1:12345
(for HTTP) and 127.0.0.1:12346 (for gRPC). This makes listening on all
interfaces opt-in rather than opt-out, avoiding accidental overexposure
of access.

Closes grafana-cold-storage#852.

Additionally, the `-reload-addr` and `-reload-port` flags have been
removed as a follow up to grafana-cold-storage#1476. Now that the HTTP and gRPC server are
static for the lifetime of the application, it is impossible for the
user to change their configuration file in such a way to cause it to
shut down while performing a reload. This means that the `-reload-addr`
and `-reload-port` no longer have a use and can be removed safely.
rfratto added a commit that referenced this pull request Mar 14, 2022
* server: Change default listen addresses to 127.0.0.1:12345 / 127.0.0.1:12346

This commit changes the default listen addresses to be 127.0.0.1:12345
(for HTTP) and 127.0.0.1:12346 (for gRPC). This makes listening on all
interfaces opt-in rather than opt-out, avoiding accidental overexposure
of access.

Closes #852.

Additionally, the `-reload-addr` and `-reload-port` flags have been
removed as a follow up to #1476. Now that the HTTP and gRPC server are
static for the lifetime of the application, it is impossible for the
user to change their configuration file in such a way to cause it to
shut down while performing a reload. This means that the `-reload-addr`
and `-reload-port` no longer have a use and can be removed safely.

* fix extra references to old flags / port defaults

* config: fix test

* fix test assertion for reload address change
@github-actions github-actions Bot added the frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. label Apr 3, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Deprecation plan for server settings Panic when reloading a changed server config block

3 participants