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

ProcessInstanceInfo set start date when constructed #1705

Merged
merged 7 commits into from
Aug 4, 2020
Merged

ProcessInstanceInfo set start date when constructed #1705

merged 7 commits into from
Aug 4, 2020

Conversation

hmatt1
Copy link
Contributor

@hmatt1 hmatt1 commented Jul 22, 2020

This is my first PR against jbpm 😄 Please let me know if I should open a Jira ticket here for this fix.


In the PrometheusProcessEventListener, the field startDate from a processInstance is used to time the process instance duration metric.
https://github.com/kiegroup/droolsjbpm-integration/blob/4fb9e4c239dfc21ea99ea5b701877cafeafcbe1d/kie-server-parent/kie-server-services/kie-server-services-prometheus/src/main/java/org/kie/server/services/prometheus/PrometheusProcessEventListener.java#L96

However, the start date was always null because it is being set when getProcessInstance is first called.
Since getProcessInstance is not called before we trigger the event listener, the start date was never set.
The ProcessInstance start date should be set when the ProcessInstanceInfo object is first created.

In the `PrometheusProcessEventListener`, the field `startDate` from a `processInstance` is used to time the process instance duration metric.
https://github.com/kiegroup/droolsjbpm-integration/blob/4fb9e4c239dfc21ea99ea5b701877cafeafcbe1d/kie-server-parent/kie-server-services/kie-server-services-prometheus/src/main/java/org/kie/server/services/prometheus/PrometheusProcessEventListener.java#L96

However, the start date was always null because it is being set when `getProcessInstance` is first called.
Since `getProcessInstance` is not called before we trigger the event listener, the start date was never set.
The `ProcessInstance` start date should be set when the `ProcessInstanceInfo` object is first created.
@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

9 similar comments
@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@kie-ci
Copy link

kie-ci commented Jul 22, 2020

Can one of the admins verify this PR? Comment with 'ok to test' to start the build.

@hmatt1
Copy link
Contributor Author

hmatt1 commented Jul 22, 2020

ok to test

Copy link

@deekshajohari deekshajohari left a comment

Choose a reason for hiding this comment

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

i believe we just need to have constructor in WorkflowProcessInstanceImpl() which sets start date to current.

public WorkflowProcessInstanceImpl() {
    this.startDate = new Date();
}

Tested on my local and prometheus metrics were enabled for "kie_server_process_instance_duration_seconds Kie Server Process Instances Duration"

@gmunozfe
Copy link
Member

jenkins retest this please

@deekshajohari
Copy link

I think you also can set it on afterProcessStarted https://github.com/kiegroup/droolsjbpm-integration/blob/4fb9e4c239dfc21ea99ea5b701877cafeafcbe1d/kie-server-parent/kie-server-services/kie-server-services-prometheus/src/main/java/org/kie/server/services/prometheus/PrometheusProcessEventListener.java#L81.

Yes this will work. However I still believe that more appropriate way will be to have start date in the object all the time :-)

@gmunozfe
Copy link
Member

jenkins retest this please

@sonarcloud
Copy link

sonarcloud bot commented Jul 27, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 2 Code Smells

87.5% 87.5% Coverage
0.0% 0.0% Duplication

warning The version of Java (1.8.0_202) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

Copy link
Member

@gmunozfe gmunozfe left a comment

Choose a reason for hiding this comment

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

@hmatt1 thanks a lot for your contribution!
Some comments regarding some stuff that can be removed or moved to a better place, but looks good.
Could you add also a test to check startDates are the same when creating a second ProcessInfo for the same process instance?

The twoProcessInstanceInfoSameStartDateTest was added along with other
minor changes based on review comments
@hmatt1
Copy link
Contributor Author

hmatt1 commented Jul 28, 2020

Thank you @gmunozfe @deekshajohari and @bxf12315 for the review comments! I updated the changes based on @gmunozfe's comments. I'm happy to refactor again if we want to go with what @deekshajohari suggested, to move initializing the startDate to the ProcessInstance instead if you feel we should go that route. That would be a slight change in behavior, since the startDate is currently initialized within the ProcessInstanceInfo.

@hmatt1
Copy link
Contributor Author

hmatt1 commented Jul 28, 2020

@hmatt1 thanks a lot for your contribution!
Some comments regarding some stuff that can be removed or moved to a better place, but looks good.
Could you add also a test to check startDates are the same when creating a second ProcessInfo for the same process instance?

I removed these comments since we now have a test for it.

@gmunozfe
Copy link
Member

jenkins retest this please

Copy link
Member

@elguardian elguardian left a comment

Choose a reason for hiding this comment

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

Hi @hmatt1
Unfortunately I cannot accept this as a fix because the next reasons:

Just some context. The process instance info contains the process instance (just a marshalling of this one) and the relation between one or another is 1:1. Actually once the process instance is completed the process instance info is removed as it is runtime information and there is no need anymore. so the process instance info is created when the process instance is created so its start date means the date when the process is created. I said that because in your test
twoProcessInstanceInfoSameStartDateTest you are setting the two process instance info for the same process instance.

ProcessInstanceInfo start date show when the process instance is created and not when is started. (those are two different things)
WorkflowProcessInstanceImpl start date show when the process is started. While you are right that is not set properly IMO you
should remove the logic you added.
The only thing you need to add here is
https://github.com/kiegroup/jbpm/blob/master/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java#L494
this.startDate = new Date();

this should fix the issue. Keep in mind that processInstanceInfo startDate and workprocessInstanceimpl could have different start dates but it should guaranteed that processInstanceInfo startDate <= workflowprocessinstanceimpl startdate

Would you mind to fix your PR logic and tests ?

PS. thx for catching this problem. good work !

Set the start date when `start()` is called
@hmatt1
Copy link
Contributor Author

hmatt1 commented Jul 31, 2020

Thanks @elguardian for the review! This approach is much simpler 😄 Thanks for the background about process instance info too

@elguardian elguardian self-requested a review August 4, 2020 07:06
Copy link
Member

@elguardian elguardian left a comment

Choose a reason for hiding this comment

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

LGTM. @gmunozfe if this QE ok. we can merge.

Copy link
Member

@gmunozfe gmunozfe left a comment

Choose a reason for hiding this comment

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

Looks good also to me. Thanks for your contribution @hmatt1 !
This is ready to merge @elguardian

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.

6 participants