Skip to content

Commit e5362ee

Browse files
authored
chore: add docs on disabling dangerous contract modification (#280)
* chore: add docs on disabling dangerous contract modification * chore: update docs regarding dangerous contract modification
1 parent 9177a4d commit e5362ee

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Disabling dangerous contract modification
2+
3+
## Background
4+
5+
When a contract is published, it is associated with the application version that generated the contract.
6+
7+
When the Pact Broker (the OSS project on which PactFlow is based) was first created, the contract content for an existing application version was allowed to be modified. When the `can-i-deploy` feature was released however, it became apparent that allowing modification of a contract for a particular consumer version was causing `can-i-deploy` to be unreliable. The result would depend on which branch had last published a contract.
8+
9+
To prevent this scenario without breaking pipelines that depended on contract modification, the PactFlow configuration setting `allow_dangerous_contract_modification` was introduced. All new SaaS accounts and new on-premises installations from August 2021 were configured to disallow contract modification for a given application version.
10+
11+
Contract modification is still allowed for accounts and installations created before August 2021, and this can cause problems when the versioning best practice guidelines are not followed. We strongly recommend that contract modification is disabled for all SaaS accounts and on-premises installations.
12+
13+
You may choose to disable contract modification and fix affected pipelines afterwards, or you may wish to identify which pipelines will be affected by the change, and fix them before making the change.
14+
15+
Please follow these instructions below to identify and prevent issues.
16+
17+
## How to identify if dangerous contract modifications are occurring
18+
19+
### Using the metrics endpoint (SaaS and On-Premesis)
20+
21+
* For On-Premises installations, ensure you have version 1.29.0 or later.
22+
* Log in to your PactFlow account.
23+
* Click on the API Browser button in the top right.
24+
* In the `Explorer bar` append `/metrics` to the base URL, and click `Go!`
25+
* In the `Properties` section, locate the object for the `pactRevisionsPerConsumerVersion` key.
26+
* If the `distribution` object has only one key, and that key is "1", then no contracts have been modified.
27+
```
28+
"pactRevisionsPerConsumerVersion": {
29+
"distribution": {
30+
"1": 916
31+
}
32+
},
33+
```
34+
* If there are multiple keys inside the `distribution` object, then contract modification is occurring.
35+
```
36+
"pactRevisionsPerConsumerVersion": {
37+
"distribution": {
38+
"1": 1039,
39+
"2": 58
40+
"3": 356,
41+
"6": 25,
42+
...
43+
"78": 1
44+
}
45+
},
46+
```
47+
48+
### Using the output of the contract publication command (SaaS and On-Premesis)
49+
50+
When modifying a contract for an existing application version, the following text would be shown in the terminal output for a consumer called "Example Consumer" and a provider called "Example Provider":
51+
52+
```
53+
Updated Example Consumer version 1.2.26 with branch master
54+
Pact with changed content published over existing content for Example Consumer version 1.2.26 and provider Example Provider. This is not recommended in normal circumstances and may indicate that you have not configured your Pact pipeline correctly. For more information see https://docs.pact.io/go/versioning
55+
```
56+
57+
If contract modification is disabled, the following error would be shown:
58+
59+
```
60+
Cannot change the content of the pact for Example Consumer version 1.2.26 and provider Example Provider, as race conditions will cause unreliable results for can-i-deploy. Each pact must be published with a unique consumer version number. Some Pact libraries generate random data when a concrete value for a type matcher is not specified, and this can cause the contract to mutate - ensure you have given example values for all type matchers. For more information see https://docs.pact.io/go/versioning
61+
{
62+
"interactions": [
63+
{
64+
- "description": "a request to list TODOs"
65+
+ "description": "a request to list TODOs 2"
66+
}
67+
]
68+
}
69+
```
70+
71+
### Checking the logs (On-Premesis only)
72+
73+
Check the start up logs of the PactFlow application to determine the value for the configuration property `allow_dangerous_contract_modification`. The logs will look like this (depending on your log format):
74+
75+
```
76+
01:18:30 I -- allow_dangerous_contract_modification=false source=...
77+
```
78+
79+
If the value is `false`, then no further action is required.
80+
81+
## How to identify which applications have contracts which are being modified
82+
83+
### SaaS
84+
85+
Please open a [support case](https://support.smartbear.com/pactflow/message) and request the Customer Care team to provide a list of applications with modified contracts.
86+
87+
### On-premesis
88+
89+
Run the following SQL query against the Postgres database:
90+
91+
```sql
92+
select distinct c.name as consumer_name
93+
from pact_publications pp
94+
join (select consumer_version_id
95+
from pact_publications
96+
group by consumer_version_id
97+
having count(*) > 1 ) as mpp
98+
on mpp.consumer_version_id = pp.consumer_version_id
99+
join pacticipants c
100+
on pp.consumer_id = c.id
101+
order by 1
102+
```
103+
104+
## How to avoid contract modification
105+
106+
To ensure a pipeline is publishing contracts in the correct way, follow these guidelines:
107+
108+
* Ensure each contract is published with a deterministic version number that *is* or *contains* the git sha, as per https://docs.pact.io/go/versioning
109+
* If the recommended approach to version numbers is already being used, then it is likely that random data is being used in a pact. You can identify what has changed between pacts by following [this documentation](https://docs.pactflow.io/docs/how_to#see-what-has-changed-in-a-pact). Random data in a pact is often cause by using matcher without providing an example value (in which case, the Pact library provides a random example value). Ensure all matchers have an example value provided. Otherwise, the random data might be being included directly in the test by using test data generation tools.
110+
111+
## Disabling dangerous contract modification
112+
113+
### SaaS
114+
115+
Please open a [support case](https://support.smartbear.com/pactflow/message) and specify that you would like the Customer Care team to disable dangerous contract modification for your account.
116+
117+
118+
## On-premesis
119+
120+
Set the environment variable `PACTFLOW_ALLOW_DANGEROUS_CONTRACT_MODIFICATION=false` and restart the server.

website/sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module.exports = {
117117
{
118118
type: 'category',
119119
label: 'Troubleshooting',
120-
items: ['docs/login-help', `docs/authorization-help`, 'docs/webhooks-help', 'docs/powershell-guide']
120+
items: ['docs/login-help', `docs/authorization-help`, 'docs/webhooks-help', 'docs/powershell-guide', 'docs/troubleshooting/disabling-dangerous-contract-modification']
121121
},
122122
{
123123
type: 'link',

0 commit comments

Comments
 (0)