Skip to content

Conversation

@shahzad31
Copy link
Contributor

@shahzad31 shahzad31 commented Feb 5, 2025

multi step api runner

can be tested with

import { apiJourney, monitor, step } from '@elastic/synthetics';

apiJourney(`My Example api journey`, ({ request }) => {
  monitor.use({
    enabled: true,
  });
  step('launch application', async () => {
    const req = await request.get('https://api.restful-api.dev/objects');
    console.log(await req.json());
  });
  step('go to url', async () => {
    const req = await request.get('https://example.badssl.com/');
    console.log(await req.json());
  });
});

src/helpers.ts Outdated
args: APIHooksArgs
) {
const promises = callbacks.map(cb => cb(args));
return await Promise.all(promises);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return await Promise.all(promises);
return await Promise.allSettled(promises);

Accounting for unrelated rejections

};
export type APIJourneyCallback = (options: APIJourneyCallbackOpts) => void;

export class APIJourney {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would like us to have a base Journey class that both BrowserJourney and APIJourney extends from and the runner should be a single entity that decides how to run each of them. I am not in favor of having multiple runners.

@shahzad31 shahzad31 changed the title DRAFT: multi step api runner. feat: multi step api runner. Feb 10, 2025
@shahzad31 shahzad31 changed the title feat: multi step api runner. feat: multi step api runner Feb 13, 2025
Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a first pass.


export type APIJourneyEndResult = JourneyStartResult &
APIJourneyResult & {
browserDelay: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

browserDelay is not appropriate for apijourneys?

async #startJourney(journey: Journey, options: RunOptions) {
journey._startTime = monotonicTimeInSeconds();
this.#driver = await Gatherer.setupDriver(options);
this.#driver = await Gatherer.setupDriver(options, journey.type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit weird , Maybe a better way would be to check if there are defined browser journeys and then launch the browser context etc based on that.


export class APIJourney extends Journey {
#cb: APIJourneyCallback;
#driver?: Driver | APIDriver;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it have a Driver at any point?

);
}

async _interceptRequest(method, url, options: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some careful review as we need some extensive tests for cached, aborted, intercepted requests etc, Will do a detailed review later on when we have tests etc.

instance = new BrowserConsole(this.driver);
break;

if ('context' in this.driver) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin Manager should be transparent to the underlying journey that was run whether its browser/api based. There will be always a chance when browser/api based journeys coexisting. I would handle these and make them respective plugins transparent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants