Skip to content

Commit

Permalink
Merge pull request #2293 from evidence-dev/next
Browse files Browse the repository at this point in the history
Release 2024-08-01
  • Loading branch information
hughess authored Aug 1, 2024
2 parents cf626d5 + 9598743 commit f860ef4
Show file tree
Hide file tree
Showing 47 changed files with 602 additions and 140 deletions.
11 changes: 11 additions & 0 deletions .changeset/calm-tigers-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@evidence-dev/evidence': patch
'@evidence-dev/plugin-connector': patch
'@evidence-dev/preprocess': patch
'@evidence-dev/sdk': patch
'@evidence-dev/core-components': patch
'@evidence-dev/faker-datasource': patch
'@evidence-dev/tailwind': patch
---

Override fast-xml-parser version to >=4.4.1 to resolve vulnerability
5 changes: 5 additions & 0 deletions .changeset/healthy-spoons-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/telemetry': patch
---

Fixes issue causing sources to hang after running
5 changes: 5 additions & 0 deletions .changeset/mighty-chefs-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/core-components': patch
---

Adds option to disable downloads for data and/or images from charts
5 changes: 5 additions & 0 deletions .changeset/popular-poets-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/evidence': patch
---

Increase node memory limit to 4GB
5 changes: 5 additions & 0 deletions .changeset/rich-ears-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/telemetry': patch
---

Add handling for blank profiles
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"undici@<5.19.1": ">=5.19.1",
"undici@>=2.0.0 <5.19.1": ">=5.19.1",
"jsonwebtoken@<9.0.0": ">=9.0.0",
"nth-check@<2.0.1": ">=2.0.1"
"nth-check@<2.0.1": ">=2.0.1",
"fast-xml-parser": ">=4.4.1"
}
}
}
3 changes: 1 addition & 2 deletions packages/datasources/mssql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"evidence": {
"datasources": [
"mssql"
],
"icon": "Microsoftsqlserver"
]
},
"keywords": [
"evidence",
Expand Down
11 changes: 11 additions & 0 deletions packages/evidence/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { logQueryEvent } from '@evidence-dev/telemetry';

import { loadEnv } from 'vite';

const increaseNodeMemoryLimit = () => {
// Don't override the memory limit if it's already set
if (process.env.NODE_OPTIONS?.includes('--max-old-space-size')) return;
process.env.NODE_OPTIONS = `${process.env.NODE_OPTIONS || ''} --max-old-space-size=4096`;
};

const loadEnvFile = () => {
const envFile = loadEnv('', '.', ['EVIDENCE_']);
Object.assign(process.env, envFile);
Expand Down Expand Up @@ -193,6 +199,7 @@ prog
.option('--debug', 'Enables verbose console logs')
.describe('launch the local evidence development environment')
.action((args) => {
increaseNodeMemoryLimit();
if (args.debug) {
process.env.VITE_EVIDENCE_DEBUG = true;
delete args.debug;
Expand Down Expand Up @@ -248,6 +255,7 @@ prog
.option('--include-values', 'Includes Environment Variable Values, this will show secrets!')
.describe('Prints out Evidence variables from the environment and .env file')
.action((args) => {
increaseNodeMemoryLimit();
const { 'include-values': includeValues } = args;
loadEnvFile();
const evidenceVars = Object.fromEntries(
Expand All @@ -265,6 +273,7 @@ prog
.option('--debug', 'Enables verbose console logs')
.describe('build production outputs')
.action((args) => {
increaseNodeMemoryLimit();
if (args.debug) {
process.env.VITE_EVIDENCE_DEBUG = true;
delete args.debug;
Expand All @@ -281,6 +290,7 @@ prog
.option('--debug', 'Enables verbose console logs')
.describe('build production outputs and fails on error')
.action((args) => {
increaseNodeMemoryLimit();
if (args.debug) {
process.env.VITE_EVIDENCE_DEBUG = true;
delete args.debug;
Expand Down Expand Up @@ -338,6 +348,7 @@ prog
.command('preview')
.describe('preview the production build')
.action((args) => {
increaseNodeMemoryLimit();
if (args.debug) {
process.env.VITE_EVIDENCE_DEBUG = true;
delete args.debug;
Expand Down
72 changes: 48 additions & 24 deletions packages/lib/telemetry/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,34 @@ const LEGACY_PROFILES_PATH = './.profile.json';

/**
* @typedef {'usageStatsDisabled' |
* 'db-plugin-unvailable' |
* 'db-connection-error' |
* 'db-connection-success' |
* 'source-connector-not-found' |
* 'db-error' |
* 'db-query'|
* 'cache-query' |
* 'dev-server-start' |
* 'build-start' |
* 'build-strict-start' |
* 'build-sources-start' |
* 'preview-server-start'
* } TelemetryEventName
* 'db-plugin-unvailable' |
* 'db-connection-error' |
* 'db-connection-success' |
* 'source-connector-not-found' |
* 'db-error' |
* 'db-query'|
* 'cache-query' |
* 'dev-server-start' |
* 'build-start' |
* 'build-strict-start' |
* 'build-sources-start' |
* 'preview-server-start'
* } TelemetryEventName
*/

/**
* @typedef {Object} Traits
* @property {Date} projectCreated
*/

/**
* @typedef {Object} Profile
* @property {string} anonymousId
* @property {Traits} traits
*/

const initializeProfile = async () => {
/** @type {Profile} */
const projectProfile = {
anonymousId: secure.v4(),
traits: {
Expand All @@ -40,16 +53,27 @@ const initializeProfile = async () => {

const getProfile = async () => {
if (!pathExistsSync(PROFILES_PATH) && !maybeMigrateProfile()) {
const profile = await initializeProfile();
return profile;
// Profile file doesn't exist and migration wasn't needed, initialize it
return await initializeProfile();
} else {
let profile = readJSONSync(PROFILES_PATH);
try {
/** @type {Profile | null} */
let profile = readJSONSync(PROFILES_PATH, { throws: false });

if (
!profile ||
!profile.anonymousId ||
profile.anonymousId === 'b958769d-6b88-43f3-978a-b970a146ffd2'
) {
profile = await initializeProfile();
}

if (profile.anonymousId === 'b958769d-6b88-43f3-978a-b970a146ffd2') {
// This anon ID was incorrectly committed to the template project, replace with a fresh ID going forward
profile = await initializeProfile();
return profile;
} catch (error) {
console.error('Error in getProfile:', error instanceof Error ? error.message : error);
// Initialize a new profile in case of errors
return await initializeProfile();
}
return profile;
}
};

Expand All @@ -71,7 +95,7 @@ const logEvent = async (
queryName = undefined
) => {
try {
let usageStats = settings
const usageStats = settings
? (settings.send_anonymous_usage_stats ?? 'yes')
: (process.env['SEND_ANONYMOUS_USAGE_STATS'] ??
process.env['send_anonymous_usage_stats'] ??
Expand Down Expand Up @@ -110,7 +134,7 @@ const logEvent = async (

if (usageStats === 'yes') {
const projectProfile = await getProfile();
const analytics = new Analytics({ writeKey: wK });
const analytics = new Analytics({ writeKey: wK, flushAt: 1 });
const payload = {
anonymousId: projectProfile.anonymousId,
event: eventName,
Expand All @@ -137,7 +161,7 @@ const logEvent = async (
};

/**
* Logs an event emiited from source queries
* Logs an event emitted from source queries
* @param {TelemetryEventName} eventName
* @param {string | undefined} [databaseName]
* @param {string | undefined} [sourceName]
Expand All @@ -163,7 +187,7 @@ function loadSettings() {
}

/**
* Checks for existance of legacy profile and then moves it to the new location
* Checks for existence of legacy profile and then moves it to the new location
* @returns {boolean} true if profile was migrated
*/
function maybeMigrateProfile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
renderer: {
control: 'options',
options: ['canvas', 'svg']
},
downloadableData: {
control: 'boolean',
options: [true, false]
},
downloadableImage: {
control: 'boolean',
options: [true, false]
}
}
};
Expand Down Expand Up @@ -243,3 +251,16 @@ LIMIT 200`,
{@const emptySet = []}
<AreaChart data={emptySet} {...args} />
</Story>

<Story
name="Non-downloadable"
args={{
x: 'departure_date',
y: 'total_fare',
downloadableData: false,
downloadableImage: false
}}
let:args
>
<AreaChart data={planeData} {...args} />
</Story>
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
export let emptyMessage = undefined;
export let renderer = undefined;
export let downloadableData = undefined;
export let downloadableImage = undefined;
export let seriesColors = undefined;
export let connectGroup = undefined;
Expand Down Expand Up @@ -116,6 +118,8 @@
{emptySet}
{emptyMessage}
{renderer}
{downloadableData}
{downloadableImage}
{connectGroup}
{seriesColors}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
seriesLabels: {
type: 'boolean',
control: { type: 'boolean' }
},
downloadableData: {
control: 'boolean',
options: [true, false]
},
downloadableImage: {
control: 'boolean',
options: [true, false]
}
},
args: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
export let emptyMessage = undefined;
export let renderer = undefined;
export let downloadableData = undefined;
export let downloadableImage = undefined;
export let seriesColors = undefined;
export let connectGroup = undefined;
Expand Down Expand Up @@ -167,6 +169,8 @@
{emptySet}
{emptyMessage}
{renderer}
{downloadableData}
{downloadableImage}
{connectGroup}
{seriesColors}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
control: 'select',
options: ['canvas', 'svg']
},
downloadableData: {
control: 'boolean',
options: [true, false]
},
downloadableImage: {
control: 'boolean',
options: [true, false]
},
eChartsOptions: {
control: 'object'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
export let seriesOptions = undefined;
export let printEchartsConfig = false;
export let renderer = undefined;
export let downloadableData = undefined;
export let downloadableImage = undefined;
export let connectGroup = undefined;
Expand Down Expand Up @@ -107,6 +109,8 @@
{emptySet}
{emptyMessage}
{renderer}
{downloadableData}
{downloadableImage}
{connectGroup}
{seriesColors}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@
control: 'select',
options: ['canvas', 'svg']
},
downloadableData: {
control: 'boolean',
options: [true, false]
},
downloadableImage: {
control: 'boolean',
options: [true, false]
},
echartsOptions: {
control: 'object'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
export let emptyMessage = undefined;
export let renderer = undefined;
export let downloadableData = undefined;
export let downloadableImage = undefined;
export let seriesColors = undefined;
export let connectGroup = undefined;
Expand Down Expand Up @@ -105,6 +107,8 @@
{emptySet}
{emptyMessage}
{renderer}
{downloadableData}
{downloadableImage}
{connectGroup}
{seriesColors}
>
Expand Down
Loading

0 comments on commit f860ef4

Please sign in to comment.