Skip to content

Commit

Permalink
[8.12] [Fleet] show download rate in upgrade details tooltlip (#173614)…
Browse files Browse the repository at this point in the history
… (#173651)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Fleet] show download rate in upgrade details tooltlip
(#173614)](#173614)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Bardi","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-19T15:07:25Z","message":"[Fleet]
show download rate in upgrade details tooltlip (#173614)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/171943\r\n\r\nShowing download
rate in the upgrade details tooltip.\r\n\r\nUsed fake data as I couldn't
get an actual agent to be in downloading\r\nstate with download percent
and rate.\r\n\r\n<img width=\"659\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/90178898/1488fa7f-b003-4d5a-a98a-27fcc8a4c70c\">\r\n\r\n\r\nInsert
test ES data with curl and go to Agent list/details to see
the\r\ntooltip, replace `existing_agent_id` with an existing agent's id
or\r\ninsert a full agent doc.\r\n```\r\ncurl -sk -XPOST --user
elastic:changeme -H 'content-type:application/json'
\\\r\nhttp://localhost:9200/_security/role/fleet_superuser -d '\r\n
{\r\n \"indices\": [\r\n {\r\n \"names\":
[\".fleet*\",\".kibana*\"],\r\n \"privileges\": [\"all\"],\r\n
\"allow_restricted_indices\": true\r\n }\r\n ]\r\n }'\r\n\r\ncurl -sk
-XPOST --user elastic:changeme -H 'content-type:application/json'
\\\r\nhttp://localhost:9200/_security/user/fleet_superuser -d '\r\n
{\r\n \"password\": \"password\",\r\n \"roles\": [\"superuser\",
\"fleet_superuser\"]\r\n }'\r\n\r\n curl -sk -XPOST --user
fleet_superuser:password -H 'content-type:application/json' \\\r\n
-H'x-elastic-product-origin:fleet' \\\r\n
http://localhost:9200/.fleet-agents/_update_by_query -d '\r\n {\r\n
\"script\": {\r\n \"source\": \"ctx._source.upgrade_details.state =
\\\"UPG_DOWNLOADING\\\";
ctx._source.upgrade_details.metadata.download_percent = 22;
ctx._source.upgrade_details.metadata.download_rate = 1223912;\",\r\n
\"lang\": \"painless\"\r\n },\r\n \"query\": {\r\n \"term\": {\r\n
\"agent.id\":\"existing_agent_id\"\r\n }\r\n }\r\n
}'\r\n\r\n```\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"b9d3c8611876632c587ca854125315c6a5c303bb","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.12.0","v8.13.0"],"number":173614,"url":"https://github.com/elastic/kibana/pull/173614","mergeCommit":{"message":"[Fleet]
show download rate in upgrade details tooltlip (#173614)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/171943\r\n\r\nShowing download
rate in the upgrade details tooltip.\r\n\r\nUsed fake data as I couldn't
get an actual agent to be in downloading\r\nstate with download percent
and rate.\r\n\r\n<img width=\"659\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/90178898/1488fa7f-b003-4d5a-a98a-27fcc8a4c70c\">\r\n\r\n\r\nInsert
test ES data with curl and go to Agent list/details to see
the\r\ntooltip, replace `existing_agent_id` with an existing agent's id
or\r\ninsert a full agent doc.\r\n```\r\ncurl -sk -XPOST --user
elastic:changeme -H 'content-type:application/json'
\\\r\nhttp://localhost:9200/_security/role/fleet_superuser -d '\r\n
{\r\n \"indices\": [\r\n {\r\n \"names\":
[\".fleet*\",\".kibana*\"],\r\n \"privileges\": [\"all\"],\r\n
\"allow_restricted_indices\": true\r\n }\r\n ]\r\n }'\r\n\r\ncurl -sk
-XPOST --user elastic:changeme -H 'content-type:application/json'
\\\r\nhttp://localhost:9200/_security/user/fleet_superuser -d '\r\n
{\r\n \"password\": \"password\",\r\n \"roles\": [\"superuser\",
\"fleet_superuser\"]\r\n }'\r\n\r\n curl -sk -XPOST --user
fleet_superuser:password -H 'content-type:application/json' \\\r\n
-H'x-elastic-product-origin:fleet' \\\r\n
http://localhost:9200/.fleet-agents/_update_by_query -d '\r\n {\r\n
\"script\": {\r\n \"source\": \"ctx._source.upgrade_details.state =
\\\"UPG_DOWNLOADING\\\";
ctx._source.upgrade_details.metadata.download_percent = 22;
ctx._source.upgrade_details.metadata.download_rate = 1223912;\",\r\n
\"lang\": \"painless\"\r\n },\r\n \"query\": {\r\n \"term\": {\r\n
\"agent.id\":\"existing_agent_id\"\r\n }\r\n }\r\n
}'\r\n\r\n```\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"b9d3c8611876632c587ca854125315c6a5c303bb"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/173614","number":173614,"mergeCommit":{"message":"[Fleet]
show download rate in upgrade details tooltlip (#173614)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/171943\r\n\r\nShowing download
rate in the upgrade details tooltip.\r\n\r\nUsed fake data as I couldn't
get an actual agent to be in downloading\r\nstate with download percent
and rate.\r\n\r\n<img width=\"659\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/90178898/1488fa7f-b003-4d5a-a98a-27fcc8a4c70c\">\r\n\r\n\r\nInsert
test ES data with curl and go to Agent list/details to see
the\r\ntooltip, replace `existing_agent_id` with an existing agent's id
or\r\ninsert a full agent doc.\r\n```\r\ncurl -sk -XPOST --user
elastic:changeme -H 'content-type:application/json'
\\\r\nhttp://localhost:9200/_security/role/fleet_superuser -d '\r\n
{\r\n \"indices\": [\r\n {\r\n \"names\":
[\".fleet*\",\".kibana*\"],\r\n \"privileges\": [\"all\"],\r\n
\"allow_restricted_indices\": true\r\n }\r\n ]\r\n }'\r\n\r\ncurl -sk
-XPOST --user elastic:changeme -H 'content-type:application/json'
\\\r\nhttp://localhost:9200/_security/user/fleet_superuser -d '\r\n
{\r\n \"password\": \"password\",\r\n \"roles\": [\"superuser\",
\"fleet_superuser\"]\r\n }'\r\n\r\n curl -sk -XPOST --user
fleet_superuser:password -H 'content-type:application/json' \\\r\n
-H'x-elastic-product-origin:fleet' \\\r\n
http://localhost:9200/.fleet-agents/_update_by_query -d '\r\n {\r\n
\"script\": {\r\n \"source\": \"ctx._source.upgrade_details.state =
\\\"UPG_DOWNLOADING\\\";
ctx._source.upgrade_details.metadata.download_percent = 22;
ctx._source.upgrade_details.metadata.download_rate = 1223912;\",\r\n
\"lang\": \"painless\"\r\n },\r\n \"query\": {\r\n \"term\": {\r\n
\"agent.id\":\"existing_agent_id\"\r\n }\r\n }\r\n
}'\r\n\r\n```\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"b9d3c8611876632c587ca854125315c6a5c303bb"}}]}]
BACKPORT-->

Co-authored-by: Julia Bardi <[email protected]>
Co-authored-by: Julien Lind <[email protected]>
  • Loading branch information
3 people authored Dec 21, 2023
1 parent a7e9015 commit 93588d5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export interface AgentUpgradeDetails {
metadata?: {
scheduled_at?: string;
download_percent?: number;
download_rate?: number; // bytes per second
failed_state?: AgentUpgradeStateType;
error_msg?: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,38 @@ describe('getDownloadEstimate', () => {
expect(getDownloadEstimate()).toEqual('');
});

it('should return an empty string if the agent has a zero download percent', () => {
expect(getDownloadEstimate(0)).toEqual('');
it('should display 0% if the agent has a zero download percent', () => {
expect(getDownloadEstimate({ download_percent: 0 })).toEqual(' (0%)');
});

it('should display 0 Bps if the agent has a zero download rate', () => {
expect(getDownloadEstimate({ download_rate: 0 })).toEqual(' (at 0.0 Bps)');
});

it('should return a formatted string if the agent has a positive download percent', () => {
expect(getDownloadEstimate(16.4)).toEqual(' (16.4%)');
expect(getDownloadEstimate({ download_percent: 16.4 })).toEqual(' (16.4%)');
});

it('should return a formatted string if the agent has a kBps download rate', () => {
expect(getDownloadEstimate({ download_rate: 1024 })).toEqual(' (at 1.0 kBps)');
});

it('should return a formatted string if the agent has a download rate and download percent', () => {
expect(getDownloadEstimate({ download_rate: 10, download_percent: 99 })).toEqual(
' (99% at 10.0 Bps)'
);
});

it('should return a formatted string if the agent has a MBps download rate', () => {
expect(getDownloadEstimate({ download_rate: 1200000 })).toEqual(' (at 1.1 MBps)');
});

it('should return a formatted string if the agent has a GBps download rate', () => {
expect(getDownloadEstimate({ download_rate: 2400000000 })).toEqual(' (at 2.2 GBps)');
});

it('should return a formatted string if the agent has a GBps download rate more than 1024', () => {
expect(getDownloadEstimate({ download_rate: 1200000000 * 1024 })).toEqual(' (at 1144.4 GBps)');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,34 @@ export function getUpgradeStartDelay(scheduledAt?: string): string {
return ` The upgrade will start in less than ${Math.ceil(timeDiffMillis / 36e5)} hours.`;
}

export function getDownloadEstimate(downloadPercent?: number): string {
if (!downloadPercent || downloadPercent === 0) {
export function getDownloadEstimate(metadata?: AgentUpgradeDetails['metadata']): string {
if (
!metadata ||
(metadata.download_percent === undefined && metadata.download_rate === undefined)
) {
return '';
}
let tooltip = '';
if (metadata.download_percent !== undefined) {
tooltip = `${metadata.download_percent}%`;
}
if (metadata.download_rate !== undefined) {
tooltip += ` at ${formatRate(metadata.download_rate)}`;
}

return ` (${downloadPercent}%)`;
return ` (${tooltip.trim()})`;
}

const formatRate = (downloadRate: number) => {
let i = 0;
const byteUnits = [' Bps', ' kBps', ' MBps', ' GBps'];
for (; i < byteUnits.length - 1; i++) {
if (downloadRate < 1024) break;
downloadRate = downloadRate / 1024;
}
return downloadRate.toFixed(1) + byteUnits[i];
};

function getStatusComponents(agentUpgradeDetails?: AgentUpgradeDetails) {
switch (agentUpgradeDetails?.state) {
case 'UPG_REQUESTED':
Expand Down Expand Up @@ -97,9 +117,7 @@ function getStatusComponents(agentUpgradeDetails?: AgentUpgradeDetails) {
id="xpack.fleet.agentUpgradeStatusTooltip.upgradeDownloading"
defaultMessage="Downloading the new agent artifact version{downloadEstimate}."
values={{
downloadEstimate: getDownloadEstimate(
agentUpgradeDetails?.metadata?.download_percent
),
downloadEstimate: getDownloadEstimate(agentUpgradeDetails?.metadata),
}}
/>
),
Expand Down

0 comments on commit 93588d5

Please sign in to comment.