Problem:
Whenever I run multiple POST requests to create discovery rules in parralel, I ocassionally get a 201
response with a different payload format.
I’m unable to reproduce this if I execute the requests sequentially. More parralel requests I execute, bigger change of hitting this issue:
{"discovery_rule":{"id":742,"name":"57531206","search":"foo","hostgroup_id":125,"hostname":"foo","max_count":0,"priority":29227,"enabled":true,"created_at":"2020-09-16T10:33:11.220Z","updated_at":"2020-09-16T10:33:11.220Z"}}
{"id":745,"name":"304796992","search":"foo","hostgroup_id":125,"hostname":"foo","max_count":0,"priority":17120,"enabled":true,"created_at":"2020-09-16T10:33:12.128Z","updated_at":"2020-09-16T10:33:12.128Z"}
Expected outcome:
Consistent payload format
Foreman and Proxy versions:
foreman-2.1.2.11-2.el7sat.noarch
foreman-proxy-2.1.2-2.el7sat.noarch
Foreman and Proxy plugin versions:
# rpm -qa foreman-*
foreman-postgresql-2.1.2.11-2.el7sat.noarch
foreman-selinux-2.1.2.1-1.el7sat.noarch
foreman-ec2-2.1.2.11-2.el7sat.noarch
foreman-service-2.1.2.11-2.el7sat.noarch
foreman-debug-2.1.2.11-2.el7sat.noarch
foreman-vmware-2.1.2.11-2.el7sat.noarch
foreman-dynflow-sidekiq-2.1.2.11-2.el7sat.noarch
foreman-bootloaders-redhat-tftpboot-202005201200-1.el7sat.noarch
foreman-proxy-2.1.2-2.el7sat.noarch
foreman-discovery-image-3.6.5-1.el7sat.noarch
foreman-installer-2.1.2.6-1.el7sat.noarch
foreman-installer-katello-2.1.2.6-1.el7sat.noarch
foreman-openstack-2.1.2.11-2.el7sat.noarch
foreman-bootloaders-redhat-202005201200-1.el7sat.noarch
foreman-gce-2.1.2.11-2.el7sat.noarch
foreman-libvirt-2.1.2.11-2.el7sat.noarch
foreman-ovirt-2.1.2.11-2.el7sat.noarch
foreman-cli-2.1.2.11-2.el7sat.noarch
`# rpm -qa katello-*
katello-default-ca-1.0-1.noarch
katello-client-bootstrap-1.7.5-1.el7sat.noarch
katello-debug-3.16.0-1.el7sat.noarch
katello-server-ca-1.0-1.noarch
katello-certs-tools-2.7.1-1.el7sat.noarch
katello-selinux-3.4.0-1.el7sat.noarch
katello-ca-consumer-dhcp-8-29-228.lab.eng.rdu2.redhat.com-1.0-5.noarch
katello-common-3.16.0-1.el7sat.noarch`
Distribution and version:
Red Hat Enterprise Linux Server release 7.8 (Maipo)
Other relevant data:
# grep 6b772cdc /var/log/foreman/production.log
2020-09-16T05:09:45 [I|app|6b772cdc] Started POST "/api/v2/discovery_rules" for 127.0.0.1 at 2020-09-16 05:09:45 -0400
2020-09-16T05:09:45 [I|app|6b772cdc] Processing by Api::V2::DiscoveryRulesController#create as JSON
2020-09-16T05:09:45 [I|app|6b772cdc] Parameters: {"discovery_rule"=>{"name"=>"<address>mclMyFZCkHBOTmESILmFzbGKdHXRPTMepDJ</address>", "hostname"=>"myhost-<%= rand(99999) %>", "priority"=>546, "hostgroup_id"=>125, "location_ids"=>[259], "organization_ids"=>[255], "search"=>"memory > 500"}, "apiv"=>"v2"}
2020-09-16T05:09:45 [D|app|6b772cdc] Authenticated user admin against INTERNAL authentication source
2020-09-16T05:09:45 [D|app|6b772cdc] Post-login processing for admin
2020-09-16T05:09:45 [I|app|6b772cdc] Authorized user admin(Admin User)
2020-09-16T05:09:45 [D|app|6b772cdc] Post-login processing for admin
2020-09-16T05:09:45 [D|tax|6b772cdc] Current location set to none
2020-09-16T05:09:45 [D|tax|6b772cdc] Current organization set to none
2020-09-16T05:09:45 [D|tax|6b772cdc] Current location set to none
2020-09-16T05:09:45 [D|tax|6b772cdc] Current organization set to none
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on name <address>mclMyFZCkHBOTmESILmFzbGKdHXRPTMepDJ</address>
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on search memory > 500
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on hostgroup_id 125
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on hostname myhost-<%= rand(99999) %>
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on max_count 0
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on priority 546
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on enabled true
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on organization_ids [255]
2020-09-16T05:09:45 [I|aud|6b772cdc] DiscoveryRule (442) create event on location_ids [259]
2020-09-16T05:09:45 [D|app|6b772cdc] Body: {"discovery_rule":{"id":442,"name":"\u003caddress\u003emclMyFZCkHBOTmESILmFzbGKdHXRPTMepDJ\u003c/address\u003e","search":"memory \u003e 500","hostgroup_id":125,"hostname":"myhost-\u003c%= rand(99999) %\u003e","max_count":0,"priority":546,"enabled":true,"created_at":"2020-09-16T09:09:45.291Z","updated_at":"2020-09-16T09:09:45.291Z"}}
2020-09-16T05:09:45 [I|app|6b772cdc] Completed 201 Created in 244ms (Views: 0.5ms | ActiveRecord: 95.8ms | Allocations: 50630)
===========
# grep 2605d72c /var/log/foreman/production.log
2020-09-16T05:10:42 [I|app|2605d72c] Started POST "/api/v2/discovery_rules" for 127.0.0.1 at 2020-09-16 05:10:42 -0400
2020-09-16T05:10:42 [I|app|2605d72c] Processing by Api::V2::DiscoveryRulesController#create as JSON
2020-09-16T05:10:42 [I|app|2605d72c] Parameters: {"discovery_rule"=>{"name"=>"<frameset>qyPzhDnC</frameset>", "hostname"=>"myhost-<%= rand(99999) %>", "priority"=>463, "hostgroup_id"=>122, "location_ids"=>[256], "organization_ids"=>[252], "search"=>"memory > 500"}, "apiv"=>"v2"}
2020-09-16T05:10:42 [D|app|2605d72c] Authenticated user admin against INTERNAL authentication source
2020-09-16T05:10:42 [D|app|2605d72c] Post-login processing for admin
2020-09-16T05:10:42 [I|app|2605d72c] Authorized user admin(Admin User)
2020-09-16T05:10:42 [D|app|2605d72c] Post-login processing for admin
2020-09-16T05:10:42 [D|tax|2605d72c] Current location set to none
2020-09-16T05:10:42 [D|tax|2605d72c] Current organization set to none
2020-09-16T05:10:42 [D|tax|2605d72c] Current location set to none
2020-09-16T05:10:42 [D|tax|2605d72c] Current organization set to none
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on name <frameset>qyPzhDnC</frameset>
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on search memory > 500
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on hostgroup_id 122
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on hostname myhost-<%= rand(99999) %>
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on max_count 0
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on priority 463
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on enabled true
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on organization_ids [252]
2020-09-16T05:10:42 [I|aud|2605d72c] DiscoveryRule (462) create event on location_ids [256]
2020-09-16T05:10:42 [D|app|2605d72c] Body: {"id":462,"name":"\u003cframeset\u003eqyPzhDnC\u003c/frameset\u003e","search":"memory \u003e 500","hostgroup_id":122,"hostname":"myhost-\u003c%= rand(99999) %\u003e","max_count":0,"priority":463,"enabled":true,"created_at":"2020-09-16T09:10:42.714Z","updated_at":"2020-09-16T09:10:42.714Z"}
2020-09-16T05:10:42 [I|app|2605d72c] Completed 201 Created in 146ms (Views: 0.4ms | ActiveRecord: 41.1ms | Allocations: 28787)
here’s my reproducer (mind that you might need to create and update other entity ids accordingly to your setup:
for i in {1..10}; do curl -sku admin:changeme -H "content-type: application/json" -d "{\"name\": \"$RANDOM$RANDOM\", \"hostname\": \"myhost-<%= rand(99999) %>\", \"priority\": $RANDOM, \"hostgroup_id\": 125, \"location_ids\": [259], \"organization_ids\": [255], \"search\": \"memory > 500\"}" https://<sat_server>/api/v2/discovery_rules; echo ""; done