mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-13 13:48:59 +02:00
fix issues
This commit is contained in:
parent
2784c74f90
commit
a6c02222f1
@ -34,7 +34,7 @@ const mapRow = (row) => ({
|
||||
const mapToDb = (client) => ({
|
||||
app_name: client.appName,
|
||||
instance_id: client.instanceId,
|
||||
sdk_version: client.sdkVersion || '',
|
||||
sdk_version: client.sdkVersion,
|
||||
sdk_type: client.sdkType,
|
||||
client_ip: client.clientIp,
|
||||
last_seen: client.lastSeen || 'now()',
|
||||
@ -74,7 +74,12 @@ export default class ClientInstanceStore implements IClientInstanceStore {
|
||||
async bulkUpsert(instances: INewClientInstance[]): Promise<void> {
|
||||
const stopTimer = this.metricTimer('bulkUpsert');
|
||||
|
||||
const rows = instances.map(mapToDb);
|
||||
const rows = instances.map((i) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(mapToDb(i)).filter(([, v]) => v !== undefined),
|
||||
),
|
||||
);
|
||||
|
||||
await this.db(TABLE)
|
||||
.insert(rows)
|
||||
.onConflict(['app_name', 'instance_id', 'environment'])
|
||||
|
@ -36,12 +36,14 @@ import type { OutdatedSdksSchema } from '../../../openapi/spec/outdated-sdks-sch
|
||||
import { CLIENT_REGISTERED } from '../../../metric-events.js';
|
||||
import { NotFoundError } from '../../../error/index.js';
|
||||
|
||||
type ClientData = IClientApp & { lastSeen?: Date };
|
||||
|
||||
export default class ClientInstanceService {
|
||||
apps = {};
|
||||
|
||||
logger: Logger;
|
||||
|
||||
seenClients: Record<string, IClientApp> = {};
|
||||
seenClients: Record<string, ClientData> = {};
|
||||
|
||||
private clientMetricsStoreV2: IClientMetricsStoreV2;
|
||||
|
||||
@ -99,24 +101,32 @@ export default class ClientInstanceService {
|
||||
);
|
||||
}
|
||||
|
||||
private updateSeenClient = (data: ClientData) => {
|
||||
const current = this.seenClients[this.clientKey(data)];
|
||||
this.seenClients[this.clientKey(data)] = {
|
||||
...current,
|
||||
...data,
|
||||
};
|
||||
};
|
||||
|
||||
public async registerInstance(
|
||||
data: PartialSome<IClientApp, 'instanceId'>,
|
||||
clientIp: string,
|
||||
): Promise<void> {
|
||||
const value = await clientMetricsSchema.validateAsync(data);
|
||||
|
||||
this.seenClients[this.clientKey(value)] = {
|
||||
this.updateSeenClient({
|
||||
appName: value.appName,
|
||||
instanceId: value.instanceId,
|
||||
environment: value.environment,
|
||||
clientIp: clientIp,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public registerFrontendClient(data: IFrontendClientApp): void {
|
||||
data.createdBy = SYSTEM_USER.username!;
|
||||
|
||||
this.seenClients[this.clientKey(data)] = data;
|
||||
this.updateSeenClient(data);
|
||||
}
|
||||
|
||||
public async registerBackendClient(
|
||||
@ -127,7 +137,7 @@ export default class ClientInstanceService {
|
||||
value.clientIp = clientIp;
|
||||
value.createdBy = SYSTEM_USER.username!;
|
||||
value.sdkType = 'backend';
|
||||
this.seenClients[this.clientKey(value)] = value;
|
||||
this.updateSeenClient(value);
|
||||
this.eventBus.emit(CLIENT_REGISTERED, value);
|
||||
|
||||
if (value.sdkVersion && value.sdkVersion.indexOf(':') > -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user