apiops
apiops copied to clipboard
[BUG] publishing API failes with `Microsoft.WindowsAzure.ApiManagement.Management.Core.Exceptions.PreconditionFailedException`
Release version
v5.1.1
Describe the bug
Publishing an api with a revision included in the name causes the publisher to fail with the following logs:
info: Publisher[0]
Putting API my-api-v1-b2b;rev=1...
dbug: PutRestResource[0]
Beginning request to put REST resource URI https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Microsoft.ApiManagement/service/poc-apiops-dev/apis/my-api-v1-b2b;rev=1?api-version=2022-04-01-preview...
dbug: PutRestResource[0]
Beginning request to put REST resource URI https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Microsoft.ApiManagement/service/poc-apiops-dev/apis/my-api-v1-b2b?api-version=2022-04-01-preview...
dbug: PutRestResource[0]
Successfully put REST resource at URI https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Microsoft.ApiManagement/service/poc-apiops-dev/apis/my-api-v1-b2b;rev=1?api-version=2022-04-01-preview.
crit: Publisher[0]
System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Microsoft.ApiManagement/service/poc-apiops-dev/apis/my-api-v1-b2b?api-version=2022-04-01-preview&asyncId=65d505a9dab0190ea44116c4&asyncCode=200&t=63844056233[460](https://github.corp.fundserv.com/FundSERV/api_ops_poc/actions/runs/17734/job/47941#step:8:461)9245&c=MIIHADCCBeigAwIBAgITfARmUs4KPxjtgZmnLQAABGZSzjANBgkqhkiG9w0BAQsFADBEMRMwEQYKCZImiZPyLGQBGRYDR0JMMRMwEQYKCZImiZPyLGQBGRYDQU1FMRgwFgYDVQQDEw9BTUUgSW5mcmEgQ0EgMDUwHhcNMjQwMjAxMDAxMjE1WhcNMjUwMTI2MDAxMjE1WjBAMT4wPAYDVQQDEzVhc3luY29wZXJhdGlvbnNpZ25pbmdjZXJ0aWZpY2F0ZS5tYW5hZ2VtZW50LmF6dXJlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMq-pifi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KIR0fV7kSfWb70qzJd5fH21JFvWQLEcGmrhWLg5W_7x5SlOIWskTRnSqtgOof8vqWq47afd0MPZ62tMFMKopcxRExoVg68rFFTF9MGT8Sqtv_vkBZmQwkvZLy1EvFsMA-vCnSLVRE_FqszObVJSXOdaiNKaXCP-cPP8qU0corhei_waoO-Tm2eyF7cA3WD7tWJqc7muG7-eJtxrX6JPJPH-0BngZHxnku_ao581iW9349j2AW2NEaqJqdQ&h=mm-PzeXa8XekpP-9fAXlFCpZHJYrXr17KQaOnUkqp20 failed with status code 412. Content is '{"error":{"code":"PreconditionFailed","message":"Exception of type 'Microsoft.WindowsAzure.ApiManagement.Management.Core.Exceptions.PreconditionFailedException' was thrown.","details":null}}'.
at common.HttpPipelineExtensions.Validate(Response response, Uri requestUri)
at common.HttpPipelineExtensions.WaitForLongRunningOperation(HttpPipeline pipeline, Response response, CancellationToken cancellationToken)
at common.HttpPipelineExtensions.PutResource(HttpPipeline pipeline, Uri uri, JsonObject resource, CancellationToken cancellationToken)
at publisher.Program.<>c__DisplayClass13_0.<<GetPutRestResource>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at publisher.Api.PutApi(ApiName apiName, ApiInformationFile apiInformationFile, ApiSpecificationFile specificationFile, JsonObject configurationApiJson, ServiceUri serviceUri, GetRestResource getRestResource, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
at publisher.Api.<>c__DisplayClass24_0.<<ProcessArtifactsToPut>b__4>d.MoveNext()
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.<>c__50`1.<<ForEachAsync>b__50_0>d.MoveNext()
--- End of stack trace from previous location ---
at common.IEnumerableExtensions.ForEachParallel[T](IEnumerable`1 enumerable, Func`2 action, CancellationToken cancellationToken)
at publisher.Api.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, GetRestResource getRestResource, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
at publisher.Service.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, GetRestResource getRestResource, PutRestResource putRestResource, DeleteRestResource deleteRestResource, ILogger logger, CancellationToken cancellationToken)
at publisher.Publisher.RunWithoutCommitId(CancellationToken cancellationToken)
at publisher.Publisher.Run(CancellationToken cancellationToken)
at publisher.Publisher.ExecuteAsync(CancellationToken cancellationToken)
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
Where as publishing my-api-v1-b2b, without the ;rev=1 at the end succeeds.
Expected behavior
Publishing an API with the revision in the name should succeed.
Actual behavior
Publishing an API with the revision in the name fails.
Reproduction Steps
With a file structure looking like this, use the publisher to publish an API both with and without a revision
.
├── apis
├── my-api-v1
│ │ ├── apiInformation.json
│ │ ├── policy.xml
│ │ └── specification.json
│ ├── my-api-v1;rev=1
│ │ ├── apiInformation.json
│ │ ├── policy.xml
│ │ └── specification.json
.....
Thank you for opening this issue! Please be patient while we will look into it and get back to you as this is an open source project. In the meantime make sure you take a look at the [closed issues](https://github.com/Azure/apiops/issues?q=is%3Aissue+is%3Aclosed) in case your question has already been answered. Don't forget to provide any additional information if needed (e.g. scrubbed logs, detailed feature requests,etc.).
Whenever it's feasible, please don't hesitate to send a Pull Request (PR) our way. We'd greatly appreciate it, and we'll gladly assess and incorporate your changes.
Did some more testing. This only happens when my-api-v1 and my-api-v1;rev=1 have different configuration. If both API configuration are exactly the same, then the publisher successfully publishes both APIs.
@shawnyu5 what do you mean by 'different configuration'? I am having the same issue with same error message. However, the order of which my API is loaded in is different to yours.
I was previously using v4.10.3 when I first encountered the error. I just tried v.5.1.1 and it is the same
info: Publisher[0]
Putting API myapi;rev=1...
info: Publisher[0]
Putting API myapi...
dbug: PutRestResource[0]
Beginning request to put REST resource URI urimyapi;rev=1...
dbug: PutRestResource[0]
Beginning request to put REST resource URI urimyapi...
dbug: PutRestResource[0]
Successfully put REST resource at URI urimyapi...
crit: Publisher[0]
System.Net.Http.HttpRequestException: HTTP request to URI urimyapi;rev=1 failed with status code 409. Content is '{"error":{"code":"IdentifierAlreadyInUse","message":"Resource already exists.","details":null}}'.
I tried to copy my-api-v1/, and rename it to my-api-v1;rev=1, so both base and rev 1 would have the exact same files. This publishes successfully. However the publisher throws an error when my-api-v1/ and my-api-v1;rev=1 have different configuration values.
ah right, so the api spec is the exactly same. but the whole point of using revision is that the api spec is different so need to wait for a fix/reply from them
@shawnyu5 & @eyvictorye - Publishing APIs with revisions is currently bugged. We will include a fix in our next major release (sometime in the next few weeks).
Hi, I was having this issue with 4.10.2. Having updated to 5.1.4, I'm still having this exact issue with 5.1.4 - was this fixed in any version?
We are going to publish the fix in v6. We just released v6 alpha but it's having some issues so it's not quite ready for testing yet. We are getting close. Stays tuned for v6 soon.
@waelkdouh awesome, will do, thank you. Appreciate your hard work.
Hi, Please could someone suggest when would v6 be releasing, any date and would v6 have fix for above issue?
We are actively working on it. We are hoping to release it in the next couple weeks. We can't promise any timelines as this is an open source project.
v6 was recently released.