-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cron): send instance=github_action label with retrieval_duration…
…_seconds metric (#2020) * chore(cron): createPromClientRetrievalMetricsLogger logs metricPushed with request url and response status * add test to ensure createPromClientRetrievalMetricsLogger sends http request to pushgateway * lint * feat(cron): createPromClientRetrievalMetricsLogger can have metricLabels passed (e.g. for instance label) * feat(cron): cron-nft-ttr includes instance=github_action label which is sent to pushgateway
- Loading branch information
Showing
6 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as nodeHttp from 'http' | ||
|
||
/** | ||
* Spin up an http server on an unused port, do some work with it, then shut it down. | ||
* @param {import('http').RequestListener} listener | ||
* @param {(baseUrl: URL) => Promise<void>} useServer | ||
* @returns | ||
*/ | ||
export async function withHttpServer(listener, useServer) { | ||
const httpServer = nodeHttp.createServer(listener) | ||
// listen on unused port | ||
await new Promise((resolve) => { | ||
httpServer.listen(0, () => { | ||
resolve(true) | ||
}) | ||
}) | ||
const baseUrl = addressUrl(httpServer.address()) | ||
if (!baseUrl) { | ||
throw new Error(`failed to determine baseUrl from server`) | ||
} | ||
try { | ||
await useServer(baseUrl) | ||
} finally { | ||
await new Promise((resolve) => { | ||
httpServer.close(resolve) | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Given return type of node http Server#address, return a URL descriving the server address | ||
* @param {string|null|import('net').AddressInfo} addressInfo | ||
* @returns {URL} | ||
*/ | ||
export function addressUrl(addressInfo) { | ||
if (addressInfo === null) | ||
throw new TypeError('addressInfo is unexpectedly null') | ||
if (typeof addressInfo === 'string') return new URL(addressInfo) | ||
const { address, port } = addressInfo | ||
const host = address === '::' ? '127.0.0.1' : address | ||
const urlString = `http://${host}:${port}` | ||
return new URL(urlString) | ||
} |