Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(proto): reduce proto configSettings to minimum needed #6424

Merged
merged 3 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lighthouse-core/lib/proto-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ function processForProto(result) {
const reportJson = JSON.parse(result);

// Clean up the configSettings
// Note: This is not strictly required for conversion if protobuf parsing is set to
// 'ignore unknown fields' in the language of conversion.
exterkamp marked this conversation as resolved.
Show resolved Hide resolved
if (reportJson.configSettings) {
// make sure the 'output' field is an array
if (reportJson.configSettings.output) {
if (!Array.isArray(reportJson.configSettings.output)) {
reportJson.configSettings.output = [reportJson.configSettings.output];
}
}
// Filter out unwanted fields
exterkamp marked this conversation as resolved.
Show resolved Hide resolved
const valid = ['emulatedFormFactor', 'locale', 'onlyCategories'];

const minifiedSettings = Object.keys(reportJson.configSettings)
.filter(key => valid.includes(key))
.reduce((obj, key) => {
// @ts-ignore
exterkamp marked this conversation as resolved.
Show resolved Hide resolved
obj[key] = reportJson.configSettings[key];
return obj;
}, {});

// @ts-ignore
reportJson.configSettings = minifiedSettings;
}

// Remove runtimeError if it is NO_ERROR
Expand Down
33 changes: 28 additions & 5 deletions lighthouse-core/test/lib/proto-preprocessor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,40 @@ const processForProto = require('../../lib/proto-preprocessor').processForProto;

/* eslint-env jest */
describe('processing for proto', () => {
it('cleans up configSettings', () => {
it('keeps only necessary configSettings', () => {
const input = {
'configSettings': {
'output': 'json',
'output': [
'json',
],
'maxWaitForLoad': 45000,
'throttlingMethod': 'devtools',
'throttling': {
'rttMs': 150,
'throughputKbps': 1638.4,
'requestLatencyMs': 562.5,
'downloadThroughputKbps': 1474.5600000000002,
'uploadThroughputKbps': 675,
'cpuSlowdownMultiplier': 4,
},
'gatherMode': false,
'disableStorageReset': false,
'disableDeviceEmulation': false,
'emulatedFormFactor': 'mobile',
'locale': 'en-US',
'blockedUrlPatterns': null,
'additionalTraceCategories': null,
'extraHeaders': null,
'onlyAudits': null,
'onlyCategories': null,
'skipAudits': null,
},
};
const expectation = {
'configSettings': {
'output': [
'json',
],
'emulatedFormFactor': 'mobile',
'locale': 'en-US',
'onlyCategories': null,
},
};
const output = processForProto(JSON.stringify(input));
Expand Down
86 changes: 3 additions & 83 deletions proto/lighthouse-result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -111,64 +111,6 @@ message LighthouseResult {

// Message containing the configuration settings for the LH run
message ConfigSettings {
// The output types the audit made (json, html...)
repeated string output = 1;

// The maximum amount of time to wait for loading in ms
google.protobuf.DoubleValue max_wait_for_load = 2;

// Network throttling options
enum ThrottlingMethod {
// Unknown method. Should not be used
UNKNOWN_THROTTLING_METHOD = 0;

// Use devtools to throttle the request
devtools = 1;

// Use no additional throttling (only throttling provided by system
// itself)
provided = 2;

// Simulate throttling with Lantern
simulate = 3;
}

// The throttling method used during this audit
ThrottlingMethod throttling_method = 3;

// Message containing the throttling settings used in an LH configuration
message Throttling {
// The round trip time in ms
google.protobuf.DoubleValue rtt_ms = 1;

// The throughput in kilobytes per second
google.protobuf.DoubleValue throughput_kbps = 2;

// The request latency in milliseconds
google.protobuf.DoubleValue request_latency_ms = 3;

// The download throughput in kilobytes per second
google.protobuf.DoubleValue download_throughput_kbps = 4;

// The upload throughput in kilobytes per second
google.protobuf.DoubleValue upload_throughput_kbps = 5;

// The amount of slowdown to apply to the cpu
google.protobuf.DoubleValue cpu_slowdown_multiplier = 6;
}

// The throttling settings used
Throttling throttling = 4;

// Flag indicating this audit was gather only or not
google.protobuf.BoolValue gather_mode = 5;

// Flag disabling clearing the browser cache before runs
google.protobuf.BoolValue disable_storage_reset = 6;

// Flag indicating if device emulation was enabled or not
google.protobuf.BoolValue disable_device_emulation = 7;

// The possible form factors an audit can be run in
enum EmulatedFormFactor {
// Unknown form factor. This should not be used
Expand All @@ -185,36 +127,14 @@ message LighthouseResult {
}

// The form factor used in the audit
EmulatedFormFactor emulated_form_factor = 8;
EmulatedFormFactor emulated_form_factor = 1;
exterkamp marked this conversation as resolved.
Show resolved Hide resolved

// The locale that was active during the audit
string locale = 9;

// List of URL patterns that were blocked during this audit
// nullable list of strings
google.protobuf.Value blocked_url_patterns = 10;

// Comma delimited list of trace categories to capture
// nullable string
google.protobuf.Value additional_trace_categories = 11;

// Map of extra HTTP Headers to pass in with the request
google.protobuf.Value extra_headers = 12;

// List of the audits that were preformed, empty if all were run
// nullable list of strings
google.protobuf.Value only_audits = 13;
string locale = 2;

// List of the categories that were run, empty if all were run
// nullable list of strings
google.protobuf.Value only_categories = 14;

// List of the audits that were skipped, empty if all were run
// nullable list of strings
google.protobuf.Value skip_audits = 15;

// Flag indicating whether this Lighthouse run was audit-only
google.protobuf.BoolValue audit_mode = 16;
google.protobuf.Value only_categories = 3;
}

// The settings that were used to run this audit
Expand Down
23 changes: 1 addition & 22 deletions proto/sample_v2_round_trip.json
Original file line number Diff line number Diff line change
Expand Up @@ -3245,30 +3245,9 @@
}
},
"configSettings": {
"additionalTraceCategories": null,
"blockedUrlPatterns": null,
"disableDeviceEmulation": false,
"disableStorageReset": false,
"emulatedFormFactor": "mobile",
"extraHeaders": null,
"gatherMode": false,
"locale": "en-US",
"maxWaitForLoad": 45000.0,
"onlyAudits": null,
"onlyCategories": null,
"output": [
"json"
],
"skipAudits": null,
"throttling": {
"cpuSlowdownMultiplier": 4.0,
"downloadThroughputKbps": 1474.5600000000002,
"requestLatencyMs": 562.5,
"rttMs": 150.0,
"throughputKbps": 1638.4,
"uploadThroughputKbps": 675.0
},
"throttlingMethod": "devtools"
"onlyCategories": null
},
"environment": {
"benchmarkIndex": 1000.0,
Expand Down