Skip to content

Commit 5613013

Browse files
#RI-5724 add retries for data chatbot + disable flags + small fixes
1 parent 0a86eda commit 5613013

File tree

6 files changed

+54
-45
lines changed

6 files changed

+54
-45
lines changed

redisinsight/api/config/features-config.json

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 2.4602,
2+
"version": 2.4603,
33
"features": {
44
"insightsRecommendations": {
55
"flag": true,
@@ -47,28 +47,6 @@
4747
}
4848
}
4949
},
50-
"documentationChat": {
51-
"flag": true,
52-
"perc": [[0,100]],
53-
"filters": [
54-
{
55-
"name": "config.server.buildType",
56-
"value": "ELECTRON",
57-
"cond": "eq"
58-
}
59-
]
60-
},
61-
"databaseChat": {
62-
"flag": true,
63-
"perc": [[0,100]],
64-
"filters": [
65-
{
66-
"name": "config.server.buildType",
67-
"value": "ELECTRON",
68-
"cond": "eq"
69-
}
70-
]
71-
},
7250
"cloudSsoRecommendedSettings": {
7351
"flag": true,
7452
"perc": [[0, 100]],

redisinsight/api/src/modules/ai/query/ai-query.service.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class AiQueryService {
137137
index,
138138
);
139139

140-
if (!context) {
140+
if (!indexContext) {
141141
return cb(await this.aiQueryContextRepository.setIndexContext(
142142
sessionMetadata,
143143
databaseId,
@@ -193,23 +193,27 @@ export class AiQueryService {
193193
}
194194

195195
async getHistory(sessionMetadata: SessionMetadata, databaseId: string): Promise<AiQueryMessage[]> {
196-
try {
197-
const auth = await this.aiQueryAuthProvider.getAuthData(sessionMetadata);
198-
return await this.aiQueryMessageRepository.list(sessionMetadata, databaseId, auth.accountId);
199-
} catch (e) {
200-
throw wrapAiQueryError(e, 'Unable to get history');
201-
}
196+
return this.aiQueryAuthProvider.callWithAuthRetry(sessionMetadata, async () => {
197+
try {
198+
const auth = await this.aiQueryAuthProvider.getAuthData(sessionMetadata);
199+
return await this.aiQueryMessageRepository.list(sessionMetadata, databaseId, auth.accountId);
200+
} catch (e) {
201+
throw wrapAiQueryError(e, 'Unable to get history');
202+
}
203+
});
202204
}
203205

204206
async clearHistory(sessionMetadata: SessionMetadata, databaseId: string): Promise<void> {
205-
try {
206-
const auth = await this.aiQueryAuthProvider.getAuthData(sessionMetadata);
207+
return this.aiQueryAuthProvider.callWithAuthRetry(sessionMetadata, async () => {
208+
try {
209+
const auth = await this.aiQueryAuthProvider.getAuthData(sessionMetadata);
207210

208-
await this.aiQueryContextRepository.reset(sessionMetadata, databaseId, auth.accountId);
211+
await this.aiQueryContextRepository.reset(sessionMetadata, databaseId, auth.accountId);
209212

210-
return this.aiQueryMessageRepository.clearHistory(sessionMetadata, databaseId, auth.accountId);
211-
} catch (e) {
212-
throw wrapAiQueryError(e, 'Unable to clear history');
213-
}
213+
return this.aiQueryMessageRepository.clearHistory(sessionMetadata, databaseId, auth.accountId);
214+
} catch (e) {
215+
throw wrapAiQueryError(e, 'Unable to clear history');
216+
}
217+
});
214218
}
215219
}

redisinsight/api/src/modules/feature/feature.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('FeatureService', () => {
108108
await service.recalculateFeatureFlags();
109109

110110
expect(repository.delete)
111-
.toHaveBeenCalledWith(mockUnknownFeature);
111+
.toHaveBeenCalledWith(mockUnknownFeature.name);
112112
expect(repository.upsert)
113113
.toHaveBeenCalledWith({
114114
name: KnownFeatures.InsightsRecommendations,

redisinsight/api/src/modules/feature/feature.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class FeatureService {
112112
actions.toDelete = featuresFromDatabase.filter((feature) => !featuresConfig?.data?.features?.has?.(feature.name));
113113

114114
// delete features
115-
await Promise.all(actions.toDelete.map((feature) => this.repository.delete(feature)));
115+
await Promise.all(actions.toDelete.map((feature) => this.repository.delete(feature.name)));
116116
// upsert modified features
117117
await Promise.all(actions.toUpsert.map((feature) => this.repository.upsert(feature)));
118118

redisinsight/api/src/modules/feature/providers/feature-flag/strategies/switchable.flag.strategy.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('SwitchableFlagStrategy', () => {
6666
))
6767
.toEqual({
6868
name: KnownFeatures.DatabaseChat,
69-
flag: false,
69+
flag: expect.any(Boolean),
7070
});
7171

7272
expect(isInTargetRangeSpy).toHaveBeenCalled();
@@ -240,5 +240,30 @@ describe('SwitchableFlagStrategy', () => {
240240
expect(isInTargetRangeSpy).toHaveBeenCalled();
241241
expect(filterSpy).toHaveBeenCalled();
242242
});
243+
244+
it('should return flag:false even if feature force enabled but flag in config = false', async () => {
245+
isInTargetRangeSpy.mockReturnValueOnce(true);
246+
filterSpy.mockReturnValueOnce(true);
247+
mockedFs.readFile.mockResolvedValueOnce(JSON.stringify({
248+
features: {
249+
[KnownFeatures.DatabaseChat]: true,
250+
},
251+
}) as any);
252+
253+
expect(await service.calculate(
254+
knownFeatures[KnownFeatures.DatabaseChat],
255+
{
256+
perc: [[0, 100]],
257+
flag: false,
258+
},
259+
))
260+
.toEqual({
261+
name: KnownFeatures.DatabaseChat,
262+
flag: false,
263+
});
264+
265+
expect(isInTargetRangeSpy).toHaveBeenCalled();
266+
expect(filterSpy).toHaveBeenCalled();
267+
});
243268
});
244269
});

redisinsight/api/src/modules/feature/providers/feature-flag/strategies/switchable.flag.strategy.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import { IFeatureFlag } from 'src/modules/feature/constants';
55
export class SwitchableFlagStrategy extends FeatureFlagStrategy {
66
async calculate(knownFeature: IFeatureFlag, featureConfig: any): Promise<Feature> {
77
const isInRange = await this.isInTargetRange(featureConfig?.perc);
8-
const isInFilter = await this.filter(featureConfig?.filters) ? !!featureConfig.flag : !featureConfig?.flag;
9-
const force = (await FeatureFlagStrategy.getCustomConfig())?.[knownFeature.name];
8+
const isInFilter = await this.filter(featureConfig?.filters);
9+
const originalFlag = !!featureConfig?.flag;
10+
11+
let flag = (isInRange && isInFilter) ? originalFlag : !originalFlag;
1012

11-
let flag = isInRange && isInFilter;
13+
const force = (await FeatureFlagStrategy.getCustomConfig())?.[knownFeature.name];
1214

13-
if (isInFilter && force === true) {
15+
if (isInFilter && originalFlag && force === true) {
1416
flag = true;
15-
} else if (isInFilter && force === false) {
17+
} else if (isInFilter && originalFlag && force === false) {
1618
flag = false;
1719
}
1820

0 commit comments

Comments
 (0)