Azure / apiops

APIOps applies the concepts of GitOps and DevOps to API deployment. By using practices from these two methodologies, APIOps can enable everyone involved in the lifecycle of API design, development, and deployment with self-service and automated tools to ensure the quality of the specifications and APIs that they’re building.
https://azure.github.io/apiops
MIT License
319 stars 186 forks source link

[BUG] API with Logic App backend fails publishing when deleted #346

Closed covterence closed 1 year ago

covterence commented 1 year ago

Release version

4.5.0

Describe the bug

When an API with a Logic App backend is deleted from DEV, publishing failed at the job "Push changes to Dev APIM" on the step trying to delete a policy of an operation that no longer exists. Not all APIs have this problem. The Petstore OAS3 (without any operations in subfolders) works fine. info: Publisher[0] Deleting policy policy for operation manual-invoke in api covtltestapi-logic-app... crit: Publisher[0] System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/integration/providers/Microsoft.ApiManagement/service/covtlapim/apis/covtltestapi-logic-app/operations/manual-invoke/policies/policy?api-version=2022-04-01-preview&format=rawxml failed with status code 404. Content is '{"error":{"code":"ResourceNotFound","message":"Operation not found.","details":null}}'. at common.HttpPipelineExtensions.Validate(Response response, Uri requestUri) at common.HttpPipelineExtensions.DeleteResource(HttpPipeline pipeline, Uri uri, CancellationToken cancellationToken) at publisher.Program.<>c__DisplayClass10_0.<<GetDeleteRestResource>b__0>d.MoveNext() --- End of stack trace from previous location --- at publisher.ApiOperationPolicy.Delete(ApiOperationPolicyName policyName, ApiOperationName operationName, ApiName apiName, ServiceUri serviceUri, DeleteRestResource deleteRestResource, ILogger logger, CancellationToken cancellationToken) at publisher.ApiOperationPolicy.<>c__DisplayClass0_0.<<ProcessDeletedArtifacts>b__1>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Parallel.<>c__501.<b__50_0>d.MoveNext() --- End of stack trace from previous location --- at common.IEnumerableExtensions.ForEachParallel[T](IEnumerable1 enumerable, Func2 action, CancellationToken cancellationToken) at publisher.ApiOperationPolicy.ProcessDeletedArtifacts(IReadOnlyCollection1 files, ServiceDirectory serviceDirectory, ServiceUri serviceUri, DeleteRestResource deleteRestResource, ILogger logger, CancellationToken cancellationToken) at publisher.Service.ProcessDeletedArtifacts(IReadOnlyCollection1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, PutRestResource putRestResource, DeleteRestResource deleteRestResource, ILogger logger, CancellationToken cancellationToken) at publisher.Publisher.ProcessDeletedCommitIdFiles(IReadOnlyCollection1 deletedCommitIdFiles, CancellationToken cancellationToken) at publisher.Publisher.RunWithCommitId(CommitId commitId, CancellationToken cancellationToken) at publisher.Publisher.Run(CancellationToken cancellationToken) at publisher.Publisher.ExecuteAsync(CancellationToken cancellationToken) info: Microsoft.Hosting.Lifetime[0] Application is shutting down...

Expected behavior

No error when publishing back to Dev

Actual behavior

Pipeline failed

Reproduction Steps

  1. Create an API in Dev APIM with a Logic App backend using "Create from Azure resource"
  2. Create named value in configuration.prod.yaml and secrete value for the new sig. Run extractor and publisher to publish to Prod.
  3. Delete the Logic App API on Dev APIM.
  4. Run extractor and publisher again. The job failed at the task "Run publisher for Dev environment".
waelkdouh commented 1 year ago

@guythetechie is it possible that the publisher is trying to publish to a missing entity after it has been deleted?

timjp87 commented 1 year ago

I'm currently facing the same issue. I had one API that is now obsolete, so i deleted it. Now the entire Release pipeline is broken as it can not publish back to DEV afer extractring so no QA or PROD deployment.

timjp87 commented 1 year ago

I worked around this by recreating the obsolete API and backend in DEV and then rerun the failed publisher pipeline jobs. It then properly deleted the resources in DEV, QA and PROD.

Be careful to recreate them the same they are in your higher environments. If you had a typo when naming your API initially this typo lives on in the ID forever so you need to create them with the DisplayName having the typo again otherwise it won't find it again. Not sure why Azure APIM doesn't simply give things UUIDs but derives from the DisplayName.