Giter VIP home page Giter VIP logo

configcat / java-sdk Goto Github PK

View Code? Open in Web Editor NEW
17.0 7.0 5.0 943 KB

ConfigCat SDK for Java. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.

Home Page: https://configcat.com/docs/sdk-reference/java

License: MIT License

Java 100.00%
feature-flags featureflags feature-flag feature-toggle feature-toggles configuration configuration-management remote-config configcat java

java-sdk's People

Contributors

adams85 avatar betterconfig avatar configcat-developer avatar dependabot[bot] avatar erosb avatar kp-cat avatar lajos88 avatar laliconfigcat avatar mr-sige avatar novalisdenahi avatar sigewuzhere avatar z4kn4fein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-sdk's Issues

Hook for Changed Features

Is your feature request related to a problem? Please describe.

When Programming reactively or asyncronusly it is only interesting to know when a Feature has changed.
I don't believe the (...)Async Endpoints are helpful here.

Describe the solution you'd like

I would like to be notified when the value of a Feature Toggle/Config is Changed.
Optimally I would like to listen to Spring Application Events.

Describe alternatives you've considered

Alternatively a simple Oberserver-Pattern would be fine.
Or any other Pub-Sub Pattern.

Additional context

We are using it with Spring Gateway, and want to change the Routing during Runtime based on the Toggles State.

BeanCreationException error after upgrading to version 8.x

Describe the bug

After upgrading java from version 16 to 17 and upgrading the config-cat lib from vesion 6.x to 8.x, the Bean creation on spring started to fail with the exception BeanCreationException

To reproduce

Upgrade java vertion to 17 and config-cat to 8.x

<dependency>
      <groupId>com.configcat</groupId>
      <artifactId>configcat-java-client</artifactId>
      <version>[8.0.0,)</version>
    </dependency>

Change the bean creation from:

@Bean
    ConfigCatClient configCatClient() {
        return ConfigCatClient
            .newBuilder()
            .mode(PollingModes.autoPoll(60))
            .logLevel(LogLevel.WARNING)
            .build(this.settings.sdkKey)
    }

To:

import com.configcat.*;

@Bean
    ConfigCatClient configCatClient() {
        return ConfigCatClient.get(this.settings.sdkKey, options -> {
          options.pollingMode(PollingModes.autoPoll());
          options.logLevel(LogLevel.WARNING);
        })
    }

The error:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configCatClient' defined in class path resource [br/com/blz/myrepo/config/ConfigCat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.configcat.ConfigCatClient]: Factory method 'configCatClient' threw exception; nested exception is java.lang.reflect.GenericSignatureFormatError: Signature Parse error: expected a class type

Extra error log statement.

We have got error log ingestion once we updated our java client to 8.0.0. On debugging the issue I found extra error log in configFetcher.java class which logs an error message on every response.

Can you please check and remove this.

OkHttpClient connection was leaked warning

Investigate this warning:

2021-01-10 23:25:45.108 WARN 61 --- [ ConnectionPool] okhttp3.OkHttpClient : A connection to https://cdn-global.configcat.com/ was leaked. Did you forget to close a response body? To see where this was allocated, set the OkHttpClient logger level to FINE: Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);

Settings Class is only Package Public

If you're not sure whether your problem is specifically related to this repository, or to the ConfigCat service overall, please contact the ConfigCat support. This issue tracker is intended only for feedback on the content of this repository.

Describe the bug

When trying to use the onConfigChanged callback, the Settings class is not available.

To reproduce

Use this code
options.hooks().addOnConfigChanged(stringSettingMap -> stringSettingMap.get("bla"));
or this
client.getHooks().addOnConfigChanged((stringSettingMap) -> stringSettingsMap.get("bla"));
The Compiler failes with: 'com.configcat.Setting' is not public in 'com.configcat'. Cannot be accessed from outside package

Expected behavior

On Config Changed can be used.

Screenshots

Bildschirm­foto 2023-03-07 um 15 49 23

SDK version

8.0.2

SDK configuration

onfigCatClient.get(this.configCatApiKey, (options -> { options.pollingMode(PollingModes.autoPoll(10)); options.hooks().addOnConfigChanged(stringSettingMap -> stringSettingMap.get("bla")); }));

Logs

If applicable, add the related SDK's log output here.

Language/Framework version

Java-SDK

Platform

macOS Ventura

Breaking change to ConfigCatClient creation is missing from release notes

I tried (or, well, Dependabot tried) to upgrade to the new 8.0.0 release of the SDK, but it fails due to a breaking change to the way you create a new instance of ConfigCatClient. In the previous release, you would call ConfigCatClient.newBuilder() and set the options through it. Now, you need to call ConfigCatClient.get(sdkKey[, optionsCallback]). I suggest you mention this in the release notes, since everyone needs to adapt to this change 🙂 (The existing note about ConfigCatClient.get does not make any sense, since that method did not even exist in the previous release, by the way.)

Spurious "onReposnse" error logged every refresh

Describe the bug

Every time ConfigCat (we're using version 8.0.0) retrieves the current values, it logs a log message like this:

{"message":"onReposnse","logger_name":"com.configcat.ConfigCatClient","thread_name":"OkHttp https://cdn-eu.configcat.com/...","level":"ERROR","level_value":40000}

This is a very unspecific error, and it seems like the value updates are still succeeding.
It pollutes our logs.

Thanks to the misspelling of "onResponse", I was able to locate the source of this spurious log message:

logger.error("onReposnse");

It seems like the log message was added to aid in debugging, but was not removed before release.

To reproduce

Use the ConfigCat SDK and observe the logs when it retrieves values from ConfigCat.

Expected behavior

If there is an actual error, it should be much more detailed.
If there is no error, then it shouldn't log a message with the error level.

When calling force refresh, failure to write on cache will make it impossible to refresh again without server state change

Describe the bug

Issue on calling forceRefresh() when previous refresh fail on writing to cache. With custom ConfigCache.
It is possible to fail when writing to cache, example: distributed cache can fail to write (even though the chance is very small it still exist).

To reproduce

Use MANUAL polling mode.
Create a feature flag, lets create String for easy check, with initial value: "INITIAL"
Create a custom ConfigCache, like below to mimic exception:

    public class FailWriteEveryThirdRequest extends ConfigCache{
        Map<String, String> map = new HashMap<>();
        AtomicInteger counter = new AtomicInteger(1);
        
        @Override
        protected String read(String key) throws Exception {
            return map.get(key);
        }

        @Override
        protected void write(String key, String value) throws Exception {
            if(counter.getAndIncrement() % 2 == 0){
                throw new RuntimeException("I fail for some reason"); // just to mimic exception on failure writing
            }
            map.put(key, value);
        }
    }

Update the value and refresh -> everything good -> before refresh for the second time (that will throw exception):

  • Update value to "UPDATE WILL THROW EXCEPTION"
  • Since it will throw exception cache won't be updated

Do force refresh again:

  • Value will not be updated because it return NOT_MODIFED response and it won't write to cache
  • When GET the flag it will still return the previous value from cache.
  • Doing forceRefresh() is not doing anything now since there is no changes at server. (Not sure if it will be different after some time)

Root cause:

  • I am not sure how the server check the "version" of the client feature value, but i believe it based on the "ETag"?
  • As you can see here it save the "ETag" value.
  • But at the exception handling on cache writing here it doesn't revert the "ETag" thus I believe server thought its already updated.

Expected behavior

At minimum, when fail to write to cache, the next successful refresh (done manually) should be able to update the value.
Better solution is server can know when there is a problem on writing and when client use webhook, server can do retry mechanism.

Screenshots

N/A

SDK version

Tried at 7.0.4 and 7.0.5

SDK configuration

Default configuration also can reproduce. (Just use manual polling and manual force refresh)

Logs

N/A

Language/Framework version

Java 8

Platform

Any

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.