Skip to content

Upgrading

Upgrade the shared proxy first, once, in a window you announce. Each team upgrades its agents later, when it suits the team, since a proxy and agents of different releases work together (Versions That Work Together).

  • Impact. Every team's scrapes go through the proxy, so its restart changes all of them at once: no path is scraped, every agent reconnects, and the dashboard loses its Activity view, each path's History, and its sign-ins (What a Proxy Restart Interrupts).
  • Check. Read what the new release refuses at startup, and note how many agents and paths the proxy has (step 1).
  • Upgrade. Put the new release in place and restart the proxy (step 2). Then each team upgrades its agents (step 3). With a primary and a standby, upgrade the primary first (Which to Upgrade First).
  • Verify. The proxy's log says it's up, and the agent and path counts match what you noted (step 2).
  • Go back. Put the previous release back, and every team's agents reconnect to it (Going Back).

For an app that embeds the agent, Upgrading an Embedded Agent covers what its code sees.

1. Check Before You Upgrade

Find out which releases you run. The proxy and the agent each log their version as they start, as --version prints it. From 4.7.0 on, their metrics give it too, in the version label of proxy_build_info and agent_build_info. An agent whose metrics are scraped without agent_build_info is older:

count by (version) (agent_build_info)

Then read the "Before you upgrade" section of each release between yours and the new one, in the release notes. It lists the changes you have to act on first.

Look hardest for what the new release refuses at startup: a proxy that refuses its config doesn't start, and while it's down, no team's paths are scraped. The boxes below give what the last three releases change for a standalone proxy and its agents. From 4.8.0, read the first; from 4.7.0, open the second too, and from 4.6.x, the third as well.

Upgrading from 4.8.0

A proxy or an agent that starts on 4.8.0 starts on 4.9.0 too. After the upgrade:

  • Each logs a WARN at startup for each key of its config section, proxy or agent, that isn't a setting, naming the nearest one. Such a key never had an effect: fix its name, or remove it.
  • The proxy's and the agents' Grafana dashboards, and grafana/alerts.yml, have panels and alerts for 4.9.0's new metrics: import them again.
  • On the screens page, give a Prometheus screen probe = "/-/healthy", which stops the browser's console logging an error every 5 seconds.

An app written in Kotlin that embeds the agent needs Kotlin 2.4 or later to compile (Upgrading an Embedded Agent).

Upgrading from 4.7.0

The proxy:

  • Refuses to start with a proxy.auth pattern that has a / after its leading one, such as team_a/*. With service discovery on, it also refuses a proxy.service.discovery.path of whitespace, / alone, or two leading slashes. A pattern with one leading slash, such as /team_a_*, now matches, where it matched no path.
  • Lets any page frame its dashboard, and so do the agents, where 4.7.0 refused framing on both. To keep refusing it, set proxy.dashboard.framingEnabled = false, and agent.dashboard.framingEnabled = false on an agent whose dashboard is on.
  • Pins each origin in proxy.dashboard.allowedOrigins to its scheme: if viewers open the dashboard over both http and https, list both origins.
  • Answers a script that sends the dashboard's login as Basic Auth with a browser's headers as it answers a browser, with the login page or a 401. Those headers are Accept: text/html, Upgrade-Insecure-Requests, Origin, and Referer; drop them from the script.
  • In the Helm charts, runs its pods, and the agents', without a Kubernetes API token. If something added to the pod needs one, such as a sidecar, set the chart's automountServiceAccountToken to true.

The agents:

  • Refuse to start with a configured path of more than one segment, such as app/metrics or //metrics, or with a proxy endpoint they can't dial, such as :50051 or [::1]50051. A discovered path of more than one segment is skipped.
  • Keep their activity feed in memory from startup, within agent.dashboard.activityLogSize, even with their dashboard off. They refuse to start with an agent.dashboard.refreshIntervalSecs, pathHistorySize, or activityLogSize that isn't positive. An agent with its direct dashboard off and agent.dashboard.showOnProxy = false does neither, and shows on no proxy's screens page.
Upgrading from 4.6.x

The proxy:

  • Refuses a path with more than 64 labels, proxy.internal.maxLabelsPerPath, and a path past the 100,000 that one identity's agents may register together, proxy.internal.maxPathsPerIdentity. With agent auth off, or every agent on the shared proxy.agentToken, every agent is one identity, so the limit counts your whole fleet. Raise either, or set it to 0 for none, before you upgrade. They apply to agents of any release.
  • Refuses framing on every dashboard response, as the agents do; 4.8.0 allows it again by default.
  • In the Helm chart, listens for its dashboard on the pod's loopback only (dashboard.host, 127.0.0.1). To publish the dashboard through a Service or an Ingress you add, set dashboard.host to 0.0.0.0, and require a login.
  • In etc/compose/proxy.yml, publishes its ports on 127.0.0.1 only, and the agents' port, 50051, not at all.

The agents:

  • Read DASHBOARD_ENABLED, DASHBOARD_PORT, DASHBOARD_PATH, DASHBOARD_HOST, DASHBOARD_USERNAME, DASHBOARD_PASSWORD, and METRICS_PROXY_PATH, which only the proxy read, or nothing did. An agent whose environment sets them, such as one that shares the proxy's env file, opens its direct dashboard, on port 8095 unless DASHBOARD_PORT names another, or serves its metrics at that path. It refuses to start on a value it can't parse, or on a dashboard port that's taken. Check each agent's environment before you upgrade it.

Note how many agents are connected and how many paths are registered, to compare after the upgrade. proxy_agent_map_size and proxy_path_map_size give them, and so do the dashboard's Agents and Paths views. Then tell the teams when the proxy will restart.

2. Upgrade the Proxy

In the JAR, Docker, and Helm tabs, the first command sets NEW to x.y.z. Change it to the release you're upgrading to, as its release page names it.

These commands are for a proxy run by the systemd unit in Running as a Service. Download the new JAR beside the running one, and check its version:

NEW=x.y.z   # the release you're upgrading to
BASE=https://github.com/pambrose/prometheus-proxy/releases/download/$NEW
cd /opt/prometheus-proxy
sudo curl -fLo prometheus-proxy.jar.new "$BASE/prometheus-proxy.jar"
# Prints Version: and the new release:
java -jar prometheus-proxy.jar.new --version

Once it prints the new release, keep the running JAR to go back to. Then move the new one into place, so the running proxy's JAR isn't written over, and restart the proxy:

cd /opt/prometheus-proxy
sudo cp prometheus-proxy.jar prometheus-proxy.jar.previous
sudo mv prometheus-proxy.jar.new prometheus-proxy.jar && sudo systemctl restart prometheus-proxy
journalctl -u prometheus-proxy -f   # follow its log

The tap has only its current release, so note the one you run first: going back runs its JAR.

# The release you run now:
brew list --versions prometheus-proxy
brew update
brew upgrade pambrose/tap/prometheus-proxy
brew services restart prometheus-proxy
# Follow its log:
tail -f "$(brew --prefix)/var/log/prometheus-proxy.log"

The upgrade keeps a prometheus-proxy.conf you've edited, and puts the new release's default beside it, as prometheus-proxy.conf.default.

Pull the new image before you stop the container, so the gap is only the start:

NEW=x.y.z   # the release you're upgrading to
docker pull "pambrose/prometheus-proxy:$NEW"
# Its IMAGE column has the tag to go back to:
docker ps --filter name=prometheus-proxy

Once the pull succeeds, stop and remove the container:

docker stop prometheus-proxy && docker rm prometheus-proxy

Then start it with the docker run you started it with, with pambrose/prometheus-proxy:$NEW as its image. For Production Setup's, run this from the directory that holds its certificate, key, and token:

docker run --detach --name prometheus-proxy \
  -p 50051:50051 \
  -p 127.0.0.1:8080:8080 \
  -p 127.0.0.1:8082:8082 \
  -p 127.0.0.1:8092:8092 \
  --env CERT_CHAIN_PEM="$(base64 < server.crt | tr -d '\n')" \
  --env PRIVATE_KEY_PEM="$(base64 < server.key | tr -d '\n')" \
  --env AGENT_TOKEN="$(cat agent-token)" \
  --env ADMIN_ENABLED=true \
  --env METRICS_ENABLED=true \
  --restart unless-stopped \
  "pambrose/prometheus-proxy:$NEW"

With Compose, change the image's tag in the compose file, and run docker compose up --detach. It recreates each container whose image changed.

Clone the repository at the new release, whose charts run its images. Then upgrade the release with the values file it was installed with:

NEW=x.y.z   # the release you're upgrading to
git clone -c advice.detachedHead=false --depth 1 --branch "$NEW" \
  https://github.com/pambrose/prometheus-proxy.git "prometheus-proxy-$NEW"
# The revision to go back to:
helm history prometheus-proxy --namespace monitoring
helm upgrade prometheus-proxy \
  "prometheus-proxy-$NEW/charts/prometheus-proxy" \
  --namespace monitoring -f proxy-values.yaml
# Wait for the new pod, then follow its log:
kubectl -n monitoring rollout status deployment/prometheus-proxy
kubectl -n monitoring logs deploy/prometheus-proxy -f

Without that file, helm get values prometheus-proxy --namespace monitoring -o yaml > proxy-values.yaml writes the values the release has. If it sets image.tag, change it to the new release, or remove it: unset, the chart runs its release's image.

The log gives the new release's version and says the proxy is up. Then it logs each agent's paths as the agent reconnects and registers them again:

The proxy's log
All Proxy services healthy
Added path /team_b_orders for agentId 12

Once the agents are back, proxy_agent_map_size and proxy_path_map_size, or the dashboard's Agents and Paths views, match what you noted. proxy_build_info gives the new version.

Going Back

If the new release refuses the proxy's config, it logs why, after Invalid configuration:, and exits with status 1 (see The Proxy or Agent Exits at Startup). Its supervisor starts it again, and it fails the same way. Correct the setting, as the release notes say. Or put the previous release back, as for any other problem the upgrade brings, and every team's agents reconnect to it:

cd /opt/prometheus-proxy
sudo mv prometheus-proxy.jar.previous prometheus-proxy.jar
sudo systemctl restart prometheus-proxy

Homebrew can't install the previous release, since the tap has only its current one. Until a release fixes what sent you back, run the previous release's JAR with the service's config. Set OLD to the release you upgraded from, as brew list --versions showed it, and download its JAR:

OLD=x.y.z   # the release you upgraded from
BASE=https://github.com/pambrose/prometheus-proxy/releases/download/$OLD
curl -fLO "$BASE/prometheus-proxy.jar"

Once it's downloaded, stop the service, and run the JAR on the Java the formula installed. It runs in your terminal until you stop it with Ctrl+C:

brew services stop prometheus-proxy
"$(brew --prefix openjdk@25)/bin/java" -jar prometheus-proxy.jar \
  --config "$(brew --prefix)/etc/prometheus-proxy.conf"

To keep it running after you close the terminal, start it with nohup, as in the Quick Start's Keep it running.

Set OLD to the tag docker ps showed before the upgrade, and stop and remove the new release's container:

OLD=x.y.z   # the release you upgraded from, as docker ps showed it
docker stop prometheus-proxy && docker rm prometheus-proxy

Then start it with the docker run you started it with, with pambrose/prometheus-proxy:$OLD as its image. For Production Setup's, run this from the directory that holds its certificate, key, and token:

docker run --detach --name prometheus-proxy \
  -p 50051:50051 \
  -p 127.0.0.1:8080:8080 \
  -p 127.0.0.1:8082:8082 \
  -p 127.0.0.1:8092:8092 \
  --env CERT_CHAIN_PEM="$(base64 < server.crt | tr -d '\n')" \
  --env PRIVATE_KEY_PEM="$(base64 < server.key | tr -d '\n')" \
  --env AGENT_TOKEN="$(cat agent-token)" \
  --env ADMIN_ENABLED=true \
  --env METRICS_ENABLED=true \
  --restart unless-stopped \
  "pambrose/prometheus-proxy:$OLD"

With Compose, put the previous tag back in the compose file, and run docker compose up --detach.

# Back to the revision before the upgrade:
helm rollback prometheus-proxy --namespace monitoring

It restores the previous revision's chart and values, and so its image.

Going back from 4.8.0 to 4.7.0, the config loads as it is, since 4.7.0 ignores the settings it doesn't have, but:

  • A proxy.auth pattern with a leading slash, such as /team_a_*, matches no path on 4.7.0, so that identity's agents can register none of their paths. Write it as team_a_* before you go back.
  • The screens page, /screens, is gone, and with it the relayed agent dashboards.
  • Every dashboard refuses to be framed again, whatever framingEnabled says, so a page of yours that frames one shows nothing there.
  • proxy.dashboard.trustedProxies does nothing, so behind a reverse proxy, every viewer shares one limit on wrong logins again.

3. Upgrade the Agents

Each team upgrades its agents the same way, with prometheus-agent in place of prometheus-proxy. That covers its JAR, unit, formula, image, container, and chart, with the agent's values file and namespace.

An agent's restart takes only its paths off the proxy. Their scrapes fail until it registers them again, seconds after it starts, unless another agent serves the same path in consolidated mode. It logs:

The agent's log
Connected to proxy at proxy-host.example.com:50051 using plaintext
Sending stream keepalives to proxy proxy-host.example.com after 30s without a result
Registered http://localhost:9100/metrics as /my_app_metrics with labels {} (static)

With proxy.dashboard.agentScreens on, an agent from 4.8.0 on also logs Proxy proxy-host.example.com shows this agent's dashboard on its screens page, and gets a tab there for its relayed dashboard. An agent whose config the new release refuses logs why, after Invalid configuration:, and exits. Step 1's release changes name what each release refuses. Going back is as for the proxy.

What a Proxy Restart Interrupts

  • Scrapes. None of the proxy's paths is scraped until the proxy is back and each agent has registered its paths again, so Prometheus records those scrapes as failed, up 0.
  • Every agent's connection. Each agent tries to reconnect every agent.internal.reconnectPauseSecs, 3 seconds by default, so it's back within seconds of the proxy. An agent from 4.6.0 or earlier with one proxy endpoint waits out gRPC's backoff instead. That backoff grows the longer the proxy is down, up to 2 minutes, so such an agent can return that much later.
  • Failover. An agent with more than one endpoint in agent.proxy.endpoints moves to the next, and returns to the first at its next reconnect.
  • The pod, in Kubernetes. The chart replaces the proxy's pod with the Recreate strategy: it stops the old pod before it starts the new one. So the gap includes the JVM's start, and pulling the new image if the node doesn't have it.
  • The dashboard. The proxy keeps its Activity view, each path's History, and its sign-ins in memory, so they start empty, and everyone signs in again.

Which to Upgrade First

Upgrade the proxy first, then the agents. That way the shared proxy restarts only once, and a newer proxy with older agents is the pairing the nginx demo runs. Each team's agents gain the features that need both sides as the team upgrades them.

With proxy.dashboard.agentScreens on, every agent upgraded to 4.8.0 or later shows its relayed dashboard on the proxy's screens page, with its paths, target URLs, scrapes, and activity. Everyone who can sign in to the proxy's dashboard sees it, other teams included, unless the agent sets agent.dashboard.showOnProxy = false. Tell each team before it upgrades (see The Dashboard on a Shared Proxy).

With a primary and a standby, upgrade the primary first. Its agents fail over to the standby within seconds, and stay there. Once the primary is back, give it a few seconds, then upgrade the standby: its restart sends each agent back to the first endpoint in its list, the upgraded primary.

In the other order, the agents stay on the standby after the primary's upgrade, until their connection to it drops. AgentNotOnPrimary, in grafana/alerts.yml, fires for each agent left on a backup endpoint for 30 minutes.

Versions That Work Together

When an agent registers, it and the proxy each say which newer features they support. Each uses a feature only when the other supports it too, and otherwise behaves as its release did before. So a proxy and agents of different releases still connect, register their paths, and scrape. A mixed pair goes without only the features its older side lacks.

Each of these needs both the proxy and the agent on the release named, or later:

  • Stream keepalives, 4.7.0, which keep a reverse proxy's idle timeout from closing an agent's streams. Without them, an agent behind nginx or another reverse proxy is cut off whenever a stream stays quiet for the idle timeout, and reconnects. Until both are upgraded, raise the timeouts (nginx Reverse Proxy).
  • Takeover notices, 4.7.0, which tell an agent that another agent took its path. Without them, the displaced agent shows the path as registered, and takes it back only when it reconnects (An Agent Is Connected but Serves No Paths).
  • Agents' dashboards on the screens page, 4.8.0. An agent from 4.7.0 or earlier gets no tab there.

The project names no range of releases that work together, and its tests run a proxy and agents of the same release. The nginx demo does mix them: its proxy is the current release, and one of its agents runs 4.6.0 on purpose.

An agent newer than its proxy says, as it connects, which of these the proxy lacks:

The agent's log, with a proxy from 4.6.0
Sending no stream keepalives to proxy proxy-host.example.com: it gives no interval
Proxy proxy-host.example.com predates path notices; a path another agent takes over stays shown here