Skip to content

Commit

Permalink
Config v6 (#18)
Browse files Browse the repository at this point in the history
* SDKKey validation updated to handle proxy and new key format

* Comparators rework

Removed:IS ONE OF, IS NOT ONE OF
Changed: CONTAINS, DOES_NOT_CONTAIN
Added: DATE_BEFORE, DATE_AFTER, HASHED_EQUALS, HASHED_NOT_EQUALS, HASHED_STARTS_WITH, HASHED_ENDS_WITH, HASHED_ARRAY_CONTAINS, HASHED_ARRAY_NOT_CONTAINS

* Fix comparators names

* Fix comparator names and add new comparator

* v6 and models added

* Implement evaluatePrerequisiteFlagCondition and added v6 tests

* Fix comparator and other errors

* Added segments impl and test

* Rename ComparisonCondition to UserCondition

* Added logs to new code

* Evaluation logger

* Evaluation logs and tests finished

* Logs NumberFormat updated and DateUTC fixed

* Remove TODOs

* EvaluateLogger depends on LogLevel

* v5 and v6 sdkKey updates

* EvaluationLoggerTurnOffTest updated with LogLevel checks

* Added attributeValueFrom user helper methods. (no date yet)

* Format code

* Fix matrix test v5vsV6. Add remoteJson to tests

* Detekt fixes

* Ktlint fixes

* Add docs

* Fix list truncation

* Date double value format fix. Cannot convert to Long because it's not milliseconds

* Fix JS test errors. Lint and detekt problems.

* Added text comparators. Updated segments evaluation. Updated tests.

* Unicode test and fixes added

* Small fix and reduce logged info in tests

* Evaluator warning fixes

* Format

* Fix failing JS tests

* Remove println

* Added tests and small fixes. CCUser handle Any values

* JS number settingtype added to handle JS number conversion.

* Fix JS Evaluation fails because of cache message

* Update 1103 error message

* Fix circular dependency missing remove.

* Rename Comparator to USerComparator.
Fix user attribute override.
Set evaluateConditions default result to true. Fix variationIDTests json.
Fix getKeyAndValue method to handle targetRule percentage options as well.

* Fix getKeyAndValue targeting rule if.
Add exception to evaluatePercentageOptions if sum is not 100%.

* Move configSalt validation from deserialization.

* update processHashedStartEndsWithCompare handle sliced String

* Update trim and refactor process methods.

* Accept NaN

* Added extra segment and prerequisite tests

* Error message fixes

* SDK key validation LOCAL_ONLY fix

* Code format

* Fix httpEngine in test

* klint fix

* Added missing PrerequisiteFlag Override Test

* Add trim test
Fix user value version trim

* Add trim test
Fix user value version trim

* Fix user toString use simple json.
Fix comparatorsTests.

* Fix Array and List convert to String to use json.

* Add specialCharacter test

* Refactor LogHelper

* Platform based double format WIP

* Set stringbuilder lineseparator as default

* Lint fixes

* Fixes after merge.
Exclude native format test.

* Change DataSource setting to config.
Fix override test.
Fix missing segment and configSalt mapping.

* JS platform send agent and etag info in the request query params.

* Remove expected NumberFormatter class. Now just the doubleToString method expected and implemented.

* Fix date conversions

* Fix log double format. Now only the native platform is different from the expected.

* NSNumberFormatter added (not tested)

* lint fix

* fix imports

* Added darwinTest module

* Try to fix darwin number formatter

* Type validation updated and some test added

* lint fix

* Try to fix formatter

* Update NumberFormatter.kt

* darwin test fix

* darwin test fix

* darwin test fix

* Fix test after merge.
Move EvaluateLogger to a new file.

* Value type and setting type validation fixed. getAnyValue and getAnyValueDetails check allowed types.
Missing hooks and error logging added.
getAnyValue and getAnyValueDetails allow null defaultValue.
Fix tests based on changes and add some type validation tests.

* Fix tests

* Fix darwin test

* Update version to 3.0.0

* Fixes on model based on code review

* Fixes based on code review

* Fixes based on code review

* Fix based on code review

* Refactor getValue/getAnyValue and getValueDetails/getAnyValueDetails to have a consistent behavior with other SDKs (#27)

* Hashed length trim added

* Fixes based on review

* Add analysis to PR checks

* Detekt and lint fixes

* SemVer fix. Lint fix

* Added when fix

* Add tests

* klint fix

* detekt fix

* Add more test

* Fix testGetValueDetailsValidTypes

* Fix test error

* Moved Utils method to internal object

* Detekt fix

* Lint fix

* Rename Utils file to Constants and internal object Utils to Helpers

* Added FlagValueSerializer tests

* Update fetcher param test to check http/2 headers.

* Added getKeyAndValue tests

---------

Co-authored-by: Peter Csajtai <peter.csajtai@outlook.com>
Co-authored-by: adams85 <31276480+adams85@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 2, 2024
1 parent 3769a53 commit 136f7ae
Show file tree
Hide file tree
Showing 113 changed files with 36,370 additions and 1,022 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,90 @@ jobs:
uses: ./.github/actions/cache-gradle
- name: Run format check
run: ./gradlew ktlintCheck --stacktrace
shell: bash

analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
- name: Cache Konan
uses: ./.github/actions/cache-konan
- name: Cache Gradle
uses: ./.github/actions/cache-gradle
- name: Run code analysis
run: ./gradlew detekt --stacktrace
shell: bash
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: build/reports/detekt/detekt.sarif
- name: Upload analysis report
uses: actions/upload-artifact@v4
with:
name: analysis-report
path: build/reports/detekt

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 11
distribution: zulu
- name: Cache Konan
uses: ./.github/actions/cache-konan
- name: Cache Gradle
uses: ./.github/actions/cache-gradle
- name: Calculate coverage
run: ./gradlew koverXmlReport --stacktrace
shell: bash
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: build/reports/kover

upload-reports:
needs: [ test, analysis, coverage, lint ]
runs-on: ubuntu-latest
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_NUMBER: ${{ github.run_number }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
- name: SonarCloud cache
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Konan
uses: ./.github/actions/cache-konan
- name: Cache Gradle
uses: ./.github/actions/cache-gradle
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: build/reports/kover
- name: Download analysis report
uses: actions/download-artifact@v4
with:
name: analysis-report
path: build/reports/detekt
- name: Upload reports to SonarCloud
run: ./gradlew sonarqube --stacktrace
shell: bash
15 changes: 13 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ kotlin {
nodejs {
testTask {
useMocha {
timeout = "10000"
timeout = "20000"
}
}
}
Expand Down Expand Up @@ -176,6 +176,13 @@ kotlin {
}
}

val darwinTest by creating {
dependsOn(commonTest)
dependencies {
implementation("io.ktor:ktor-client-darwin:$ktor_version")
}
}

val nativeMain by creating {
dependsOn(commonMain)
}
Expand All @@ -193,7 +200,11 @@ kotlin {
}

configure(nativeTestSets) {
dependsOn(nativeTest)
if (this.name.isDarwin()) {
dependsOn(darwinTest)
} else {
dependsOn(nativeTest)
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ style:
WildcardImport:
active: false
ReturnCount:
max: 8
max: 9
DestructuringDeclarationWithTooManyEntries:
maxDestructuringEntries: 5


complexity:
ComplexCondition:
threshold: 5
threshold: 11
TooManyFunctions:
thresholdInClasses: 22
thresholdInInterfaces: 17
LongMethod:
threshold: 70
LongParameterList:
constructorThreshold: 10
functionThreshold: 7
CyclomaticComplexMethod:
threshold: 17
NestedBlockDepth:
threshold: 10

exceptions:
TooGenericExceptionCaught:
Expand Down
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.configcat
version=2.1.0
version=3.0.0

ktor_version=2.0.3
kotlinx_serialization_version=1.4.1
Expand All @@ -17,4 +17,6 @@ kotlin.native.ignoreDisabledTargets=true
kotlin.mpp.stability.nowarn=true

kotlin.native.binary.memoryModel=experimental
org.gradle.jvmargs=-Xmx6g
org.gradle.jvmargs=-Xmx6g

kotlin.ignore.tcsm.overflow=true
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
3 changes: 2 additions & 1 deletion src/androidMain/kotlin/com/configcat/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class SharedPreferencesCache(context: Context) : ConfigCache {
private val sharedPreferences: SharedPreferences

init {
sharedPreferences = context.applicationContext.getSharedPreferences("configcat_preferences", Context.MODE_PRIVATE)
sharedPreferences =
context.applicationContext.getSharedPreferences("configcat_preferences", Context.MODE_PRIVATE)
}

override suspend fun read(key: String): String? = sharedPreferences.getString(key, null)
Expand Down
35 changes: 35 additions & 0 deletions src/androidMain/kotlin/com/configcat/NumberFormatter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.configcat

import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*
import kotlin.math.abs

internal actual fun doubleToString(doubleToString: Double): String {
// Handle Double.NaN, Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY
if (doubleToString.isNaN() || doubleToString.isInfinite()) {
return doubleToString.toString()
}

// To get similar result between different SDKs the Double value format is modified.
// Between 1e-6 and 1e21 we don't use scientific-notation. Over these limits scientific-notation used but the
// ExponentSeparator replaced with "e" and "e+".
// "." used as decimal separator in all cases.
val abs = abs(doubleToString)
val fmt =
if (1e-6 <= abs && abs < 1e21) DecimalFormat("#.#################") else DecimalFormat("#.#################E0")
val symbols = DecimalFormatSymbols.getInstance(Locale.UK)
if (abs > 1) {
symbols.exponentSeparator = "e+"
} else {
symbols.exponentSeparator = "e"
}
fmt.decimalFormatSymbols = symbols
return fmt.format(doubleToString)
}

internal actual fun formatDoubleForLog(doubleToFormat: Double): String {
val decimalFormat = DecimalFormat("0.#####")
decimalFormat.decimalFormatSymbols = DecimalFormatSymbols.getInstance(Locale.UK)
return decimalFormat.format(doubleToFormat)
}
10 changes: 10 additions & 0 deletions src/androidMain/kotlin/com/configcat/fetch/HttpRequestBuilder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.configcat.fetch

import io.ktor.client.request.*

internal actual fun httpRequestBuilder(
configCatUserAgent: String,
eTag: String
): HttpRequestBuilder {
return commonHttpRequestBuilder(configCatUserAgent, eTag)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.configcat.override

import com.configcat.model.Setting

internal actual fun convertToSetting(value: Any): Setting {
return commonConvertToSetting(value)
}
Loading

0 comments on commit 136f7ae

Please sign in to comment.