-
Notifications
You must be signed in to change notification settings - Fork 398
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
[FIXED JENKINS-41811] Expose event origin to listeners #164
Conversation
@@ -99,7 +99,13 @@ | |||
<dependency> | |||
<groupId>org.jenkins-ci.plugins</groupId> | |||
<artifactId>git</artifactId> | |||
<version>2.4.0</version> | |||
<version>2.4.0</version> <!-- should really be 2.6.4 to match scm-api but ok as git wass forward compat --> |
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.
Workflow tests need rework for the updated git dependency, but as git plugin didn't break the rules of SCM API we don't need to update to 2.6.4 / 3.0.4... just would be missing the SCMEvent integration in git plugin, but the tests in this plugin do not rely on that functionality, so no harm
*/ | ||
@Deprecated | ||
@Restricted(NoExternalUse.class) |
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.
From what I can see the only consumer of this API is the 1.x GitHub Branch Source. If there are other use cases for consumers remaining post SCM API 2.0.x updates then this would need to be augmented to pass through the origin.
I'd much rather kill off the code path, so by adding the @Restricted
we will flush out any impls without breaking them until they update their dependency
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.
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.
@jglick that single impl is not in GHBS 2.0.x
pom.xml
Outdated
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>scm-api</artifactId> | ||
<version>2.0.3-SNAPSHOT</version> |
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.
👎 on scm-api dependency
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.
Why? scm-api
is harmless—it has no UI.
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.
Because it adds useless dependency that participate in multibranch/branch api chaos with cycle dependencies and huge pages with instructions what to do with broken instances. I also have gh plugins depending on github-plugin and i don't want to deal with redundant dependencies. github-plugin as trigger and eventing mechanism may work without additional deps. Freely add Listener calls instead of deprecating it. I would also like to see firstly such changes in gitlab and other trigger plugins, not only gh.
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.
@KostyaSha you already have the dependency via git 2.4.0 (but just an older version) and we need the SCMEvent.originOf(req)
helper method
@@ -24,6 +24,8 @@ | |||
// TODO: document me | |||
void onPost(String triggeredByUser); | |||
|
|||
void onPost(String origin, String triggeredByUser); |
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 wait until java8
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.
Could instead introduce an extension interface
.
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.
From what i see i'm against depending on scm-api that adds mess in plugins with all this new plugins.
@@ -153,7 +157,10 @@ public static Jenkins getJenkinsInstance() throws IllegalStateException { | |||
* Other plugins may be interested in listening for these updates. | |||
* | |||
* @since 1.8 | |||
* @deprecated we do not think this API is required any more, if we are wrong, please raise a JIRA |
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.
we? You?
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.
Not binary compatible.
@@ -99,7 +99,13 @@ | |||
<dependency> | |||
<groupId>org.jenkins-ci.plugins</groupId> | |||
<artifactId>git</artifactId> | |||
<version>2.4.0</version> | |||
<version>2.4.0</version> <!-- should really be 2.6.4 to match scm-api but ok as git wass forward compat --> |
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.
typo
pom.xml
Outdated
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>scm-api</artifactId> | ||
<version>2.0.3-SNAPSHOT</version> |
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.
preferably specify a timestamp
@@ -87,6 +96,7 @@ private boolean runPolling() { | |||
PrintStream logger = listener.getLogger(); | |||
long start = System.currentTimeMillis(); | |||
logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); | |||
logger.println("Started by event from " + origin); |
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.
Can origin
be null
? Or would it be "?"
here?
@@ -24,6 +24,8 @@ | |||
// TODO: document me | |||
void onPost(String triggeredByUser); | |||
|
|||
void onPost(String origin, String triggeredByUser); |
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.
Could instead introduce an extension interface
.
*/ | ||
@Deprecated | ||
@Restricted(NoExternalUse.class) |
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.
@@ -92,7 +93,7 @@ public void run() { | |||
if (GitHubRepositoryNameContributor.parseAssociatedNames(job) | |||
.contains(changedRepository)) { | |||
LOGGER.info("Poked {}", fullDisplayName); | |||
trigger.onPost(pusherName); | |||
trigger.onPost(origin, pusherName); |
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.
Must at least catch AbstractMethodError
here.
@KostyaSha I am not adding a dependency on scm-api, the current transitive dependency on scm-api is
|
That's terrible. |
exactly, that version is so ancient which is why we need to bump it ;-) |
typed huge sentence on how i disappointed with jenkins & CB and deleted. |
@@ -15,6 +15,7 @@ | |||
* and triggers a build. | |||
* | |||
* @author aaronwalker | |||
* @deprecated extend {@link GitHubTrigger2} instead |
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.
Careful—does this produce deprecation warnings for implementers of GitHubTrigger2
?
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.
Who has implemented it? it is doubtful the interface is even required.
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.
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 think @jglick mean compiler warnings, but i guess they work only on annotations.
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 wonder if this interface is required for https://github.com/jenkinsci/github-sqs-plugin/blob/master/src/main/java/com/base2services/jenkins/SqsBuildTrigger.java or if it is a gratuitous linkage between the two plugins. It is the only OSS consumer of this interface... the only reason for it to exist is so that the two trigger options will both work for triggering builds... which seems a really crappy UX
i.e. is it obvious to the user that checking one or both of the above check boxes will do exactly the same thing?
And those check boxes are kind of against the idiomatic Jenkins way for configuring hooks, i.e. through Poll SCM
I really think all this needs a good tidy up... but I am not going to take that on in this PR ;-)
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.
(FTR the "Build when a message is published to an SQS Queue" sounds more that a bit scary... what kind of message and what queue? Does it mean that every time any message is pushed to any SQS Queue anywhere in the world that my build will be triggered?)
@@ -4,6 +4,7 @@ | |||
import com.cloudbees.jenkins.GitHubRepositoryName; | |||
import com.cloudbees.jenkins.GitHubRepositoryNameContributor; | |||
import com.cloudbees.jenkins.GitHubTrigger; | |||
import com.cloudbees.jenkins.GitHubTrigger2; |
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.
Unused import AFAICT.
So just to show useless information in UI you are adding useless hard dependencies, deprecating and hacking everything around? That will all end that nobody outside CB will be able to consume and implement plugins based on such code. For example credentials-plugin - nobody knows how to use it. |
Well writing out your anger certainly helps process it. But SCM API update was only a problem for GitHub Branch Source and BitBucket Branch Source plugins. I didn't even need to update Subversion as it was fine with the updated SCM API. I only updated GIT and Mercurial because they could both significantly benefit from the event apis, (and because I needed to in order to fix GitHub Branch Source and BitBucket Branch Source plugins), but from a "oh we upgraded SCM API" perspective, the 1.x -> 2.x transition for SCM API does not mandate an upgrade to the Git plugin (but we gain improvements from the update) SCM API is designed to be as minimal as possible. In the longer term, we're probably going to pull all the SCM stuff out of core and into SCM API where we can provide plugin authors with better guidance and try to consolidate and tidy up a lot of the mess that has evolved in the various plugins (everyone implementing their own thread pools for polling; lack of consolidated eventing; etc) I would really like to know what your objection is to SCM API |
Next on my todo list are implementation, consumer and user guides for credentials plugin. |
GH plugin implementing eventing and it works fine it doesn't require to hack multiple plugins. I have good experience with github-plugin API + github-integration/pullrequest-plugins. They work great without any additional plugins, dependency tree is/was clear. Keeping in mind that i want switch one day from github-api library i'm not so strong on polluting this plugin ;) |
/** | ||
* Called when a POST is made. | ||
*/ | ||
public void onPost(final String origin, String triggeredByUser) { |
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.
S maybe replace it with more common object with fields that will be expandable in future?
We have customers with phantom builds that they don't know where they are being triggered from. I have seen non-customer users with the same problem. So I disagree that the information is useless. It is only useless until you have builds being triggered causing unnecessary deployment int production... when you have that situation it is essential. I am bumping a dependency that this plugin should really be depending on. Triggering scm builds will need to be consolidated into the scm event path for this plugin anyway. |
Origin is only one of multiple things that may be needed for debugging. System logger is standart pattern for debugging issues in jenkins. |
@@ -75,6 +77,13 @@ public void onPost() { | |||
* Called when a POST is made. | |||
*/ | |||
public void onPost(String triggeredByUser) { | |||
onPost(SCMEvent.originOf(Stapler.getCurrentRequest()), triggeredByUser); |
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.
So why not call Stapler.getCurrentRequest()
in GitHubTrigger
implementation, it still the same thread?
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.
From all what i see (threading) you can call Stapler.getCurrentRequest()
in eventsubscriber/trigger impl
That assumes that all callers of the api are doing the call from a stapler request. If somebody is relaying requests between masters, there may be no request but the origin has been relayed (and relay appended) Hence better to have the origin as an explicit parameter |
And that is really crappy when trying to trace why a job got built. The logs have rotated away before you can find out. Jobs already retain the cause of their build. They should include tracing information for that cause. |
So it only CB enterprise issue?
So wrap it to object along with |
Crap is system settings that requires restart master, you and other still adding them into jenkins and plugins and ignoring my suggestions to stop doing it without ui/system settings. https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java#L1782 wonderful example! Introduced because some people don't want to see verbose/too much information about build. |
fed2636
to
45ade81
Compare
processEvent() and everything else still on String arg |
} | ||
|
||
@Override | ||
public String toString() { |
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.
Gratuitous for a throwaway builder.
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.
perhaps... until you have to debug one
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.
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 usually placing reflection tostring builder because people always forget to add new fields. And in any way jenkins can't work with java security.
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.
Personally like idea with wrapper-objects for events.
But GithubTrigger2 smells like very bad thing. I'd like to avoid. Its already ignoring interface to search trigger: triggerFrom(job, GitHubPushTrigger.class)
- so we don't call interface anywhere - isn't it?
} | ||
|
||
@Override | ||
public boolean equals(Object o) { |
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.
time to try lombok?
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.
IMO way more magic danger than it is worth.
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.
ok, agree, should be tested separately
@@ -57,7 +59,7 @@ | |||
* | |||
* @author Kohsuke Kawaguchi | |||
*/ | |||
public class GitHubPushTrigger extends Trigger<Job<?, ?>> implements GitHubTrigger { | |||
public class GitHubPushTrigger extends Trigger<Job<?, ?>> implements GitHubTrigger2 { |
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.
can we just drop this Interface implementation? Do you know somebody who use it?
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.
You can't know who is using it.
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.
so we can just continue to implement old interface (marked as deprecated) and do nothing with its methods and just use brand new method
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.
Or switch to java8?
|
||
verify(trigger).onPost(TRIGGERED_BY_USER_FROM_RESOURCE); | ||
verify(trigger).onPost(GitHubTriggerEvent.create() |
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 should be verify(trigger).onPost(same(...))
(with matcher?)
76cf356
to
a0567d6
Compare
@@ -87,6 +102,9 @@ private boolean runPolling() { | |||
PrintStream logger = listener.getLogger(); | |||
long start = System.currentTimeMillis(); | |||
logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); | |||
if (event.getOrigin() != null) { | |||
logger.format("Started by event from %s on %tc%n", event.getOrigin(), event.getTimestamp()); |
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.
if you made toString, then simply print event
* | ||
* @since 1.25.2 | ||
*/ | ||
public class GHSubscriberEvent extends SCMEvent<String> { |
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.
So you are adding hard dependency on plugin that community never discussed to design?
Where it and it's design was discussed with community/devs? https://github.com/jenkinsci/scm-api-plugin/graphs/contributors How that happened that your plugin become hard dependency for everybody and everybody should depend on it? |
Opening release sources https://github.com/jenkinsci/scm-api-plugin/tree/d03e1d08c8cc800e3edc361b3b313bf69ece67ef no docs, how at all it happenned to be dependency for everybody... |
} | ||
|
||
@Override | ||
public String toString() { |
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.
perhaps... until you have to debug one
@@ -15,6 +15,7 @@ | |||
* and triggers a build. | |||
* | |||
* @author aaronwalker | |||
* @deprecated extend {@link GitHubTrigger2} instead |
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 wonder if this interface is required for https://github.com/jenkinsci/github-sqs-plugin/blob/master/src/main/java/com/base2services/jenkins/SqsBuildTrigger.java or if it is a gratuitous linkage between the two plugins. It is the only OSS consumer of this interface... the only reason for it to exist is so that the two trigger options will both work for triggering builds... which seems a really crappy UX
i.e. is it obvious to the user that checking one or both of the above check boxes will do exactly the same thing?
And those check boxes are kind of against the idiomatic Jenkins way for configuring hooks, i.e. through Poll SCM
I really think all this needs a good tidy up... but I am not going to take that on in this PR ;-)
@@ -15,6 +15,7 @@ | |||
* and triggers a build. | |||
* | |||
* @author aaronwalker | |||
* @deprecated extend {@link GitHubTrigger2} instead |
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.
(FTR the "Build when a message is published to an SQS Queue" sounds more that a bit scary... what kind of message and what queue? Does it mean that every time any message is pushed to any SQS Queue anywhere in the world that my build will be triggered?)
@@ -85,14 +86,19 @@ protected void onEvent(GHEvent event, String payload) { | |||
@Override | |||
public void run() { | |||
for (Item job : Jenkins.getInstance().getAllItems(Item.class)) { | |||
GitHubTrigger trigger = triggerFrom(job, GitHubPushTrigger.class); | |||
GitHubPushTrigger trigger = triggerFrom(job, GitHubPushTrigger.class); |
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.
Highlights the pointlessness of the GitHubTrigger interface when the only other user could avoid it completely: https://github.com/jenkinsci/github-sqs-plugin/blob/d5886f8c3669e4ca61c1c359cd216aca713c7aeb/src/main/java/com/base2services/jenkins/github/GitHubTriggerProcessor.java#L87 which doesn't need to down-cast to the interface type as it knows that the triggerClass
is always SqsBuildTrigger
Well the current long term goals is to move most stuff out of core and into separate plugins. While we could pull the existing (crappy) SCM classes into their own plugin, to my mind it makes more sense to move them into SCM API. When/if it comes time to move them, rest assured that - if I am involved - there will be a discussion with the community.
Well most people see the multi-branch stuff as the way forward, SCM API is the API that these things are built on top of. I have tried to keep separation of concerns (with the added cognitive costs involved) such that the multibranch stuff is all in Branch API while the pure SCM related stuff is in SCM API. I have provided guides for people to develop competing alternatives to Branch API. Just because I see Branch API as the best approach does not mean I am arrogant and believe it is the "one true solution". Ideally the How many people are complaining about the efforts I am putting into the SCM API and Branch APIs? From what I can see (other than bugs that need fixing) almost everyone likes the SCM API and Branch API approach - but perhaps people are afraid to speak up (which saddens me). I really do not want to go down the hard-fork path that you seem to want to push everyone towards. I hope this is just another case of "Lost in Translation" |
I think the test failure is unrelated:
|
No, you didn't get my point. Direction is good, but it done in the same way as started contributing in jenkins. I can show example, you blocked CloudProvisioningRequest enhancement PR and most of improvements for cloud in core, then you say that you want cloud-api-plugin, ok. People ready to participate (i.e. me), but nothing can't happen without devs from company X. I definitely sure that acegi will be replaced with spring-security only when it will be needed for company X needs. I'm also J developer (unfortunately) and reading development mail list. I don't remember any related discussion, i see only that somebody came from company X and says "it's future, use it". Docs? Later! Just merge and use plugin XX. Where is communication with community (if it still exists)?
Most of people even doesn't know that such plugins exists. Like != code and use it. Documentation appeared only in december afair. I got description from @jglick not so long ago. I don't talk even about dependency mess. One of solution that i saw from people - remove workflow plugins from production instance. But it other story.
I push to do better communication/design BEFORE doing something and not AFTER ("deal with it"). Mine rewritten (in some sense forked by functionality) plugins doesn't affect any other plugins, so i have no need to disturb anybody (excluding libraries like github-api). org-folder, branch/scm/etc affects everybody, but not discussed with everybody. You can get release/fix for any plugin you want, community - can't. |
That's java 😄 If it pass locally, then ok. |
Rest assured I am very frustrated that I have not been given time to fix the Cloud API problems
Actually I have a plan to bypass the need to do that... and I have agreement to let me do some quick experiments, but right now I am trying to tidy up some other bigger messes |
And then it ends with security-plugin? 🤣 |
Yes, I agree that the documentation should have been written sooner, but there is documentation now and I even documented a clear clean path for implementing the old-style SCM API in a modern way.
What is the dependency mess in SCM API? SCM API specifically has no additional runtime dependencies Now if you are talking about the maze of pipeline dependencies, I hear you, but how is that relevant to this plugin? |
I don't remember details but some scm related stuff was moved from workflow plugins into git and then everything bomb. Maybe not related directly to scm, but related to use/do modern apis. |
@lanwen are we good to go? |
released as |
@lanwen please squash/fixup commits in one without mentioning user next time. Now i have useless highlights from commits. |
See JENKINS-41811
Downstream of jenkinsci/scm-api-plugin#27
Upstream of changes in GitHub Branch Source to start exposing the event origin
See also jenkinsci/branch-api-plugin#79 (includes screenshots of events from GitHub Branch Source with this PRs changes integrated)
@reviewbybees
This change is