Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

journey-level tags are ignored by push command #927

Open
dmlemeshko opened this issue May 15, 2024 · 1 comment
Open

journey-level tags are ignored by push command #927

dmlemeshko opened this issue May 15, 2024 · 1 comment
Assignees

Comments

@dmlemeshko
Copy link
Member

The goal is to define a single journey file and run it on different serverless test envs (qa, staging, prod). Since some journeys maybe qa-only, I rely on tagging mechanism to run/push only required journeys.

Journey example:

journey(
  { name: '[AppEx] Sample data: flights dashboard', tags: ['qa', 'prod'] },
  ({ page, params, request, context }) => {
    monitor.use({
      id: 'appex-kibana-dasboard-monitor',
      schedule: DEFAULT_SCHEDULE,
      tags: ['appex', 'serverless'],
    });
    step('open flights dashboard', async () => {
      const dashboard = new DashboardPage(page);
      await page.goto(`${params.base_url}/app/dashboards`);
      await page.getByTestId('dashboardListingTitleLink-[Flights]-Global-Flight-Dashboard').click();
      await dashboard.waitToBeLoaded({ itemsCount: 15 });
      await page.waitForLoadState('domcontentloaded');
    });
  }
);
synthetics.config.ts
import type { SyntheticsConfig } from '@elastic/synthetics';

export default (env) => {
  const configQA: SyntheticsConfig = {
    params: {
      base_url: process.env.BASE_URL,
      es_username: process.env.ES_USERNAME,
      es_password: process.env.ES_PASSWORD,
    },
    playwrightOptions: {
      ignoreHTTPSErrors: false,
      testIdAttribute: 'data-test-subj',
      timezoneId: 'UTC',
      locale: 'en-US',
    },
    /**
     * Configure global monitor settings
     */
    monitor: {
      // @ts-ignore
      locations: ['us_central_qa'],
      privateLocations: [],
      schedule: 60,
    },
    /**
     * Project monitors settings
     */
    project: {
      id: 'serverless-qa',
      url: <REDACTED>,
      space: 'default',
    },
  };

  const configStaging: SyntheticsConfig = {
    params: {
      base_url: process.env.BASE_URL,
      es_username: process.env.ES_USERNAME,
      es_password: process.env.ES_PASSWORD,
    },
    playwrightOptions: {
      ignoreHTTPSErrors: false,
      testIdAttribute: 'data-test-subj',
      timezoneId: 'UTC',
      locale: 'en-US',
    },
    monitor: {
      locations: ['us_east'],
      privateLocations: [],
      schedule: 60,
    },
    project: {
      id: 'serverless-staging',
      url: <REDACTED>,
      space: 'default',
    },
  };

  const configProd: SyntheticsConfig = {
    params: {
      base_url: process.env.BASE_URL,
      es_username: process.env.ES_USERNAME,
      es_password: process.env.ES_PASSWORD,
    },
    playwrightOptions: {
      ignoreHTTPSErrors: false,
      testIdAttribute: 'data-test-subj',
      timezoneId: 'UTC',
      locale: 'en-US',
    },
    monitor: {
      locations: ['us_east'],
      privateLocations: [],
      schedule: 60,
    },
    project: {
      id: 'serverless-prod',
      url: <REDACTED>,
      space: 'default',
    },
  };

  if (env === 'prod') {
    return configProd;
  } else if (env === 'staging') {
    return configStaging;
  } else {
    return configQA;
  }
};

run command works as expected: TEST_ENV=prod npx @elastic/synthetics journeys --tags=prod

Journey: [AppEx] Sample data: flights dashboard
waitForRender: 0 out of 15 are loaded...
Retrying..
waitForRender: 1 out of 15 are loaded...
Retrying..
waitForRender: 1 out of 15 are rendered...
Retrying..
waitForRender: 8 out of 15 are rendered...
Retrying..
waitForRender: 14 out of 15 are rendered...
Retrying..
waitForRender: 14 out of 15 are rendered...
Retrying..
waitForRender: 14 out of 15 are rendered...
Retrying..
waitForRender: 14 out of 15 are rendered...
Retrying..
waitForRender: 14 out of 15 are rendered...
Retrying..
waitForRender: 15 out of 15 are rendered...
   ✓  Step: 'open flights dashboard' succeeded (9228 ms)

push command completely ignores journey tags:

NODE_ENV=prod npx @elastic/synthetics push --tags "prod" --auth <REDACTED>
> Pushing monitors for 'serverless-prod' project in kibana 'default' space
> bundling 0 monitors
> Monitor Diff: Added(0) Updated(0) Removed(1) Unchanged(0)

It only works if I add 'prod' tag in config-level, but this way tags in Synthetics UI will look confusing: 'appex', 'serverless', 'qa', 'prod';

I believe that ideally tagging mechanism should be identical for both commands, could be possible to use Journey context while filtering monitors for push?

@devcorpio devcorpio self-assigned this May 15, 2024
@vigneshshanmugam
Copy link
Member

vigneshshanmugam commented May 15, 2024

Okay here is the gist of the issue

  • Journey runner doesn’t understand a thing about monitor.use - because monitors are meant for synthetics Kibana and Service, so when you run locally the only thing that gets applied are the journey tags.
  • Push command is different since they are ideally sending everything to Kibana/Service which is meant to run monitors which is why your monitor.use tags are more prioritized over your local journey tags.

Look at this test which clearly explains the process - https://github.com/vigneshshanmugam/synthetics/blob/8fd2b339f4961f1b4f8e78d76f7704975455047a/__tests__/core/runner.test.ts#L846

We could fix this by appending the monitor.use tags during push instead of replacing them.

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

No branches or pull requests

3 participants