Skip to content

Commit ee0dcd9

Browse files
[Monitor Ingestion] Browser gzipping using pako (Azure#22880)
1 parent 01df6ac commit ee0dcd9

File tree

11 files changed

+222
-587
lines changed

11 files changed

+222
-587
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 32 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/monitor/monitor-ingestion/CHANGELOG.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
# Release History
22

3-
## 1.0.0-beta.2 (Unreleased)
3+
## 1.0.0-beta.2 (2022-08-22)
44

55
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
12-
6+
- Added gzip support for browser
137
## 1.0.0-beta.1 (2022-07-19)
148

159
### Features Added

sdk/monitor/monitor-ingestion/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@
9292
"@azure/core-rest-pipeline": "^1.4.0",
9393
"@azure/core-tracing": "^1.0.0",
9494
"@azure/logger": "^1.0.0",
95-
"tslib": "^2.2.0"
95+
"tslib": "^2.2.0",
96+
"pako": "^2.0.4"
9697
},
9798
"devDependencies": {
99+
"@azure/core-util": "^1.0.0",
98100
"@azure-tools/test-credential": "~1.0.0",
99101
"@azure-tools/test-recorder": "^2.0.0",
100102
"@azure/dev-tool": "^1.0.0",
@@ -106,6 +108,7 @@
106108
"@types/chai": "^4.1.6",
107109
"@types/mocha": "^7.0.2",
108110
"@types/node": "^12.0.0",
111+
"@types/pako": "^2.0.0",
109112
"chai": "^4.2.0",
110113
"cross-env": "^7.0.2",
111114
"dotenv": "^8.2.0",

sdk/monitor/monitor-ingestion/recordings/browsers/logsingestionclient_live_tests/recording_partial_fail_test__when_dcr_id_is_incorrect_for_alternate_requests.json

Lines changed: 52 additions & 332 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/monitor/monitor-ingestion/recordings/browsers/logsingestionclient_live_tests/recording_sends_basic_data.json

Lines changed: 13 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/monitor/monitor-ingestion/recordings/browsers/logsingestionclient_live_tests/recording_success_test__divides_huge_data_into_chunks.json

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/monitor/monitor-ingestion/recordings/browsers/logsingestionclient_live_tests/recording_throws_error_when_all_logs_fail.json

Lines changed: 52 additions & 200 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/monitor/monitor-ingestion/src/gZippingPolicy.browser.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import { PipelinePolicy } from "@azure/core-rest-pipeline";
5-
5+
import * as pako from "pako";
66
/**
77
* Name of the {@link gZippingPolicy}
88
*/
@@ -11,7 +11,10 @@ export const gZippingPolicyName = "GzippingPolicyForBrowser";
1111
export const GZippingPolicy: PipelinePolicy = {
1212
name: gZippingPolicyName,
1313
sendRequest: async (req, next) => {
14-
// This is a no-op for now, will be implementing gzipping for browser using pako https://github.com/Azure/azure-sdk-for-js/issues/22593
14+
if (req.body) {
15+
const buffer = pako.gzip(String(req.body));
16+
req.body = buffer;
17+
}
1518
return next(req);
1619
},
1720
};

sdk/monitor/monitor-ingestion/src/utils/splitDataToChunksHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function splitDataToChunks(logs: Record<string, unknown>[]): Record<strin
1717
chunk.push(element);
1818
size += elementSize;
1919
} else {
20-
chunkArray.push(chunk);
20+
if (chunk.length) chunkArray.push(chunk);
2121
chunk = [element];
2222
size = elementSize;
2323
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { splitDataToChunks } from "../../src/utils/splitDataToChunksHelper";
5+
import { assert } from "chai";
6+
7+
describe("LogsIngestionClient unit tests", function () {
8+
it("creates one chunk for single log record of 1MB size", () => {
9+
const log = [
10+
{
11+
data: Array(1000000).fill("x").join(""),
12+
},
13+
];
14+
const chunkArray = splitDataToChunks(log);
15+
assert.equal(chunkArray.length, 1);
16+
assert.isNotEmpty(chunkArray[0]);
17+
assert.deepEqual(chunkArray[0], log);
18+
});
19+
20+
it("creates one chunk for single log record greater than 1MB size", () => {
21+
const log: Record<string, unknown>[] = [
22+
{
23+
data: Array(3000000).fill("x").join(""),
24+
},
25+
];
26+
const chunkArray = splitDataToChunks(log);
27+
assert.equal(chunkArray.length, 1);
28+
assert.isNotEmpty(chunkArray[0]);
29+
assert.deepEqual(chunkArray[0], log);
30+
});
31+
32+
it("creates two chunks for logs greater than 1MB size", () => {
33+
const log = [
34+
{
35+
data: Array(3000000).fill("x").join(""),
36+
},
37+
{
38+
data: Array(3000000).fill("x").join(""),
39+
},
40+
];
41+
const chunkArray = splitDataToChunks(log);
42+
assert.equal(chunkArray.length, 2);
43+
assert.deepEqual(chunkArray[0][0], log[0]);
44+
assert.deepEqual(chunkArray[1][0], log[1]);
45+
});
46+
});

0 commit comments

Comments
 (0)