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

move over most trivial services to backend-defaults #24724

Merged
merged 1 commit into from May 17, 2024

Conversation

freben
Copy link
Member

@freben freben commented May 10, 2024

Closes: #24736

This moves over most of the remaining core service factories/implementations to backend-defaults.

NOTE that this is on top of the freben/tasks-plugin-api branch (#24563), adding to what it started.

There are still some slightly less trivial services to move, such as auth and logging.

Small point of interest: BackendInitializer now duck-types the lifecycle detection instead of doing instanceof. The reason I changed this is that I was afraid that the initializer would lead to issues because one or the other of the now two implementations of the services got passed to it.

@freben freben requested review from backstage-service and a team as code owners May 10, 2024 14:20
@freben freben requested review from benjdlambert and vinzscam and removed request for a team May 10, 2024 14:20
@freben freben force-pushed the freben/more-default-moves branch from ca3b43f to 710da83 Compare May 10, 2024 15:06
@freben freben requested a review from Rugvip May 10, 2024 15:07
Copy link
Contributor

@camilaibs camilaibs left a comment

Choose a reason for hiding this comment

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

Thank you so much @freben for opening this pull request. Left a few comments below 🙂

* limitations under the License.
*/

import { CacheManager } from '@backstage/backend-common';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the CacheManager be extracted to this package as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Opening this up for discussion! Happy to expose them from here if we want. Just gotta make sure we're happy to do so and whether it is better to wait for some service extension points to appear instead.

* limitations under the License.
*/

import { UrlReaders } from '@backstage/backend-common';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the UrlReaders be extracted to this package as well?

* limitations under the License.
*/

import { DatabaseManager } from '@backstage/backend-common';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the DatabaseManager be extracted to this package as well?

@@ -20,22 +20,55 @@
"license": "Apache-2.0",
"exports": {
".": "./src/index.ts",
"./cache": "./src/entrypoints/cache/index.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to create a codemod to assist adopters with updating their imports?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could try!


import { CacheManager } from '@backstage/backend-common';
import {
coreServices,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am more and more inclined to suggest renaming coreServices to defaultServices... Are there any conceptual differences between core and default services? It may also make sense to move the definitions to this package if we rename to defaultServices.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh that's a bit of a bigger discussion I guess. We've called them core services all the time - the ones that are in backend-plugin-api. That's where the nomenclature comes from, irrespective of if backend-defaults also exists as a concept or not. They are the "core set of interfaces that you can consume". The default implementations of those core interfaces live in backend-defaults, but you may bring your own.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it right to say core services are the ones the backend application can't function without? Without a clear definition of what makes a service "core", I think it would simplify things if we considered them all as services with standard implementations since they're essential to a minimal backend. What about root services? Are they all core? Maybe it's just me, but do you remember other people asking about this or making confusion about core, root, and plugins services 🤔 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it right to say core services are the ones the backend application can't function without?

They are the ones that backend-plugin-api expose. No more, no less. They are owned by the core maintainers, and we guarantee that they have sensible definitions out of the box. It's "our sdk" so to speak. I don't think the definition is more complex than that. :)

Maybe it's more useful to think in terms of, what do we move to backend-plugin-api and what do we leave outside? We generally put things in there that we feel are so foundational, and useful for so many plugins, that we want to make it part of the central guaranteed offering. Events are such a thing that started outside as a plugin, but then got considered for "adoption" as a foundational piece, because it really is a foundation that others should be encouraged to use and share information between each other with.

Another thing that is special about many (but not all) core services is that they really don't have anywhere else to live. We don't have a logging plugin that can hold the logger.

Without a clear definition of what makes a service "core", I think it would simplify things if we considered them all as services with standard implementations since they're essential to a minimal backend.

They're not though. It's just a toolbox. The things that we want to offer since we want to encourage people to build upon those primitives instead of reinventing wheels all over. Arguably not even config and logger are "essential", you just use them if you need them and we encourage you to try to leverage that instead of env vars and console logs, because it makes your plugin a better citizen.

What about root services? Are they all core?

No, being root or plugin scoped is a separate orthogonal concern. The service itself chooses what makes sense in its own situation. That only deals with the "lifecycle" / instantiation of the service.

Maybe it's just me, but do you remember other people asking about this or making confusion about core, root, and plugins services 🤔 ?

Hm not sure. The root/plugin thing I don't think I've heard. Figuring out where your deps live, yeah maybe? It's easy to find coreServices, people quickly pick up on that and enjoy the IDE completion helping them find what's available. But then, why isn't the catalog client in there for example? Sure, that gets a bit philosophical then, why is that not considered core but some others are? I kinda have an answer, but it's not always clear from the outside.

* limitations under the License.
*/

import { getVoidLogger } from '@backstage/backend-common';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm moving this helper to the backend-plugin-api package, but I would like to confirm if moving to backend-default makes more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds more like a testUtils thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use the mockServices.logger.mock() instead? This question just came to my mind now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah!

@@ -20,7 +20,10 @@ import {
createServiceFactory,
} from '@backstage/backend-plugin-api';

/** @public */
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move the deprecated files to a deprecated folder? Just for making it easy to cleanup later?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah that could really help!

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
@freben freben force-pushed the freben/more-default-moves branch from 710da83 to b0210ec Compare May 16, 2024 08:27
Copy link
Contributor

@camilaibs camilaibs left a comment

Choose a reason for hiding this comment

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

Approving as the comments left are optional and could be addressed in a follow-up pull request. Thank you again 🙌🏻

Base automatically changed from freben/tasks-plugin-api to master May 17, 2024 11:07
Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Awesome stuff! 👏 Let's :shipit:

Comment on lines +379 to 382
const service = lifecycleService as any;
if (service && typeof service.startup === 'function') {
return service;
}
Copy link
Member

Choose a reason for hiding this comment

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

👍

@freben freben merged commit 26cf95a into master May 17, 2024
31 checks passed
@freben freben deleted the freben/more-default-moves branch May 17, 2024 11:33
Copy link
Contributor

Uffizzi Cluster pr-24724 was deleted.

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.

Extract all service implementations from backend-common to the backend-defaults package
3 participants