mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-18 05:02:24 +08:00
Revert "Telemetry: Add precedingUpgrade data to dev/build events"
This commit is contained in:
parent
6ae449f40a
commit
1da5b3d3cd
@ -5,7 +5,7 @@ import { dedent } from 'ts-dedent';
|
||||
import global from 'global';
|
||||
|
||||
import { logger } from '@storybook/node-logger';
|
||||
import { telemetry, getPrecedingUpgrade } from '@storybook/telemetry';
|
||||
import { telemetry } from '@storybook/telemetry';
|
||||
import type {
|
||||
BuilderOptions,
|
||||
CLIOptions,
|
||||
@ -173,14 +173,11 @@ export async function buildStaticStandalone(
|
||||
effects.push(
|
||||
initializedStoryIndexGenerator.then(async (generator) => {
|
||||
const storyIndex = await generator?.getIndex();
|
||||
const payload = {
|
||||
precedingUpgrade: await getPrecedingUpgrade('build'),
|
||||
};
|
||||
if (storyIndex) {
|
||||
Object.assign(payload, {
|
||||
storyIndex: summarizeIndex(storyIndex),
|
||||
});
|
||||
}
|
||||
const payload = storyIndex
|
||||
? {
|
||||
storyIndex: summarizeIndex(storyIndex),
|
||||
}
|
||||
: undefined;
|
||||
await telemetry('build', payload, { configDir: options.configDir });
|
||||
})
|
||||
);
|
||||
|
@ -11,7 +11,7 @@ import type {
|
||||
|
||||
import { normalizeStories, logConfig } from '@storybook/core-common';
|
||||
|
||||
import { telemetry, getPrecedingUpgrade } from '@storybook/telemetry';
|
||||
import { telemetry } from '@storybook/telemetry';
|
||||
import { getMiddleware } from './utils/middleware';
|
||||
import { getServerAddresses } from './utils/server-address';
|
||||
import { getServer } from './utils/server-init';
|
||||
@ -156,16 +156,12 @@ async function doTelemetry(
|
||||
initializedStoryIndexGenerator.then(async (generator) => {
|
||||
const storyIndex = await generator?.getIndex();
|
||||
const { versionCheck, versionUpdates } = options;
|
||||
const payload = {
|
||||
precedingUpgrade: await getPrecedingUpgrade('dev'),
|
||||
};
|
||||
if (storyIndex) {
|
||||
Object.assign(payload, {
|
||||
versionStatus: versionUpdates ? versionStatus(versionCheck) : 'disabled',
|
||||
storyIndex: summarizeIndex(storyIndex),
|
||||
});
|
||||
}
|
||||
|
||||
const payload = storyIndex
|
||||
? {
|
||||
versionStatus: versionUpdates ? versionStatus(versionCheck) : 'disabled',
|
||||
storyIndex: summarizeIndex(storyIndex),
|
||||
}
|
||||
: undefined;
|
||||
telemetry('dev', payload, { configDir: options.configDir });
|
||||
});
|
||||
}
|
||||
|
@ -1,146 +0,0 @@
|
||||
import { getPrecedingUpgrade } from './event-cache';
|
||||
|
||||
expect.addSnapshotSerializer({
|
||||
print: (val: any) => JSON.stringify(val, null, 2),
|
||||
test: (val) => typeof val !== 'string',
|
||||
});
|
||||
|
||||
describe('event-cache', () => {
|
||||
const init = { body: { eventType: 'init', eventId: 'init' }, timestamp: 1 };
|
||||
const upgrade = { body: { eventType: 'upgrade', eventId: 'upgrade' }, timestamp: 2 };
|
||||
const dev = { body: { eventType: 'dev', eventId: 'dev' }, timestamp: 3 };
|
||||
|
||||
describe('data handling', () => {
|
||||
it('errors', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', {
|
||||
init: { timestamp: 1, body: { ...init.body, error: {} } },
|
||||
});
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 1,
|
||||
"eventType": "init",
|
||||
"eventId": "init"
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('session IDs', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', {
|
||||
init: { timestamp: 1, body: { ...init.body, sessionId: 100 } },
|
||||
});
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 1,
|
||||
"eventType": "init",
|
||||
"eventId": "init",
|
||||
"sessionId": 100
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('extra fields', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', {
|
||||
init: { timestamp: 1, body: { ...init.body, foobar: 'baz' } },
|
||||
});
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 1,
|
||||
"eventType": "init",
|
||||
"eventId": "init"
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('no intervening dev events', () => {
|
||||
it('no upgrade events', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', {});
|
||||
expect(preceding).toBeUndefined();
|
||||
});
|
||||
|
||||
it('init', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', { init });
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 1,
|
||||
"eventType": "init",
|
||||
"eventId": "init"
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('upgrade', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', { upgrade });
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 2,
|
||||
"eventType": "upgrade",
|
||||
"eventId": "upgrade"
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('both init and upgrade', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', { init, upgrade });
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 2,
|
||||
"eventType": "upgrade",
|
||||
"eventId": "upgrade"
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('intervening dev events', () => {
|
||||
it('no upgrade events', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', { dev });
|
||||
expect(preceding).toBeUndefined();
|
||||
});
|
||||
|
||||
it('init', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', { init, dev });
|
||||
expect(preceding).toBeUndefined();
|
||||
});
|
||||
|
||||
it('upgrade', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', { upgrade, dev });
|
||||
expect(preceding).toBeUndefined();
|
||||
});
|
||||
|
||||
it('init followed by upgrade', async () => {
|
||||
const preceding = await getPrecedingUpgrade('dev', { init, upgrade, dev });
|
||||
expect(preceding).toBeUndefined();
|
||||
});
|
||||
|
||||
it('both init and upgrade with intervening dev', async () => {
|
||||
const secondUpgrade = {
|
||||
body: { eventType: 'upgrade', eventId: 'secondUpgrade' },
|
||||
timestamp: 4,
|
||||
};
|
||||
const preceding = await getPrecedingUpgrade('dev', { init, dev, upgrade: secondUpgrade });
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 4,
|
||||
"eventType": "upgrade",
|
||||
"eventId": "secondUpgrade"
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('both init and upgrade with non-intervening dev', async () => {
|
||||
const earlyDev = {
|
||||
body: { eventType: 'dev', eventId: 'earlyDev' },
|
||||
timestamp: -1,
|
||||
};
|
||||
const preceding = await getPrecedingUpgrade('dev', { dev: earlyDev, init, upgrade });
|
||||
expect(preceding).toMatchInlineSnapshot(`
|
||||
{
|
||||
"timestamp": 2,
|
||||
"eventType": "upgrade",
|
||||
"eventId": "upgrade"
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,39 +0,0 @@
|
||||
import { cache } from '@storybook/core-common';
|
||||
import type { EventType } from './types';
|
||||
|
||||
export const set = async (eventType: EventType, body: any) => {
|
||||
const lastEvents = (await cache.get('lastEvents')) || {};
|
||||
lastEvents[eventType] = { body, timestamp: Date.now() };
|
||||
await cache.set('lastEvents', lastEvents);
|
||||
};
|
||||
|
||||
export const get = async (eventType: EventType) => {
|
||||
const lastEvents = await cache.get('lastEvents');
|
||||
return lastEvents?.[eventType];
|
||||
};
|
||||
|
||||
const upgradeFields = (event: any) => {
|
||||
const { body, timestamp } = event;
|
||||
return {
|
||||
timestamp,
|
||||
eventType: body?.eventType,
|
||||
eventId: body?.eventId,
|
||||
sessionId: body?.sessionId,
|
||||
};
|
||||
};
|
||||
|
||||
export const getPrecedingUpgrade = async (eventType: EventType, events: any = undefined) => {
|
||||
const lastEvents = events || (await cache.get('lastEvents'));
|
||||
const init = lastEvents?.init;
|
||||
let precedingUpgrade = init;
|
||||
const upgrade = lastEvents?.upgrade;
|
||||
if (upgrade && (!precedingUpgrade || upgrade.timestamp > precedingUpgrade?.timestamp)) {
|
||||
precedingUpgrade = upgrade;
|
||||
}
|
||||
if (!precedingUpgrade) return undefined;
|
||||
|
||||
const lastEventOfType = lastEvents?.[eventType];
|
||||
return !lastEventOfType?.timestamp || precedingUpgrade.timestamp > lastEventOfType.timestamp
|
||||
? upgradeFields(precedingUpgrade)
|
||||
: undefined;
|
||||
};
|
@ -11,8 +11,6 @@ export * from './types';
|
||||
|
||||
export { getStorybookCoreVersion } from './package-json';
|
||||
|
||||
export { getPrecedingUpgrade } from './event-cache';
|
||||
|
||||
export const telemetry = async (
|
||||
eventType: EventType,
|
||||
payload: Payload = {},
|
||||
|
@ -3,7 +3,6 @@ import retry from 'fetch-retry';
|
||||
import { nanoid } from 'nanoid';
|
||||
import type { Options, TelemetryData } from './types';
|
||||
import { getAnonymousProjectId } from './anonymous-id';
|
||||
import { set as saveToCache } from './event-cache';
|
||||
|
||||
const URL = process.env.STORYBOOK_TELEMETRY_URL || 'https://storybook.js.org/event-log';
|
||||
|
||||
@ -25,7 +24,7 @@ export async function sendTelemetry(
|
||||
// the server actually gets the request and stores it anyway.
|
||||
|
||||
// flatten the data before we send it
|
||||
const { eventType, payload, metadata, ...rest } = data;
|
||||
const { payload, metadata, ...rest } = data;
|
||||
const context = options.stripMetadata
|
||||
? {}
|
||||
: {
|
||||
@ -33,9 +32,8 @@ export async function sendTelemetry(
|
||||
inCI: Boolean(process.env.CI),
|
||||
};
|
||||
const eventId = nanoid();
|
||||
const body = { ...rest, eventType, eventId, sessionId, metadata, payload, context };
|
||||
const body = { ...rest, eventId, sessionId, metadata, payload, context };
|
||||
let request: Promise<any>;
|
||||
let cache: Promise<any>;
|
||||
|
||||
try {
|
||||
request = fetch(URL, {
|
||||
@ -51,18 +49,15 @@ export async function sendTelemetry(
|
||||
: 1000),
|
||||
});
|
||||
tasks.push(request);
|
||||
cache = saveToCache(eventType, body);
|
||||
tasks.push(cache);
|
||||
|
||||
if (options.immediate) {
|
||||
await Promise.all(tasks);
|
||||
} else {
|
||||
await request;
|
||||
await cache;
|
||||
}
|
||||
} catch (err) {
|
||||
//
|
||||
} finally {
|
||||
tasks = tasks.filter((task) => task !== request && task !== cache);
|
||||
tasks = tasks.filter((task) => task !== request);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user