From 3a9dc00629033474cac587bafd5cdb95ed01816c Mon Sep 17 00:00:00 2001 From: Konrad Pabjan Date: Thu, 30 Jul 2020 17:23:28 +0200 Subject: [PATCH] Better Artifact Telemetry + Increase Upload chunk size (#535) * Differentiate user-agents for better internal telemetry * Bump chunk size from 4 to 8 MB * Update User-Agent Strings --- packages/artifact/src/internal/config-variables.ts | 2 +- packages/artifact/src/internal/download-http-client.ts | 5 ++++- packages/artifact/src/internal/http-manager.ts | 8 +++++--- packages/artifact/src/internal/upload-http-client.ts | 5 ++++- packages/artifact/src/internal/utils.ts | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/artifact/src/internal/config-variables.ts b/packages/artifact/src/internal/config-variables.ts index 5cdfd2d9..1d25f6eb 100644 --- a/packages/artifact/src/internal/config-variables.ts +++ b/packages/artifact/src/internal/config-variables.ts @@ -6,7 +6,7 @@ export function getUploadFileConcurrency(): number { // When uploading large files that can't be uploaded with a single http call, this controls // the chunk size that is used during upload export function getUploadChunkSize(): number { - return 4 * 1024 * 1024 // 4 MB Chunks + return 8 * 1024 * 1024 // 8 MB Chunks } // The maximum number of retries that can be attempted before an upload or download fails diff --git a/packages/artifact/src/internal/download-http-client.ts b/packages/artifact/src/internal/download-http-client.ts index 4ddd76d5..70ea4e44 100644 --- a/packages/artifact/src/internal/download-http-client.ts +++ b/packages/artifact/src/internal/download-http-client.ts @@ -27,7 +27,10 @@ export class DownloadHttpClient { private statusReporter: StatusReporter constructor() { - this.downloadHttpManager = new HttpManager(getDownloadFileConcurrency()) + this.downloadHttpManager = new HttpManager( + getDownloadFileConcurrency(), + '@actions/artifact-download' + ) // downloads are usually significantly faster than uploads so display status information every second this.statusReporter = new StatusReporter(1000) } diff --git a/packages/artifact/src/internal/http-manager.ts b/packages/artifact/src/internal/http-manager.ts index 59bf26c1..9c19a620 100644 --- a/packages/artifact/src/internal/http-manager.ts +++ b/packages/artifact/src/internal/http-manager.ts @@ -6,12 +6,14 @@ import {createHttpClient} from './utils' */ export class HttpManager { private clients: HttpClient[] + private userAgent: string - constructor(clientCount: number) { + constructor(clientCount: number, userAgent: string) { if (clientCount < 1) { throw new Error('There must be at least one client') } - this.clients = new Array(clientCount).fill(createHttpClient()) + this.userAgent = userAgent + this.clients = new Array(clientCount).fill(createHttpClient(userAgent)) } getClient(index: number): HttpClient { @@ -22,7 +24,7 @@ export class HttpManager { // for more information see: https://github.com/actions/http-client/blob/04e5ad73cd3fd1f5610a32116b0759eddf6570d2/index.ts#L292 disposeAndReplaceClient(index: number): void { this.clients[index].dispose() - this.clients[index] = createHttpClient() + this.clients[index] = createHttpClient(this.userAgent) } disposeAndReplaceAllClients(): void { diff --git a/packages/artifact/src/internal/upload-http-client.ts b/packages/artifact/src/internal/upload-http-client.ts index 3733e1ae..66f1dc30 100644 --- a/packages/artifact/src/internal/upload-http-client.ts +++ b/packages/artifact/src/internal/upload-http-client.ts @@ -42,7 +42,10 @@ export class UploadHttpClient { private statusReporter: StatusReporter constructor() { - this.uploadHttpManager = new HttpManager(getUploadFileConcurrency()) + this.uploadHttpManager = new HttpManager( + getUploadFileConcurrency(), + '@actions/artifact-upload' + ) this.statusReporter = new StatusReporter(10000) } diff --git a/packages/artifact/src/internal/utils.ts b/packages/artifact/src/internal/utils.ts index 9f9109eb..93c22b66 100644 --- a/packages/artifact/src/internal/utils.ts +++ b/packages/artifact/src/internal/utils.ts @@ -204,8 +204,8 @@ export function getUploadHeaders( return requestOptions } -export function createHttpClient(): HttpClient { - return new HttpClient('actions/artifact', [ +export function createHttpClient(userAgent: string): HttpClient { + return new HttpClient(userAgent, [ new BearerCredentialHandler(getRuntimeToken()) ]) }