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
Conversation
ca3b43f
to
710da83
Compare
There was a problem hiding this 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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤔 ?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah!
packages/backend-defaults/src/entrypoints/permissions/permissionsServiceFactory.ts
Show resolved
Hide resolved
@@ -20,7 +20,10 @@ import { | |||
createServiceFactory, | |||
} from '@backstage/backend-plugin-api'; | |||
|
|||
/** @public */ | |||
/** |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
11c5cbc
to
ddfd660
Compare
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
710da83
to
b0210ec
Compare
There was a problem hiding this 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 🙌🏻
There was a problem hiding this 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
const service = lifecycleService as any; | ||
if (service && typeof service.startup === 'function') { | ||
return service; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Uffizzi Cluster |
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 doinginstanceof
. 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.