Skip to content

chore: address lint issues #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
252a958
init targeting evaluator with str comp
Kavindu-Dodan Oct 26, 2023
ad8f179
complete fractional op
Kavindu-Dodan Oct 27, 2023
6730553
first version of fractional op
Kavindu-Dodan Oct 27, 2023
84c6eec
improve error handling
Kavindu-Dodan Oct 30, 2023
711eb8d
review changes
Kavindu-Dodan Oct 31, 2023
c4de635
review changes
Kavindu-Dodan Nov 1, 2023
e631c6d
initialize in-process basics
Kavindu-Dodan Nov 1, 2023
4437e4e
more basic logic
Kavindu-Dodan Nov 1, 2023
7a463cb
fix rebase
Kavindu-Dodan Nov 2, 2023
3ae1e10
refactor internals with abstractions
Kavindu-Dodan Nov 2, 2023
c61388a
complete sync basics
Kavindu-Dodan Nov 2, 2023
3f152e6
finalize connection todo tests
Kavindu-Dodan Nov 3, 2023
017c5c4
fix status checks
Kavindu-Dodan Nov 3, 2023
894f518
test for grpc fetch
Kavindu-Dodan Nov 3, 2023
98b2a66
service level test
Kavindu-Dodan Nov 3, 2023
e796434
tests and docs
Kavindu-Dodan Nov 3, 2023
a491abb
update package lock
Kavindu-Dodan Nov 6, 2023
4e36d50
fix dependency issue on e2e tests
Kavindu-Dodan Nov 6, 2023
a4ec710
review changes
Kavindu-Dodan Nov 13, 2023
454e08b
review changes
Kavindu-Dodan Nov 13, 2023
68e2d46
fix rebase conflicts
Kavindu-Dodan Nov 13, 2023
2a5268f
Update libs/providers/flagd/README.md
Kavindu-Dodan Nov 13, 2023
f2c6933
Update libs/providers/flagd/README.md
toddbaert Nov 13, 2023
e7fa43d
Update libs/providers/flagd/src/lib/flagd-provider.ts
Kavindu-Dodan Nov 13, 2023
b74b2b1
fixed linting issues
beeme1mr Nov 14, 2023
a3b2b7f
Apply suggestions from code review
beeme1mr Nov 14, 2023
d199450
fixed linting issues
beeme1mr Nov 14, 2023
3563ae9
Merge branch 'main' into fix-lint-issues
beeme1mr Nov 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/hooks/open-telemetry/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './lib/traces';
export * from './lib/metrics';
export * from './lib/metrics';
6 changes: 3 additions & 3 deletions libs/hooks/open-telemetry/src/lib/conventions.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// see: https://opentelemetry.io/docs/specs/otel/logs/semantic_conventions/feature-flags/
export const FEATURE_FLAG = 'feature_flag';
export const EXCEPTION_ATTR = 'exception'
export const EXCEPTION_ATTR = 'exception';

export const ACTIVE_COUNT_NAME = `${FEATURE_FLAG}.evaluation_active_count`;
export const REQUESTS_TOTAL_NAME = `${FEATURE_FLAG}.evaluation_requests_total`;
export const SUCCESS_TOTAL_NAME = `${FEATURE_FLAG}.evaluation_success_total`;
export const ERROR_TOTAL_NAME = `${FEATURE_FLAG}.evaluation_error_total`;

export type EvaluationAttributes = {[key: `${typeof FEATURE_FLAG}.${string}`]: string | undefined };
export type EvaluationAttributes = { [key: `${typeof FEATURE_FLAG}.${string}`]: string | undefined };
export type ExceptionAttributes = { [EXCEPTION_ATTR]: string };

export const KEY_ATTR: keyof EvaluationAttributes = `${FEATURE_FLAG}.key`;
export const PROVIDER_NAME_ATTR: keyof EvaluationAttributes = `${FEATURE_FLAG}.provider_name`;
export const VARIANT_ATTR: keyof EvaluationAttributes = `${FEATURE_FLAG}.variant`;
export const REASON_ATTR: keyof EvaluationAttributes = `${FEATURE_FLAG}.reason`;
export const REASON_ATTR: keyof EvaluationAttributes = `${FEATURE_FLAG}.reason`;
2 changes: 1 addition & 1 deletion libs/hooks/open-telemetry/src/lib/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './metrics-hook';
export * from './metrics-hook';
11 changes: 7 additions & 4 deletions libs/hooks/open-telemetry/src/lib/metrics/metrics-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type EvaluationDetails,
type FlagValue,
type Hook,
type HookContext
type HookContext,
} from '@openfeature/server-sdk';
import { Attributes, Counter, UpDownCounter, ValueType, metrics } from '@opentelemetry/api';
import {
Expand All @@ -19,7 +19,7 @@ import {
REASON_ATTR,
REQUESTS_TOTAL_NAME,
SUCCESS_TOTAL_NAME,
VARIANT_ATTR
VARIANT_ATTR,
} from '../conventions';
import { OpenTelemetryHook, OpenTelemetryHookOptions } from '../otel-hook';

Expand All @@ -36,7 +36,7 @@ const ERROR_DESCRIPTION = 'feature flag evaluation error counter';

/**
* A hook that adds conventionally-compliant metrics to feature flag evaluations.
*
*
* See {@link https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/feature-flags/}
*/
export class MetricsHook extends OpenTelemetryHook implements Hook {
Expand All @@ -46,7 +46,10 @@ export class MetricsHook extends OpenTelemetryHook implements Hook {
private readonly evaluationSuccessCounter: Counter<EvaluationAttributes | Attributes>;
private readonly evaluationErrorCounter: Counter<ErrorEvaluationAttributes>;

constructor(options?: MetricsHookOptions, private readonly logger?: Logger) {
constructor(
options?: MetricsHookOptions,
private readonly logger?: Logger,
) {
super(options, logger);
const meter = metrics.getMeter(METER_NAME);
this.evaluationActiveUpDownCounter = meter.createUpDownCounter(ACTIVE_COUNT_NAME, {
Expand Down
2 changes: 1 addition & 1 deletion libs/hooks/open-telemetry/src/lib/traces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './tracing-hook';
export * from './tracing-hook';
28 changes: 13 additions & 15 deletions libs/hooks/open-telemetry/src/lib/traces/tracing-hook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,47 @@ describe('OpenTelemetry Hooks', () => {
variant: 'enabled',
flagMetadata: {},
};

tracingHook.after(hookContext, evaluationDetails);

expect(addEvent).toBeCalledWith('feature_flag', {
'feature_flag.key': 'testFlagKey',
'feature_flag.provider_name': 'testProvider',
'feature_flag.variant': 'enabled',
});
});

it('should use a stringified value as the variant value on the span event', () => {
const evaluationDetails: EvaluationDetails<boolean> = {
flagKey: hookContext.flagKey,
value: true,
flagMetadata: {},
};

tracingHook.after(hookContext, evaluationDetails);

expect(addEvent).toBeCalledWith('feature_flag', {
'feature_flag.key': 'testFlagKey',
'feature_flag.provider_name': 'testProvider',
'feature_flag.variant': 'true',
});
});

it('should set the value without extra quotes if value is already a string', () => {
const evaluationDetails: EvaluationDetails<string> = {
flagKey: hookContext.flagKey,
value: 'already-string',
flagMetadata: {},
};
tracingHook.after(hookContext, evaluationDetails);

expect(addEvent).toBeCalledWith('feature_flag', {
'feature_flag.key': 'testFlagKey',
'feature_flag.provider_name': 'testProvider',
'feature_flag.variant': 'already-string',
});
});

it('should not call addEvent because there is no active span', () => {
getActiveSpan.mockReturnValueOnce(undefined);
const evaluationDetails: EvaluationDetails<boolean> = {
Expand All @@ -100,15 +100,14 @@ describe('OpenTelemetry Hooks', () => {
variant: 'enabled',
flagMetadata: {},
};

tracingHook.after(hookContext, evaluationDetails);
expect(addEvent).not.toBeCalled();
});
});

describe('attribute mapper configured', () => {
describe('no error in mapper', () => {

beforeEach(() => {
tracingHook = new TracingHook({
attributeMapper: (flagMetadata) => {
Expand All @@ -132,9 +131,9 @@ describe('OpenTelemetry Hooks', () => {
metadata3: true,
},
};

tracingHook.after(hookContext, evaluationDetails);

expect(addEvent).toBeCalledWith('feature_flag', {
'feature_flag.key': 'testFlagKey',
'feature_flag.provider_name': 'testProvider',
Expand All @@ -147,7 +146,6 @@ describe('OpenTelemetry Hooks', () => {
});

describe('error in mapper', () => {

beforeEach(() => {
tracingHook = new TracingHook({
attributeMapper: (_) => {
Expand All @@ -167,9 +165,9 @@ describe('OpenTelemetry Hooks', () => {
metadata3: true,
},
};

tracingHook.after(hookContext, evaluationDetails);

expect(addEvent).toBeCalledWith('feature_flag', {
'feature_flag.key': 'testFlagKey',
'feature_flag.provider_name': 'testProvider',
Expand Down
2 changes: 1 addition & 1 deletion libs/hooks/open-telemetry/src/lib/traces/tracing-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type TracingHookOptions = OpenTelemetryHookOptions;

/**
* A hook that adds conventionally-compliant span events to feature flag evaluations.
*
*
* See {@link https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/feature-flags/}
*/
export class TracingHook extends OpenTelemetryHook implements Hook {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('ConfigCatProvider', () => {

it('should throw TypeMismatchError if type is different than expected', async () => {
await expect(provider.resolveBooleanEvaluation('number1', false, { targetingKey })).rejects.toThrow(
TypeMismatchError
TypeMismatchError,
);
});
});
Expand All @@ -183,7 +183,7 @@ describe('ConfigCatProvider', () => {

it('should throw TypeMismatchError if type is different than expected', async () => {
await expect(provider.resolveStringEvaluation('number1', 'default', { targetingKey })).rejects.toThrow(
TypeMismatchError
TypeMismatchError,
);
});
});
Expand All @@ -201,7 +201,7 @@ describe('ConfigCatProvider', () => {

it('should throw TypeMismatchError if type is different than expected', async () => {
await expect(provider.resolveNumberEvaluation('stringTest', 0, { targetingKey })).rejects.toThrow(
TypeMismatchError
TypeMismatchError,
);
});
});
Expand All @@ -223,7 +223,7 @@ describe('ConfigCatProvider', () => {

it('should throw TypeMismatchError if string is only a JSON primitive', async () => {
await expect(provider.resolveObjectEvaluation('jsonPrimitive', {}, { targetingKey })).rejects.toThrow(
TypeMismatchError
TypeMismatchError,
);
});
});
Expand Down
20 changes: 10 additions & 10 deletions libs/providers/config-cat/src/lib/config-cat-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ConfigCatProvider implements Provider {
hooks.on('configChanged', (projectConfig: IConfig | undefined) =>
this.events.emit(ProviderEvents.ConfigurationChanged, {
flagsChanged: projectConfig ? Object.keys(projectConfig.settings) : undefined,
})
}),
);

hooks.on('clientError', (message: string, error) => {
Expand All @@ -90,7 +90,7 @@ export class ConfigCatProvider implements Provider {
async resolveBooleanEvaluation(
flagKey: string,
defaultValue: boolean,
context: EvaluationContext
context: EvaluationContext,
): Promise<ResolutionDetails<boolean>> {
if (!this._client) {
throw new GeneralError('Provider is not initialized');
Expand All @@ -99,7 +99,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync<SettingValue>(
flagKey,
undefined,
transformContext(context)
transformContext(context),
);

const validatedValue = validateFlagType('boolean', value);
Expand All @@ -112,7 +112,7 @@ export class ConfigCatProvider implements Provider {
public async resolveStringEvaluation(
flagKey: string,
defaultValue: string,
context: EvaluationContext
context: EvaluationContext,
): Promise<ResolutionDetails<string>> {
if (!this._client) {
throw new GeneralError('Provider is not initialized');
Expand All @@ -121,7 +121,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync<SettingValue>(
flagKey,
undefined,
transformContext(context)
transformContext(context),
);

const validatedValue = validateFlagType('string', value);
Expand All @@ -134,7 +134,7 @@ export class ConfigCatProvider implements Provider {
public async resolveNumberEvaluation(
flagKey: string,
defaultValue: number,
context: EvaluationContext
context: EvaluationContext,
): Promise<ResolutionDetails<number>> {
if (!this._client) {
throw new GeneralError('Provider is not initialized');
Expand All @@ -143,7 +143,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync<SettingValue>(
flagKey,
undefined,
transformContext(context)
transformContext(context),
);

const validatedValue = validateFlagType('number', value);
Expand All @@ -156,7 +156,7 @@ export class ConfigCatProvider implements Provider {
public async resolveObjectEvaluation<U extends JsonValue>(
flagKey: string,
defaultValue: U,
context: EvaluationContext
context: EvaluationContext,
): Promise<ResolutionDetails<U>> {
if (!this._client) {
throw new GeneralError('Provider is not initialized');
Expand All @@ -165,7 +165,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync(
flagKey,
undefined,
transformContext(context)
transformContext(context),
);

if (typeof value === 'undefined') {
Expand Down Expand Up @@ -197,7 +197,7 @@ export class ConfigCatProvider implements Provider {
function toResolutionDetails<U extends JsonValue>(
value: U,
data: Omit<IEvaluationDetails, 'value'>,
reason?: ResolutionReason
reason?: ResolutionReason,
): ResolutionDetails<U> {
const matchedRule = Boolean(data.matchedEvaluationRule || data.matchedEvaluationPercentageRule);
const evaluatedReason = matchedRule ? StandardResolutionReasons.TARGETING_MATCH : StandardResolutionReasons.STATIC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('context-transformer', () => {
expect(() => transformContext(context)).toThrow(TargetingKeyMissingError);
});


it('map targeting key to identifier', () => {
const context: EvaluationContext = {
targetingKey: 'test',
Expand Down Expand Up @@ -126,8 +125,8 @@ describe('context-transformer', () => {
it('map several custom properties correctly', () => {
const context: EvaluationContext = {
targetingKey: 'test',
email: "email",
country: "country",
email: 'email',
country: 'country',
customString: 'customString',
customNumber: 1,
customBoolean: true,
Expand All @@ -140,8 +139,8 @@ describe('context-transformer', () => {

const user = {
identifier: 'test',
email: "email",
country: "country",
email: 'email',
country: 'country',
custom: {
customString: 'customString',
customBoolean: 'true',
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/env-var/src/lib/env-var-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class EnvVarProvider implements Provider {

private evaluateEnvironmentVariable<T extends JsonValue>(
key: string,
parse: (value: string) => T
parse: (value: string) => T,
): ResolutionDetails<T> {
const envVarKey = this.options.disableConstantCase ? key : constantCase(key);
const value = process.env[envVarKey];
Expand Down
4 changes: 2 additions & 2 deletions libs/providers/flagd-web/src/e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default {
displayName: 'providers-flagd-web-e2e',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsConfig: './tsconfig.lib.json'}],
'^.+\\.[tj]s$': ['ts-jest', { tsConfig: './tsconfig.lib.json' }],
},
testEnvironment: 'node',
preset: 'ts-jest',
clearMocks: true,
setupFiles: ['./setup.ts'],
verbose: true,
silent: false,
};
};
16 changes: 9 additions & 7 deletions libs/providers/flagd-web/src/e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ const FLAGD_WEB_NAME = 'flagd-web';

// register the flagd provider before the tests.
console.log('Setting flagd web provider...');
OpenFeature.setProvider(new FlagdWebProvider({
host: 'localhost',
port: 8013,
tls: false,
maxRetries: -1,
}));
OpenFeature.setProvider(
new FlagdWebProvider({
host: 'localhost',
port: 8013,
tls: false,
maxRetries: -1,
}),
);
assert(
OpenFeature.providerMetadata.name === FLAGD_WEB_NAME,
new Error(`Expected ${FLAGD_WEB_NAME} provider to be configured, instead got: ${OpenFeature.providerMetadata.name}`)
new Error(`Expected ${FLAGD_WEB_NAME} provider to be configured, instead got: ${OpenFeature.providerMetadata.name}`),
);
console.log('flagd web provider configured!');
Loading