Skip to content

Commit bed4649

Browse files
author
Beatriz Rizental
authored
Merge pull request #988 from brizental/1742093-rate-limit-at-upload-time
Bug 1742093 - Refactor upload management logic to be exactly like in glean-core
2 parents 98e5e9a + ebd75b5 commit bed4649

File tree

17 files changed

+956
-602
lines changed

17 files changed

+956
-602
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.27.0...main)
44

55
* [#984](https://github.com/mozilla/glean.js/pull/984): BUGFIX: Return correct upload result in case an error happens while building a ping request.
6+
* [#988](https://github.com/mozilla/glean.js/pull/988): BUGFIX: Enforce rate limitation at upload time, not at ping submission time.
7+
* Note: This change required a big refactoring of the internal uploading logic.
68

79
# v0.27.0 (2021-11-22)
810

glean/src/core/glean.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { ConfigurationInterface } from "./config.js";
77
import { Configuration } from "./config.js";
88
import MetricsDatabase from "./metrics/database.js";
99
import PingsDatabase from "./pings/database.js";
10-
import PingUploader from "./upload/index.js";
10+
import PingUploadManager from "./upload/manager.js";
1111
import { isBoolean, isString, isUndefined, sanitizeApplicationId } from "./utils.js";
1212
import { CoreMetrics } from "./internal_metrics.js";
1313
import EventsDatabase from "./metrics/events_database/index.js";
@@ -39,7 +39,7 @@ class Glean {
3939
// The ping uploader. Note that we need to use the definite assignment assertion
4040
// because initialization will not happen in the constructor, but in the `initialize`
4141
// method.
42-
private _pingUploader!: PingUploader;
42+
private _pingUploader!: PingUploadManager;
4343
// The Glean configuration object.
4444
private _config!: Configuration;
4545

@@ -62,7 +62,7 @@ class Glean {
6262
return Glean._instance;
6363
}
6464

65-
private static get pingUploader(): PingUploader {
65+
private static get pingUploader(): PingUploadManager {
6666
return Glean.instance._pingUploader;
6767
}
6868

@@ -238,9 +238,7 @@ class Glean {
238238
Context.pingsDatabase = new PingsDatabase();
239239
Context.errorManager = new ErrorManager();
240240

241-
Glean.instance._pingUploader = new PingUploader(correctConfig, Context.pingsDatabase);
242-
243-
Context.pingsDatabase.attachObserver(Glean.pingUploader);
241+
Glean.instance._pingUploader = new PingUploadManager(correctConfig, Context.pingsDatabase);
244242

245243
if (config?.plugins) {
246244
for (const plugin of config.plugins) {
@@ -460,11 +458,11 @@ class Glean {
460458
static async shutdown(): Promise<void> {
461459
// Order here matters!
462460
//
463-
// The main dispatcher needs to be shut down first,
464-
// because some of its tasks may enqueue new tasks on the ping uploader dispatcher
461+
// The dispatcher needs to be shutdown first,
462+
// because some of its tasks may enqueue new pings to upload
465463
// and we want these uploading tasks to also be executed prior to complete shutdown.
466464
await Context.dispatcher.shutdown();
467-
await Glean.pingUploader.shutdown();
465+
await Glean.pingUploader.blockOnOngoingUploads();
468466
}
469467

470468
/**

0 commit comments

Comments
 (0)