Skip to content

Commit

Permalink
Fix serving rollout strategies in party-server-ish and edge-rest. Fix…
Browse files Browse the repository at this point in the history
… accessing flags/values when set first time (#638)

* Cleaning up logs, minor test changes

* Minor cleanup, final testing for fixing #544

* Fix issue with party-server-ish not supporting strategies

Fixes issue #639
  • Loading branch information
rvowles authored Jan 10, 2022
1 parent 455427e commit c3efbac
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion adks/e2e-sdk/app/steps/flag_steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Then(/^the feature flag is (locked|unlocked) and (off|on)$/, async function (loc
// logger.info('the feature %s is value %s and locked status %s', this.feature.key, f.valueBoolean, f.locked);
expect(f.getBoolean()).to.eq(value === 'on');
expect(f.isLocked()).to.eq(lockedStatus === 'locked');
}, 2000, 200);
}, 4000, 500);
});

When(/^I (unlock|lock) the feature$/, async function (lockUnlock) {
Expand Down
1 change: 1 addition & 0 deletions adks/e2e-sdk/app/steps/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Given(/^I connect to the feature server$/, function () {
expect(found).to.be.true;
logger.info('Successfully completed poll');
const edge = new EdgeFeatureHubConfig(world.featureUrl, serviceAccountPerm.sdkUrlClientEval);
//edge.edgeServiceProvider((repo, config) => new FeatureHubPollingClient(repo, config, 200));
edge.init();
world.edgeServer = edge;
// give it time to connect
Expand Down
4 changes: 2 additions & 2 deletions adks/e2e-sdk/app/support/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { makeid } from './random';
import { expect } from 'chai';
import { SdkWorld } from './world';

// const superuserEmailAddress = 'irina@i.com';
const superuserEmailAddress = 'superuser@mailinator.com';
const superuserEmailAddress = 'irina@i.com';
// const superuserEmailAddress = 'superuser@mailinator.com';
const superuserPassword = 'password123';

async function ensureLoggedIn(world: SdkWorld) {
Expand Down
4 changes: 2 additions & 2 deletions adks/e2e-sdk/app/support/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class SdkWorld extends World {
constructor(props) {
super(props);

this.adminUrl = process.env.FEATUREHUB_HOST || 'http://localhost:8903';
this.featureUrl = process.env.FEATUREHUB_SDK_HOST || 'http://localhost:8903';
this.adminUrl = process.env.FEATUREHUB_HOST || 'http://localhost:8085';
this.featureUrl = process.env.FEATUREHUB_SDK_HOST || 'http://localhost:8085';

this.adminApiConfig = new Configuration({ basePath: this.adminUrl, apiKey: apiKey });
this.portfolioApi = new PortfolioServiceApi(this.adminApiConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void updateFeatureValue(PublishFeatureValue fv) {

private void receivedNewFeatureForExistingEnvironmentFeatureCache(PublishFeatureValue fv, EnvironmentFeatures featureMap) {
if (fv.getAction() == PublishAction.CREATE) {
log.info("received brand new feature `{}` for a new environment `{}`",
log.trace("received brand new feature `{}` for a new environment `{}`",
fv.getFeature().getFeature().getKey(),
fv.getEnvironmentId());
featureMap.set(fv.getFeature());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.featurehub.mr.model.*
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.*
import java.util.stream.Collectors

class DbDachaSqlApi : DachaApiKeyService {
private val log: Logger = LoggerFactory.getLogger(DbDachaSqlApi::class.java)
Expand Down Expand Up @@ -104,9 +105,34 @@ class DbDachaSqlApi : DachaApiKeyService {
else -> fv.value(null)
}

if (dbFeature.rolloutStrategies != null) {
fv.rolloutStrategies(dbFeature.rolloutStrategies.map { fromRolloutStrategy(it) })
} else {
fv.rolloutStrategies(listOf())
}


return fv
}

private fun fromRolloutStrategy(rs: RolloutStrategy): CacheRolloutStrategy {
return CacheRolloutStrategy()
.id(rs.id ?: "rs-id")
.percentage(rs.percentage)
.percentageAttributes(rs.percentageAttributes)
.value(rs.value)
.attributes(if (rs.attributes == null) ArrayList() else rs.attributes!!
.stream().map { rsa: RolloutStrategyAttribute -> fromRolloutStrategyAttribute(rsa) }
.collect(Collectors.toList()))
}

private fun fromRolloutStrategyAttribute(rsa: RolloutStrategyAttribute): CacheRolloutStrategyAttribute {
return CacheRolloutStrategyAttribute()
.conditional(rsa.conditional!!)
.values(rsa.values)
.fieldName(rsa.fieldName!!)
.type(rsa.type!!)
}

private fun calculateEtag(details: DachaKeyDetailsResponse): String {
val det =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private FeatureValue onlyCreateFeatureValueForEnvironment(UUID eid, String key,
updateFeatureValue(featureValue, person, dbFeatureValue);

save(dbFeatureValue);
publish(dbFeatureValue);

return convertUtils.toFeatureValue(dbFeatureValue);
} else {
Expand All @@ -143,7 +144,10 @@ private FeatureValue onlyCreateFeatureValueForEnvironment(UUID eid, String key,
@Transactional
private void save(DbFeatureValue featureValue) {
database.save(featureValue);
}

private void publish(DbFeatureValue featureValue) {
log.trace("publishing update for {}", featureValue);
cacheSource.publishFeatureChange(featureValue);
}

Expand Down Expand Up @@ -176,6 +180,7 @@ private FeatureValue onlyUpdateFeatureValueForEnvironment(FeatureValue featureVa
updateFeatureValue(featureValue, person, strategy);

save(strategy);
publish(strategy);

return convertUtils.toFeatureValue(strategy);
}
Expand Down Expand Up @@ -366,6 +371,7 @@ public void updateFeature(String sdkUrl, UUID eid, String featureKey, boolean up

// API can never change strategies
save(fv);
publish(fv);
}

static class EnvironmentsAndStrategies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ open class DbCacheSource @Inject constructor(private val convertUtils: Conversio
if (cacheName != null) {
val cacheBroadcast = cacheBroadcasters[cacheName]
if (cacheBroadcast != null) {
log.info("publishing environment {} ({})", environment.name, environment.id)
log.trace("publishing environment {} ({})", environment.name, environment.id)
val environmentCacheItem = fillEnvironmentCacheItem(
environmentsByCacheName(cacheName).findCount(),
environment,
Expand Down
3 changes: 2 additions & 1 deletion e2e/lib/superuser_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class SuperuserCommon {
PortfolioServiceApi get portfolioService => _portfolioServiceApi;
ApplicationServiceApi get applicationService => _applicationServiceApi;

String get initUser => "superuser@mailinator.com";
// String get initUser => "irina@i.com";
String get initUser => "irina@i.com";
String get initPassword => "password123";
String? get superuserGroupId => _superuser?.groups
.firstWhere((g) => g.admin == true && g.portfolioId == null)
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/features/feature_values.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Create feature values
When I create the feature with a key "<featureKey>" and alias "<alias>" and name "<featureName>" and link "<link>" and type "boolean"
And I can find the feature with a key "<featureKey>"
# add superuser and regular user to the group to they have feature permissions
When I add the user "superuser@mailinator.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
When I add the user "irina@i.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
When I add the user "seb@mailinator.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
When I can login as user "seb@mailinator.com" with password "password123"
And I unlock the feature value for environment "<envName>" for feature "<featureKey>"
Expand Down Expand Up @@ -92,7 +92,7 @@ Feature: Create feature values
And I ensure that the feature with the key "<featureKey>" has been removed
When I create the feature with a key "<featureKey>" and alias "<alias>" and name "<featureName>" and link "<link>" and type "boolean"
And I can find the feature with a key "<featureKey>"
When I add the user "superuser@mailinator.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
When I add the user "irina@i.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
And I unlock the feature value for environment "<envName>" for feature "<featureKey>"
And I unlock the feature value for environment "<envName2>" for feature "<featureKey>"
And I set the boolean feature value as "true" for environment "<envName>" for feature "<featureKey>"
Expand Down
8 changes: 4 additions & 4 deletions e2e/test/features/persona_acls.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Create some personas with different feature access data
Given I ensure a portfolio named "<portfolio>" with description "persona test" exists
And the first superuser is used for authentication
When I ensure a portfolio "<portfolio>" has created a group called "<group>"
When I add the user "superuser@mailinator.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
When I add the user "irina@i.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
Given I ensure an application with the name "<appName>" with description "<appDesc>" in the portfolio "<portfolio>" exists
And I ensure that an environment "<envName>" with description "<envDesc>" exists in the app "<appName>" in the portfolio "<portfolio>"
And I ensure that an environment "<envName2>" with description "<envDesc2>" exists in the app "<appName>" in the portfolio "<portfolio>"
Expand Down Expand Up @@ -57,7 +57,7 @@ Feature: Create some personas with different feature access data
Given I ensure a portfolio named "<portfolio>" with description "persona test" exists
And the first superuser is used for authentication
When I ensure a portfolio "<portfolio>" has created a group called "<group>"
When I add the user "superuser@mailinator.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
When I add the user "irina@i.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
Given I ensure an application with the name "<appName>" with description "<appDesc>" in the portfolio "<portfolio>" exists
And I ensure that an environment "<envName>" with description "<envDesc>" exists in the app "<appName>" in the portfolio "<portfolio>"
And I ensure that an environment "<envName2>" with description "<envDesc2>" exists in the app "<appName>" in the portfolio "<portfolio>"
Expand Down Expand Up @@ -91,7 +91,7 @@ Feature: Create some personas with different feature access data
And the first superuser is used for authentication
When I ensure a portfolio "<portfolio>" has created a group called "<groupA>"
When I ensure a portfolio "<portfolio>" has created a group called "<groupB>"
When I add the user "superuser@mailinator.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
When I add the user "irina@i.com" to the group "<adminGroup>" in the portfolio "<portfolio>"
Given I ensure an application with the name "<appName>" with description "<appDesc>" in the portfolio "<portfolio>" exists
And I ensure that an environment "<envName>" with description "<envDesc>" exists in the app "<appName>" in the portfolio "<portfolio>"
And I ensure that the feature with the key "<featureKey>" has been removed
Expand Down Expand Up @@ -126,7 +126,7 @@ Feature: Create some personas with different feature access data
And I ensure that the feature with the key "<featureKey>" has been removed
When I create the feature with a key "<featureKey>" and alias "<alias>" and name "<featureName>" and link "<link>" and type "boolean"
And I can find the feature with a key "<featureKey>"
When I add the user "superuser@mailinator.com" to the group "<group1>" in the portfolio "<portfolio>"
When I add the user "irina@i.com" to the group "<group1>" in the portfolio "<portfolio>"
And I unlock the feature value for environment "<envName>" for feature "<featureKey>"
And I unlock the feature value for environment "<envName2>" for feature "<featureKey>"
And I set the boolean feature value as "true" for environment "<envName>" for feature "<featureKey>"
Expand Down

0 comments on commit c3efbac

Please sign in to comment.