From aff900d01a1812b25296d0b22f50d49cff031c99 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Tue, 5 Sep 2023 16:35:17 -0700 Subject: [PATCH] docs: use the 'latest' GH release API for the latest extension or agent release (#402) The "Monitoring AWS Lambda $lang Functions" doc pages use some in-browser JS to interpolate the ARNs for the latest Lambda extension release and the latest APM agent release. This changes that JS to use the "latest release" GH API https://api.github.com/repos/elastic/${ghRepo}/releases/latest rather than listing all (or the first page of GH releases): https://api.github.com/repos/elastic/${ghRepo}/releases and picking the latest by `release.created_at`. GH releases for a repo have a sense of the "latest" release (see `--latest` flag to https://cli.github.com/manual/gh_release_create) even if it isn't the latest tag or published release in time. The Node.js APM agent will soon have 4.x releases and 3.x maintenance releases. It is possible that a 3.x release is the latest in time, but not marked as the "latest" release. This change ensures that the Lambda doc page will pick the correct (4.x) one. (cherry picked from commit 989993294e6fb2c7c969d88b0d1b942e43ab8b9e) --- .../lambda-attributes-selector.asciidoc | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/docs/lambda-selector/lambda-attributes-selector.asciidoc b/docs/lambda-selector/lambda-attributes-selector.asciidoc index cab788bb..1fd709eb 100644 --- a/docs/lambda-selector/lambda-attributes-selector.asciidoc +++ b/docs/lambda-selector/lambda-attributes-selector.asciidoc @@ -86,21 +86,12 @@ const addArnGenerator = async (type, ghRepo, arnPattern) => { var releaseArns = []; const retrieveLatestLayerVersion = async () => { - const releases = await fetch(`https://api.github.com/repos/elastic/${ghRepo}/releases`).then(data => { + var latestRelease = await fetch(`https://api.github.com/repos/elastic/${ghRepo}/releases/latest`).then(data => { return data.status >= 400 ? undefined : data.json(); }); - if(releases){ - var latestRelease = releases[0]; - - releases.forEach(release => { - if(Date.parse(release.created_at) > Date.parse(latestRelease.created_at)){ - latestRelease = release; - } - }); - + if (latestRelease) { releaseArns = latestRelease.body.match(layerArnPattern); - version = latestRelease.tag_name.replace("v","ver-").replace(/\./g, '-'); } else { document.getElementById("default-arn-selector-section").style.display = "none";