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

[Synthetics] Refactor: Create monitor configs repository !! #202325

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

shahzad31
Copy link
Contributor

@shahzad31 shahzad31 commented Nov 29, 2024

Summary

Create monitor configs repository around monitor saved object to make sure all operations are performed from same class.

This will be helpful when we create a new saved object to support multiple-spaces !!

Testing

All unit tests, api tests passing should be more than enough !!

@shahzad31 shahzad31 requested a review from a team as a code owner November 29, 2024 14:19
@botelastic botelastic bot added ci:project-deploy-observability Create an Observability project Team:obs-ux-management Observability Management User Experience Team labels Nov 29, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@shahzad31 shahzad31 requested a review from kdelemme November 29, 2024 14:21
@shahzad31 shahzad31 added release_note:skip Skip the PR/issue when compiling release notes backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) labels Nov 29, 2024
@elasticmachine
Copy link
Contributor

elasticmachine commented Dec 4, 2024

💛 Build succeeded, but was flaky

  • Buildkite Build
  • Commit: 11d7931
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-202325-11d793151c5a

Failed CI Steps

Metrics [docs]

✅ unchanged

History

Copy link
Contributor

@kdelemme kdelemme left a comment

Choose a reason for hiding this comment

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

I have a few questions and suggestions (especially the class methods one) but otherwise that looks good

Comment on lines +82 to +85
this.monitorConfigRepository = new MonitorConfigRepository(
savedObjectsClient,
server.encryptedSavedObjects.getClient()
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we inject the whole dependency instead of instantiating it in the constructor?
But it's already a good thing to introduce a repository pattern 👍🏻

expect(
await route.handler({
// @ts-expect-error partial implementation for testing
request: { query: {} },
// @ts-expect-error partial implementation for testing
syntheticsEsClient: jest.fn(),
savedObjectClient: jest.fn(),
// @ts-expect-error partial implementation for testing
monitorConfigRepository: { getAll },
Copy link
Contributor

Choose a reason for hiding this comment

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

If we create a mockMonitorConfigRepository somewhere that implements the interface with jest.fn() we can get ride of the @ts directive and reuse it in the other tests

Comment on lines +26 to +34
soClient: SavedObjectsClientContract;
encryptedSavedObjectsClient: EncryptedSavedObjectsClient;
constructor(
soClient: SavedObjectsClientContract,
encryptedSavedObjectsClient: EncryptedSavedObjectsClient
) {
this.soClient = soClient;
this.encryptedSavedObjectsClient = encryptedSavedObjectsClient;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

neat: Use short hand constructor to remove boilerplate

Suggested change
soClient: SavedObjectsClientContract;
encryptedSavedObjectsClient: EncryptedSavedObjectsClient;
constructor(
soClient: SavedObjectsClientContract,
encryptedSavedObjectsClient: EncryptedSavedObjectsClient
) {
this.soClient = soClient;
this.encryptedSavedObjectsClient = encryptedSavedObjectsClient;
}
constructor(
private soClient: SavedObjectsClientContract,
private encryptedSavedObjectsClient: EncryptedSavedObjectsClient
) { }

Comment on lines +36 to +40
get = async (id: string) => {
return await this.soClient.get<EncryptedSyntheticsMonitorAttributes>(syntheticsMonitorType, id);
};

async getDecrypted(id: string, spaceId: string): Promise<SavedObject<SyntheticsMonitor>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not used arrow function for class methods, it comes with some unnecessary memory overhead and in our case we don't need it.
Plus it makes this class more consistent if we pick just one way of defining methods

Comment on lines +318 to +320
const monitorConfigRepository = new MonitorConfigRepository(
soClient,
encryptedSavedObjects.getClient()
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it possible to instantiate the SyntheticsMonitorClient with the MonitorConfigRepository directly? Maybe that's too much of a refactoring. If we were to move the SyntheticsMonitorClient into the SynthethicsRouterWrapper were we instantiate the repository, we could directly inject it as a dependency?

Also, maybe not possible to do if the SyntheticsMonitorClient is used outside of the route, I haven't checked deeper

);
}

getAll = async ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

@shahzad31 shahzad31 marked this pull request as draft February 10, 2025 10:35
@elasticmachine
Copy link
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) ci:project-deploy-observability Create an Observability project release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-management Observability Management User Experience Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants