@appland/appmap 3.27.6 → 3.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/built/appmap.html +1 -1
- package/built/cmds/agentInstaller/agentInstallerProcedure.js +5 -5
- package/built/cmds/agentInstaller/agentInstallerProcedure.js.map +1 -1
- package/built/cmds/record/action/printAppMapCount.js +9 -15
- package/built/cmds/record/action/printAppMapCount.js.map +1 -1
- package/built/cmds/record/action/startTestCases.js +10 -6
- package/built/cmds/record/action/startTestCases.js.map +1 -1
- package/built/cmds/record/record.js +3 -2
- package/built/cmds/record/record.js.map +1 -1
- package/built/depends.js +37 -20
- package/built/depends.js.map +1 -1
- package/built/fingerprint/appmapIndex.js +156 -0
- package/built/fingerprint/appmapIndex.js.map +1 -0
- package/built/fingerprint/fingerprintQueue.js +13 -1
- package/built/fingerprint/fingerprintQueue.js.map +1 -1
- package/built/fingerprint/fingerprinter.js +41 -100
- package/built/fingerprint/fingerprinter.js.map +1 -1
- package/built/main.js.map +1 -1
- package/built/search/findEvents.js +9 -1
- package/built/search/findEvents.js.map +1 -1
- package/built/telemetry.js +1 -2
- package/built/telemetry.js.map +1 -1
- package/built/utils.js +26 -45
- package/built/utils.js.map +1 -1
- package/package.json +4 -5
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { createHash } = require('crypto');
|
|
3
|
-
const { join: joinPath } = require('path');
|
|
3
|
+
const { join: joinPath, basename } = require('path');
|
|
4
4
|
const fsp = require('fs').promises;
|
|
5
|
-
const semver = require('semver');
|
|
6
5
|
const { buildAppMap } = require('@appland/models');
|
|
7
|
-
const
|
|
6
|
+
const assert = require('assert');
|
|
8
7
|
const { default: FileTooLargeError } = require('./fileTooLargeError');
|
|
9
|
-
const { verbose,
|
|
8
|
+
const { verbose, mtime } = require('../utils');
|
|
10
9
|
const { algorithms, canonicalize } = require('./canonicalize');
|
|
10
|
+
const { default: AppMapIndex } = require('./appmapIndex');
|
|
11
11
|
/**
|
|
12
12
|
* CHANGELOG
|
|
13
13
|
*
|
|
14
|
+
* # 1.1.3
|
|
15
|
+
*
|
|
16
|
+
* * Removed ctime file. Use mtime to determine when the AppMap was last updated.
|
|
17
|
+
* * Use higher precision for mtime.
|
|
18
|
+
*
|
|
14
19
|
* # 1.1.2
|
|
15
20
|
*
|
|
16
|
-
* * Reject large appmaps
|
|
21
|
+
* * Reject large appmaps to avoid running out of system resources trying to process them.
|
|
17
22
|
*
|
|
18
23
|
* # 1.1.1
|
|
19
24
|
*
|
|
@@ -26,7 +31,7 @@ const { algorithms, canonicalize } = require('./canonicalize');
|
|
|
26
31
|
* * Fix handling of parent assignment in normalization.
|
|
27
32
|
* * sql can contain the analysis (action, tables, columns), and/or the normalized query string.
|
|
28
33
|
*/
|
|
29
|
-
const VERSION = '1.1.
|
|
34
|
+
const VERSION = '1.1.3';
|
|
30
35
|
const MAX_APPMAP_SIZE = 50 * 1000 * 1000;
|
|
31
36
|
class Fingerprinter {
|
|
32
37
|
/**
|
|
@@ -41,93 +46,28 @@ class Fingerprinter {
|
|
|
41
46
|
}
|
|
42
47
|
// eslint-disable-next-line class-methods-use-this
|
|
43
48
|
async fingerprint(appMapFileName) {
|
|
44
|
-
const appMapCreatedAt = await ctime(appMapFileName);
|
|
45
|
-
if (!appMapCreatedAt) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
49
|
if (verbose()) {
|
|
49
|
-
console.
|
|
50
|
+
console.log(`Fingerprinting ${appMapFileName}`);
|
|
50
51
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const versionFileName = joinPath(indexDir, 'version');
|
|
54
|
-
const versionUpToDate = async () => {
|
|
55
|
-
let versionStr = '0.0.1';
|
|
56
|
-
try {
|
|
57
|
-
versionStr = await fsp.readFile(versionFileName);
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
if (err.code !== 'ENOENT') {
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
versionStr = versionStr.toString().trim();
|
|
65
|
-
if (verbose()) {
|
|
66
|
-
console.warn(`${appMapFileName} index version is ${versionStr}`);
|
|
67
|
-
}
|
|
68
|
-
return semver.satisfies(versionStr, `>= ${VERSION}`);
|
|
69
|
-
};
|
|
70
|
-
const indexUpToDate = async () => {
|
|
71
|
-
let indexedAt = 0;
|
|
72
|
-
try {
|
|
73
|
-
const indexedAtStr = await fsp.readFile(mtimeFileName);
|
|
74
|
-
indexedAt = parseInt(indexedAtStr, 10);
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
if (err.code !== 'ENOENT') {
|
|
78
|
-
throw err;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (verbose()) {
|
|
82
|
-
console.warn(`${appMapFileName} created at ${appMapCreatedAt}, indexed at ${indexedAt}`);
|
|
83
|
-
}
|
|
84
|
-
return indexedAt >= appMapCreatedAt;
|
|
85
|
-
};
|
|
86
|
-
if ((await versionUpToDate()) && (await indexUpToDate())) {
|
|
87
|
-
if (verbose()) {
|
|
88
|
-
console.warn('Fingerprint is up to date. Skipping...');
|
|
89
|
-
}
|
|
52
|
+
const index = new AppMapIndex(appMapFileName);
|
|
53
|
+
if (!(await index.initialize())) {
|
|
90
54
|
return;
|
|
91
55
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (stat.size > MAX_APPMAP_SIZE)
|
|
95
|
-
throw new FileTooLargeError(appMapFileName, stat.size, MAX_APPMAP_SIZE);
|
|
96
|
-
}
|
|
97
|
-
let data;
|
|
98
|
-
try {
|
|
99
|
-
data = await fsp.readFile(appMapFileName);
|
|
100
|
-
}
|
|
101
|
-
catch (e) {
|
|
102
|
-
if (e.code !== 'ENOENT') {
|
|
103
|
-
console.warn(`${appMapFileName} does not exist. Skipping...`);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
throw e;
|
|
107
|
-
}
|
|
108
|
-
if (verbose()) {
|
|
109
|
-
console.warn(`Read ${data.length} bytes`);
|
|
110
|
-
}
|
|
111
|
-
let appmapData;
|
|
112
|
-
try {
|
|
113
|
-
// TODO: Should we normalize, compress, etc here?
|
|
114
|
-
appmapData = JSON.parse(data.toString());
|
|
115
|
-
}
|
|
116
|
-
catch (err) {
|
|
117
|
-
if (err instanceof SyntaxError) {
|
|
118
|
-
// File may be in the process of writing.
|
|
119
|
-
console.warn(`Error parsing JSON file ${appMapFileName} : ${err.message}`);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
throw err;
|
|
123
|
-
}
|
|
124
|
-
if (!appmapData.metadata) {
|
|
56
|
+
if ((await index.versionUpToDate(VERSION)) &&
|
|
57
|
+
(await index.indexUpToDate())) {
|
|
125
58
|
if (verbose()) {
|
|
126
|
-
console.
|
|
59
|
+
console.log('Fingerprint is up to date. Skipping...');
|
|
127
60
|
}
|
|
128
61
|
return;
|
|
129
62
|
}
|
|
130
|
-
|
|
63
|
+
if ((await index.appmapFileSize()) > MAX_APPMAP_SIZE)
|
|
64
|
+
throw new FileTooLargeError(appMapFileName, await index.appmapFileSize(), MAX_APPMAP_SIZE);
|
|
65
|
+
const appmapData = await index.loadAppMapData();
|
|
66
|
+
if (!appmapData)
|
|
67
|
+
return;
|
|
68
|
+
const appmapDataWithoutMetadata = await index.loadAppMapData();
|
|
69
|
+
if (!appmapDataWithoutMetadata)
|
|
70
|
+
return;
|
|
131
71
|
delete appmapDataWithoutMetadata.metadata;
|
|
132
72
|
const appmapDigest = createHash('sha256')
|
|
133
73
|
.update(JSON.stringify(appmapDataWithoutMetadata, null, 2))
|
|
@@ -135,19 +75,16 @@ class Fingerprinter {
|
|
|
135
75
|
const fingerprints = [];
|
|
136
76
|
appmapData.metadata.fingerprints = fingerprints;
|
|
137
77
|
const appmap = buildAppMap(appmapData).normalize().build();
|
|
138
|
-
await
|
|
78
|
+
await index.mkdir_p();
|
|
139
79
|
await Promise.all(Object.keys(algorithms).map(async (algorithmName) => {
|
|
140
80
|
const canonicalForm = canonicalize(algorithmName, appmap);
|
|
141
81
|
const canonicalJSON = JSON.stringify(canonicalForm, null, 2);
|
|
142
82
|
if (this.printCanonicalAppMaps) {
|
|
143
|
-
await writeFileAtomic(
|
|
83
|
+
await index.writeFileAtomic(`canonical.${algorithmName}.json`, canonicalJSON);
|
|
144
84
|
}
|
|
145
85
|
const fingerprintDigest = createHash('sha256')
|
|
146
86
|
.update(canonicalJSON)
|
|
147
87
|
.digest('hex');
|
|
148
|
-
if (verbose()) {
|
|
149
|
-
console.warn(`Computed digest for ${algorithmName}`);
|
|
150
|
-
}
|
|
151
88
|
fingerprints.push({
|
|
152
89
|
appmap_digest: appmapDigest,
|
|
153
90
|
canonicalization_algorithm: algorithmName,
|
|
@@ -156,16 +93,20 @@ class Fingerprinter {
|
|
|
156
93
|
});
|
|
157
94
|
}));
|
|
158
95
|
appmapData.metadata.fingerprints.sort((a, b) => a.canonicalization_algorithm.localeCompare(b.canonicalization_algorithm));
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
await
|
|
162
|
-
|
|
163
|
-
await
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
96
|
+
const tempAppMapFileName = joinPath(index.indexDir, [basename(appMapFileName), 'tmp'].join('.'));
|
|
97
|
+
await index.writeFileAtomic(basename(tempAppMapFileName), JSON.stringify(appmap, null, 2));
|
|
98
|
+
const appMapIndexedAt = await mtime(tempAppMapFileName);
|
|
99
|
+
assert(appMapIndexedAt, `${tempAppMapFileName} should always exist and be a readable file`);
|
|
100
|
+
await Promise.all([
|
|
101
|
+
index.writeFileAtomic('version', VERSION),
|
|
102
|
+
index.writeFileAtomic('classMap.json', JSON.stringify(appmap.classMap, null, 2)),
|
|
103
|
+
index.writeFileAtomic('metadata.json', JSON.stringify(appmap.metadata, null, 2)),
|
|
104
|
+
index.writeFileAtomic('mtime', `${appMapIndexedAt}`),
|
|
105
|
+
]);
|
|
106
|
+
// At this point, moving the AppMap file into place will trigger re-indexing.
|
|
107
|
+
// But the mtime will match the file modification time, so the algorithm will
|
|
108
|
+
// determine that the index is up-to-date.
|
|
109
|
+
await fsp.rename(tempAppMapFileName, appMapFileName, { overwrite: true });
|
|
169
110
|
this.counterFn();
|
|
170
111
|
}
|
|
171
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fingerprinter.js","sourceRoot":"","sources":["../../src/fingerprint/fingerprinter.js"],"names":[],"mappings":";AAAA,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACzC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"fingerprinter.js","sourceRoot":"","sources":["../../src/fingerprint/fingerprinter.js"],"names":[],"mappings":";AAAA,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACzC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;AACnC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAEtE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/C,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC/D,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CA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