Skip to content

AppConfig "empty" response handling #1672

Closed
@chrisclayson

Description

@chrisclayson

What were you trying to accomplish?

Using the AppConfigProvider for the parameters project, I noticed a bug in the handling of instances where AppConfig returns the empty response (i.e. where config has not changed).

This was specifically for a "Freeform configuration profile" rather than feature flags (which I have not tested).

Expected Behavior

The provider should re-use the cached config.

Current Behavior

The provider returns an empty string for the config rather than the cached config. The seems to be because the provider only checks for null and not "empty".

Possible Solution

I implemented a copy of the AppConfigProvider class and added a check for response.configuration().asByteArray().length > 0 and this worked, i.e.:

        // Get the value of the key. Note that AppConfig will return null if the value
        // has not changed since we last asked for it in this session - in this case
        // we return the value we stashed at last request.
        String value = response.configuration() != null && response.configuration().asByteArray().length > 0 ?
                response.configuration().asUtf8String() : // if we have a new value, use it
                establishedSession != null ?
                        establishedSession.lastConfigurationValue :
                        // if we don't but we have a previous value, use that
                        null; // otherwise we've got no value

        // Update the cache so we can get the next value later
        establishedSessions.put(key, new EstablishedSession(nextSessionToken, value));

        return value;

I'm happy to submit as a PR.

Steps to Reproduce (for bugs)

  • Setup a freeform configuration profile in AppConfig with some value (we used a JSON object { "version": 1 })
  • Retrieve from a lambda using PowerTools parameters:
          var config = ParamManager.getAppConfigProvider("test", "test")
                .withMaxAge(30, ChronoUnit.SECONDS)
                .get("test");
  • Fire continuous traffic at the lambda

The first retrieval, on any given runtime environment, will work fine, but after the 30 second TTL the next retrieve from AppConfg returns an empty string, which is returned from the get() method rather than original (cached value).

Environment

  • Powertools for AWS Lambda (Java) 1.18.0
  • Built with Gradle
  • Java 17 runtime

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions