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

Quarkus-info extension could provide beans available to applications #32994

Closed
manofthepeace opened this issue Apr 28, 2023 · 9 comments · Fixed by #33226
Closed

Quarkus-info extension could provide beans available to applications #32994

manofthepeace opened this issue Apr 28, 2023 · 9 comments · Fixed by #33226
Labels
kind/enhancement New feature or request
Milestone

Comments

@manofthepeace
Copy link
Contributor

Description

In our applicaiton we use git-commit-id-maven-plugin to create a git.properties, which we add to the build via quarkus.config.locations

I think it would be good if we could remove that and use quarkus-info and inject or a composite bean or multiple bean for; JavaInfo, GitInfo, BuildInfo, OsInfo, which could then be use through an application. This way we could easily customize also the format we want and/or need via a custom endpoint, or not use an endpoint at all but have it available for logging or any other purposes.

Implementation ideas

No response

@gsmet
Copy link
Member

gsmet commented May 2, 2023

/cc @geoand

@geoand
Copy link
Contributor

geoand commented May 2, 2023

So if I understand correctly you just want access to the data via CDI which you would then use to build your own endpoint?

@manofthepeace
Copy link
Contributor Author

Yes. In my particular case the endpoint + a startup log are using the data from git-commit-id-maven-plugin which could then be removed and use only quarkus-info provided data and ProcessorInfo. example log in my case;

log.info("<app> version {} running on {} cpus. Git branch is {} and short sha is {}", gitConfig.version(),
    ProcessorInfo.availableProcessors(), gitConfig.branch(), gitConfig.commitId());

where gitConfig is a ConfigMapping created from the properties file create by git-commit-id-maven-plugin

@geoand
Copy link
Contributor

geoand commented May 2, 2023

Gotcha. I think this makes sense

@manofthepeace
Copy link
Contributor Author

Not sure what is the easiest, but could also be as simple as having is statically available as ProcessorInfo does.

geoand added a commit to geoand/quarkus that referenced this issue May 9, 2023
geoand added a commit to geoand/quarkus that referenced this issue May 9, 2023
geoand added a commit that referenced this issue May 9, 2023
Allow to inject info extension data as beans
@quarkus-bot quarkus-bot bot added this to the 3.1 - main milestone May 9, 2023
michelle-purcell pushed a commit to michelle-purcell/quarkus that referenced this issue May 9, 2023
manofthepeace pushed a commit to manofthepeace/quarkus that referenced this issue May 16, 2023
@ygyg70
Copy link
Contributor

ygyg70 commented Aug 29, 2023

I was trying to use this capability (Quarkus version 3.0.0) with the following behavior:

  • Injection of BuildInfo and GitInfo works in dev, test mode
  • Locally, all artifact types (jar, native) are built without errors
  • IDE (Intellij) shows "Unsatisfied dependency: no bean matches the injection point" warning for the injection fields
  • With Github action, build fails with the exception shown below

Any ideas?

Error: #25 347.2 [ERROR] 	[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: jakarta.enterprise.inject.spi.DeploymentException: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.quarkus.info.GitInfo and qualifiers [@Default]
#25 347.2 [ERROR] 	- java member: ***.AppLifecycleBean#gitInfo
#25 347.2 [ERROR] 	- declared on CLASS bean [types=[***.AppLifecycleBean, java.lang.Object], qualifiers=[@Default, @Any], target=***.AppLifecycleBean]
#25 347.2 [ERROR] 	at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1435)
#25 347.2 [ERROR] 	at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:310)
#25 347.2 [ERROR] 	at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:155)
#25 347.2 [ERROR] 	at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:469)
#25 347.2 [ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
#25 347.2 [ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
#25 347.2 [ERROR] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
#25 347.2 [ERROR] 	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
#25 347.2 [ERROR] 	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:864)
#25 347.2 [ERROR] 	at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
#25 347.2 [ERROR] 	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
#25 347.2 [ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
#25 347.2 [ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
#25 347.2 [ERROR] 	at java.base/java.lang.Thread.run(Thread.java:833)
#25 347.2 [ERROR] 	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
#25 347.2 [ERROR] Caused by: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.quarkus.info.GitInfo and qualifiers [@Default]
#25 347.2 [ERROR] 	- java member: ***.AppLifecycleBean#gitInfo
#25 347.2 [ERROR] 	- declared on CLASS bean [types=[***.AppLifecycleBean, java.lang.Object], qualifiers=[@Default, @Any], target=***.AppLifecycleBean]
#25 347.2 [ERROR] 	at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:477)
#25 347.2 [ERROR] 	at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:624)
#25 347.2 [ERROR] 	at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:298)

@geoand
Copy link
Contributor

geoand commented Aug 29, 2023

I've never seen that. Do you have a sample application thta exhibits that behavior?

@ramiswailem
Copy link

I use GitInfo from the dependency Quarkus-info:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-info</artifactId>
</dependency>
@Inject
GitInfo gitInfo;

String commitId;
String commitTime;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    
  void onStart(@Observes StartupEvent ev) {
        LOG.info("The application is starting...");
        var localDateTime = gitInfo.commitTime().toLocalDateTime();
        commitId = gitInfo.latestCommitId();
        commitTime = localDateTime.format(formatter);
    }

@geoand
Copy link
Contributor

geoand commented Aug 29, 2023

I tried it and it worked just fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants