-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added changes to enable tracing in lambdas. (#3554)
This PR addresses the need to enable tracing for the lambdas used in the runners architecture: # Highlights: - This feature enables the tracing in all lambdas which allow to debug/investigate any issues that arise out of day-to-day use of runners infrastructure. - If user decides to add all the features provisioned in the PR, user should be able to find the complete linked trace between the time a webhook is triggered with workflow job event to the API gateway endpoint to the execution of scale up lambda which creates a new runner to fulfill the need of creating a new runner and also find the relevant logs linked to the trace in **AWS CloudWatch ServiceLens**. As of result, user need not navigate to various log groups to find any issue in any given service. - Please find the X-ray costing in this [link](https://aws.amazon.com/xray/pricing/) detailing the cost involved in enabling this feature. # Additions: - [x] Provide an option to enable traces in EC2 bash script which allows to find and link any issues that may arise out of starting the runner and find this information linked in the trace created out of this feature. # Options: Use Cloudwatch config agent which now supports to capture traces ([link](https://aws.amazon.com/about-aws/whats-new/2023/08/amazon-cloudwatch-agent-opentelemetry-traces-x-ray/)) can be used to capture traces and link them to the log groups. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Niek Palm <npalm@users.noreply.github.com>
- Loading branch information
1 parent
d85511a
commit 970e8a6
Showing
63 changed files
with
531 additions
and
197 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
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
31 changes: 31 additions & 0 deletions
31
lambdas/functions/control-plane/src/axios/fetch-override.test.ts
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,31 @@ | ||
import axios, { AxiosResponse } from 'axios'; | ||
|
||
import { axiosFetch } from './fetch-override'; | ||
|
||
jest.mock('axios'); | ||
type FetchResponse = AxiosResponse & { json: () => string }; | ||
|
||
describe('axiosFetch', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('should return a promise that resolves with the response data', async () => { | ||
// Arrange | ||
const url = 'https://example.com'; | ||
const options = { body: { foo: 'bar' } }; | ||
const responseData = { data: { baz: 'qux' } }; | ||
const mockedAxios = axios as unknown as jest.Mock; | ||
mockedAxios.mockResolvedValue(responseData); | ||
|
||
// Act | ||
const result = (await axiosFetch(url, options)) as FetchResponse; | ||
|
||
// Assert | ||
expect(axios).toHaveBeenCalledWith(url, { ...options, data: options.body }); | ||
expect(result).toEqual({ | ||
...responseData, | ||
json: expect.any(Function), | ||
}); | ||
expect(result.json()).toEqual(responseData.data); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
lambdas/functions/control-plane/src/axios/fetch-override.ts
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,19 @@ | ||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
|
||
type FetchResponse = AxiosResponse & { json: () => string }; | ||
|
||
type FetchOptions = AxiosRequestConfig & { body?: object }; | ||
|
||
// Fetch is not covered to be traced by xray so we need to override it with axios | ||
// https://github.com/aws/aws-xray-sdk-node/issues/531 | ||
export const axiosFetch = async (url: string, options: FetchOptions): Promise<FetchResponse> => { | ||
const response = await axios(url, { ...options, data: options.body }); | ||
return new Promise((resolve) => { | ||
resolve({ | ||
...response, | ||
json: () => { | ||
return response.data; | ||
}, | ||
}); | ||
}); | ||
}; |
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
Oops, something went wrong.