Skip to content

Commit af5b1c0

Browse files
Bamboo hotfix app specific dataset (#741)
* fix for app specific dataset * fix post run analytics collector
1 parent abe43c5 commit af5b1c0

File tree

3 files changed

+108
-69
lines changed

3 files changed

+108
-69
lines changed

app/jmeter/bamboo.jmx

Lines changed: 85 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@
169169
<stringProp name="Argument.value">${__P(perc_view_projects_list, 0)}</stringProp>
170170
<stringProp name="Argument.metadata">=</stringProp>
171171
</elementProp>
172+
<elementProp name="perc_standalone_extension" elementType="Argument">
173+
<stringProp name="Argument.name">perc_standalone_extension</stringProp>
174+
<stringProp name="Argument.value">${__P(perc_standalone_extension, 0)}</stringProp>
175+
<stringProp name="Argument.metadata">=</stringProp>
176+
</elementProp>
172177
</collectionProp>
173178
</Arguments>
174179
<hashTree/>
@@ -687,77 +692,92 @@ if ( sleep_time &gt; 0 ) {
687692
<stringProp name="parameters"></stringProp>
688693
<stringProp name="filename"></stringProp>
689694
<stringProp name="cacheKey">true</stringProp>
690-
<stringProp name="script">log.info(&quot;PARSING JOB_ID for user ${username}, job_id ${job_id}&quot;)</stringProp>
695+
<stringProp name="script">log.info(&quot;PARSING JOB_ID for user ${username}, build_id ${build_id}, job_id ${job_id}&quot;)</stringProp>
691696
</JSR223PostProcessor>
692697
<hashTree/>
693698
</hashTree>
694699
</hashTree>
695-
<TransactionController guiclass="TransactionControllerGui" testclass="TransactionController" testname="jmeter_view_build_result:view_job_result" enabled="true">
696-
<boolProp name="TransactionController.includeTimers">false</boolProp>
697-
<boolProp name="TransactionController.parent">true</boolProp>
698-
</TransactionController>
700+
<IfController guiclass="IfControllerPanel" testclass="IfController" testname="if job id exists" enabled="true">
701+
<stringProp name="IfController.condition">${__groovy(vars.get(&quot;job_id&quot;) != &quot;NOT_FOUND&quot;)}</stringProp>
702+
<boolProp name="IfController.evaluateAll">false</boolProp>
703+
<boolProp name="IfController.useExpression">true</boolProp>
704+
</IfController>
699705
<hashTree>
700-
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="120 /browse/job" enabled="true">
701-
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
702-
<collectionProp name="Arguments.arguments"/>
703-
</elementProp>
704-
<stringProp name="HTTPSampler.domain"></stringProp>
705-
<stringProp name="HTTPSampler.port"></stringProp>
706-
<stringProp name="HTTPSampler.protocol"></stringProp>
707-
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
708-
<stringProp name="HTTPSampler.path">${application.postfix}/browse/${build_id}-${job_id}</stringProp>
709-
<stringProp name="HTTPSampler.method">GET</stringProp>
710-
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
711-
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
712-
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
713-
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
714-
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
715-
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
716-
<stringProp name="HTTPSampler.response_timeout"></stringProp>
717-
</HTTPSamplerProxy>
706+
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="JSR223 PostProcessor" enabled="true">
707+
<stringProp name="scriptLanguage">groovy</stringProp>
708+
<stringProp name="parameters"></stringProp>
709+
<stringProp name="filename"></stringProp>
710+
<stringProp name="cacheKey">true</stringProp>
711+
<stringProp name="script">log.info(&quot; ${username}, build_id ${build_id}, job_id ${job_id}&quot;)</stringProp>
712+
</JSR223PostProcessor>
713+
<hashTree/>
714+
<TransactionController guiclass="TransactionControllerGui" testclass="TransactionController" testname="jmeter_view_build_result:view_job_result" enabled="true">
715+
<boolProp name="TransactionController.includeTimers">false</boolProp>
716+
<boolProp name="TransactionController.parent">true</boolProp>
717+
</TransactionController>
718718
<hashTree>
719-
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
720-
<collectionProp name="HeaderManager.headers">
721-
<elementProp name="Accept-Language" elementType="Header">
722-
<stringProp name="Header.name">Accept-Language</stringProp>
723-
<stringProp name="Header.value">en-US,en;q=0.5</stringProp>
724-
</elementProp>
725-
<elementProp name="Accept" elementType="Header">
726-
<stringProp name="Header.name">Accept</stringProp>
727-
<stringProp name="Header.value">text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</stringProp>
728-
</elementProp>
729-
<elementProp name="Upgrade-Insecure-Requests" elementType="Header">
730-
<stringProp name="Header.name">Upgrade-Insecure-Requests</stringProp>
731-
<stringProp name="Header.value">1</stringProp>
732-
</elementProp>
733-
<elementProp name="Cache-Control" elementType="Header">
734-
<stringProp name="Header.name">Cache-Control</stringProp>
735-
<stringProp name="Header.value">no-cache</stringProp>
736-
</elementProp>
737-
<elementProp name="Accept-Encoding" elementType="Header">
738-
<stringProp name="Header.name">Accept-Encoding</stringProp>
739-
<stringProp name="Header.value">gzip, deflate</stringProp>
740-
</elementProp>
741-
</collectionProp>
742-
</HeaderManager>
743-
<hashTree/>
744-
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response Assertion" enabled="true">
745-
<collectionProp name="Asserion.test_strings"/>
746-
<stringProp name="Assertion.custom_message">Job summary</stringProp>
747-
<stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
748-
<boolProp name="Assertion.assume_success">false</boolProp>
749-
<intProp name="Assertion.test_type">2</intProp>
750-
</ResponseAssertion>
751-
<hashTree/>
752-
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="JSR223 PostProcessor" enabled="true">
753-
<stringProp name="scriptLanguage">groovy</stringProp>
754-
<stringProp name="parameters"></stringProp>
755-
<stringProp name="filename"></stringProp>
756-
<stringProp name="cacheKey">true</stringProp>
757-
<stringProp name="script">log.info(&quot;Job_id: ${job_id} for user ${username}&quot;)
719+
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="120 /browse/job" enabled="true">
720+
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
721+
<collectionProp name="Arguments.arguments"/>
722+
</elementProp>
723+
<stringProp name="HTTPSampler.domain"></stringProp>
724+
<stringProp name="HTTPSampler.port"></stringProp>
725+
<stringProp name="HTTPSampler.protocol"></stringProp>
726+
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
727+
<stringProp name="HTTPSampler.path">${application.postfix}/browse/${build_id}-${job_id}</stringProp>
728+
<stringProp name="HTTPSampler.method">GET</stringProp>
729+
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
730+
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
731+
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
732+
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
733+
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
734+
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
735+
<stringProp name="HTTPSampler.response_timeout"></stringProp>
736+
</HTTPSamplerProxy>
737+
<hashTree>
738+
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
739+
<collectionProp name="HeaderManager.headers">
740+
<elementProp name="Accept-Language" elementType="Header">
741+
<stringProp name="Header.name">Accept-Language</stringProp>
742+
<stringProp name="Header.value">en-US,en;q=0.5</stringProp>
743+
</elementProp>
744+
<elementProp name="Accept" elementType="Header">
745+
<stringProp name="Header.name">Accept</stringProp>
746+
<stringProp name="Header.value">text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</stringProp>
747+
</elementProp>
748+
<elementProp name="Upgrade-Insecure-Requests" elementType="Header">
749+
<stringProp name="Header.name">Upgrade-Insecure-Requests</stringProp>
750+
<stringProp name="Header.value">1</stringProp>
751+
</elementProp>
752+
<elementProp name="Cache-Control" elementType="Header">
753+
<stringProp name="Header.name">Cache-Control</stringProp>
754+
<stringProp name="Header.value">no-cache</stringProp>
755+
</elementProp>
756+
<elementProp name="Accept-Encoding" elementType="Header">
757+
<stringProp name="Header.name">Accept-Encoding</stringProp>
758+
<stringProp name="Header.value">gzip, deflate</stringProp>
759+
</elementProp>
760+
</collectionProp>
761+
</HeaderManager>
762+
<hashTree/>
763+
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response Assertion" enabled="true">
764+
<collectionProp name="Asserion.test_strings"/>
765+
<stringProp name="Assertion.custom_message">Job summary</stringProp>
766+
<stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
767+
<boolProp name="Assertion.assume_success">false</boolProp>
768+
<intProp name="Assertion.test_type">2</intProp>
769+
</ResponseAssertion>
770+
<hashTree/>
771+
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="JSR223 PostProcessor" enabled="true">
772+
<stringProp name="scriptLanguage">groovy</stringProp>
773+
<stringProp name="parameters"></stringProp>
774+
<stringProp name="filename"></stringProp>
775+
<stringProp name="cacheKey">true</stringProp>
776+
<stringProp name="script">log.info(&quot;Job_id: ${job_id} for user ${username}&quot;)
758777
</stringProp>
759-
</JSR223PostProcessor>
760-
<hashTree/>
778+
</JSR223PostProcessor>
779+
<hashTree/>
780+
</hashTree>
761781
</hashTree>
762782
</hashTree>
763783
<TestAction guiclass="TestActionGui" testclass="TestAction" testname="pacing - end" enabled="true">
@@ -1487,7 +1507,7 @@ if (actual_username != app_specific_username) {
14871507
<hashTree/>
14881508
</hashTree>
14891509
</hashTree>
1490-
<IfController guiclass="IfControllerPanel" testclass="IfController" testname="login_as_default_user_if_specific_user_was_loggedin " enabled="false">
1510+
<IfController guiclass="IfControllerPanel" testclass="IfController" testname="login_as_default_user_if_specific_user_was_loggedin " enabled="true">
14911511
<stringProp name="IfController.condition">${run_as_specific_user}</stringProp>
14921512
<boolProp name="IfController.evaluateAll">false</boolProp>
14931513
<boolProp name="IfController.useExpression">true</boolProp>

app/util/analytics/bamboo_post_run_collector.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
from multiprocessing.pool import ThreadPool
3+
import datetime
34

45
from util.api.bamboo_clients import BambooClient
56
from util.conf import BAMBOO_SETTINGS
@@ -15,6 +16,7 @@ def __init__(self, locust_log):
1516
user=BAMBOO_SETTINGS.admin_login, password=BAMBOO_SETTINGS.admin_password)
1617
self.locust_log = locust_log
1718
self.locust_build_job_results = self.parallel_get_all_builds_results()
19+
self.start_analytics_utc_time = datetime.datetime.now(datetime.timezone.utc)
1820

1921
def parallel_get_all_builds_results(self):
2022
locust_log_lines = self.locust_log.get_locust_log()
@@ -28,6 +30,17 @@ def parallel_get_all_builds_results(self):
2830
all_builds_job_results_lists = pool.map(self.client.get_build_job_results, [i for i in build_job_id_list])
2931
return all_builds_job_results_lists
3032

33+
def is_build_starts_last_n_seconds(self, build_result, n_sec):
34+
build_start_time_regexp = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}"
35+
build_start_match = re.search(build_start_time_regexp, build_result['buildStartedTime'])
36+
build_start_datetime = datetime.datetime.strptime(build_start_match.group(), '%Y-%m-%dT%H:%M:%S').\
37+
replace(tzinfo=datetime.timezone.utc)
38+
build_start_in_last_n_sec = build_start_datetime > (self.start_analytics_utc_time
39+
- datetime.timedelta(seconds=n_sec))
40+
41+
build_in_progress = build_result['lifeCycleState'] == 'InProgress' and build_result['buildDuration'] == 0
42+
return build_in_progress and build_start_in_last_n_sec
43+
3144
@property
3245
def unexpected_status_plan_count(self):
3346
unexpected_finished_plan_count = 0
@@ -39,7 +52,9 @@ def unexpected_status_plan_count(self):
3952
raise Exception(f'ERROR: Could not parse expected plan status from the plan name {plan_name}')
4053
expected_status = expected_status.group(1)
4154
if expected_status not in plan_result:
42-
unexpected_finished_plan_count = unexpected_finished_plan_count + 1
55+
if not self.is_build_starts_last_n_seconds(build_result,
56+
BAMBOO_SETTINGS.default_dataset_plan_duration*2):
57+
unexpected_finished_plan_count = unexpected_finished_plan_count + 1
4358
return unexpected_finished_plan_count
4459

4560
def get_plan_count_with_n_queue(self, n_sec):
@@ -58,5 +73,7 @@ def unexpected_duration_plan_count(self):
5873
unexpected_duration_plans_count = 0
5974
for build_result in self.locust_build_job_results:
6075
if not expected_min_duration <= build_result['buildDuration']/1000 <= expected_max_duration:
61-
unexpected_duration_plans_count = unexpected_duration_plans_count + 1
76+
if not self.is_build_starts_last_n_seconds(build_result,
77+
BAMBOO_SETTINGS.default_dataset_plan_duration * 2):
78+
unexpected_duration_plans_count = unexpected_duration_plans_count + 1
6279
return unexpected_duration_plans_count

app/util/data_preparation/bamboo_prepare_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
def get_users(client, users_count):
1818
existing_users = client.get_users(users_count)
19+
existing_users = [user for user in existing_users if user['name'] != 'admin']
20+
1921
users_to_generate = 0
2022
users = []
21-
if len(existing_users) < users_count:
23+
if len(existing_users) <= users_count:
2224
users_to_generate = users_count - len(existing_users)
2325
users.extend(existing_users)
2426
if users_to_generate:
@@ -71,7 +73,7 @@ def write_test_data_to_files(dataset):
7173
build_plans = [f"{dataset[PROJECTS][build_plan['searchEntity']['projectName']]},{build_plan['id']}" for
7274
build_plan in dataset[BUILD_PLANS]]
7375
__write_to_file(BAMBOO_BUILD_PLANS, build_plans)
74-
users = [f"{user['name']},{DEFAULT_PASSWORD}" for user in dataset[USERS] if user['name'] != 'admin']
76+
users = [f"{user['name']},{DEFAULT_PASSWORD}" for user in dataset[USERS]]
7577
__write_to_file(BAMBOO_USERS, users)
7678

7779

0 commit comments

Comments
 (0)