http plugin: optional retry + stale-if-error for flaky/rate-limited cloud APIs
Is your feature request related to a problem? Please describe.
evcc's device integration has historically centered on local/EEBUS and Modbus. For remote or cloud-only deployments the generic http plugin is the main building block (custom meters, tariffs, sources), but it has no resilience against transient upstream failures. In plugin/http.go the request path ((*HTTP).request -> DoBody) returns the error straight through on any timeout / 5xx / rate-limit response. There is a response cache, but no retry and no "serve the last good value if the upstream errors".
So a single hiccup from a flaky or rate-limited cloud API surfaces as a meter/plugin error and disturbs the control loop, even though a perfectly good value was available seconds earlier. Concretely: the SolarEdge Monitoring API (the only way to read a SolarEdge system when evcc runs off-site, since the SolarEdge templates are all local/Modbus) has a hard request budget and returns intermittent 5xx. Each transient failure currently propagates into evcc as a meter error.
Describe the solution you'd like
Two optional, opt-in settings on the http plugin (defaulting to today's behavior, so nothing changes for existing configs):
retry- retry the request with backoff before giving up, so a transient 5xx/timeout doesn't immediately become a plugin error. Non-retryable statuses (e.g. 4xx) still fail fast.staleIfError- if the upstream still fails after retries, serve the last successfully fetched value up to a configurable age instead of erroring.
Config sketch:
source: http
uri: https://monitoringapi.solaredge.com/...
cache: 6m
retry:
count: 3
backoff: 2s # base backoff, exponential
staleIfError: 15m # serve last good value up to this age on failure
This fits the existing code: github.com/cenkalti/backoff/v4 is already a dependency (util/request/functions.go even uses backoff.Permanent to classify non-retryable responses), and httpcache is already wired into the plugin's transport stack, so stale-if-error can build on the value already being cached.
Describe alternatives you've considered
- External caching + retry proxy in front of the cloud API. This works (I run one in front of SolarEdge purely to shield evcc from these transients), but it is a sidecar service that shouldn't be necessary for what is a generic HTTP resilience concern.
- Relying on the existing
cachealone. It doesn't help here: on a failed revalidation the plugin errors rather than serving the cached value, and it does no retry. - Per-integration handling, as was done for tariffs (#28675 / #28676, "don't treat HTTP 429 as permanent backoff error"). That solved it for the tariff layer only; the generic
httpplugin used by meters and custom sources still has no equivalent.
Additional context
- Prior art: #28675 / #28676 brought transient-vs-permanent retry/backoff to the tariff layer; this request is to bring the same resilience to the generic
httpplugin. #31108 (http plugin cache clock-skew fix) shows the plugin's cache/transport stack is actively maintained, which is wherestaleIfErrorwould sit. - I could not find an existing issue/discussion proposing
staleIfError(serving a last-good value on upstream failure) for the http plugin; that part appears new. - Happy to help shape the config surface and to test against a real, rate-limited SolarEdge Monitoring API setup.
but it has no resilience against transient upstream failures
Not sure what is claim is based on. We're generally treating remote errors as "operation not completed" and repeat during the next control cycle. Why isn't this sufficient?
Concretely: the SolarEdge Monitoring API (the only way to read a SolarEdge system when evcc runs off-site, since the SolarEdge templates are all local/Modbus) has a hard request budget and returns intermittent 5xx.
Did you open issue with SE? It's an obvious bug counting their errors against request budget.
Two clarifications:
-
Not a budget issue on our side. The SolarEdge limit is ~500 req/s and we're well under it. The failures are transient 5xx and 15-35 s hangs, not throttling, so "their errors count against the budget" doesn't really apply here. Agree the 5xx are their bug, but SE isn't going to fix it - or do you have a different experience through evcc?
-
On "repeat next control cycle": that's fine for a command/write, but for the grid meter it means the current cycle has no value. In
pvmode a failed grid read drops the surplus signal, so the loadpoint disables mid-charge; with a Vaillant the boost is a non-modulating Quick-Veto, so one dropped cycle cancels the whole ~35 min charge and it re-triggers later. stale-if-error (serve last-good for a bounded TTL) keeps the loop stable across a 20 s blip instead of flapping.
I already do this with a tiny local caching proxy (took evcc from intermittent errors to zero), so this is really just asking whether that pattern belongs in the http plugin. Completely fine if you'd rather keep it external. I mainly wanted to surface the control-stability angle, not resilience for its own sake.
but for the grid meter it means the current cycle has no value. In pv mode a failed grid read drops the surplus signal, so the loadpoint disables mid-charge
Does it? A failed grid read should probably retry that- whatever the root cause is- and short-circuit any loadpoint control. If that's the issue we should rather fix that?
/cc @premultiply
You're right! I checked core/site.go and I had the mechanism wrong:
- The grid read is already retried:
updateGridMeterusesbackoff.RetryWithData(site.gridMeter.CurrentPower, modbus.Backoff()). - Control is already short-circuited on failure:
sitePowerreturns the error, and insite.updatethe wholelp.Update(...)path sits underif err == nil { … } else { log }. So a failed grid read just skips the cycle and the loadpoint holds state. It doesn't disable or flap.
So the control-stability argument doesn't stand; evcc already handles this, which was the main justification.
So now that the http plugin already has cache + timeout, and dropCacheBusting strips the no-store/max-age=0 headers that used to defeat caching for us (#31025), the built-in cache actually holds against the SolarEdge API. So our local proxy was really just papering over the 5xx/hangs. We'll likely retire it and set cache + timeout on the http meter instead. Good call to push back, thanks @andig - happy to close.
...that's why I'm trying to understand the actual underlying issue ;)