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