Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New api/plan endpoint throwing errors due to trying to add status #2456

Closed
endriu0 opened this issue Aug 18, 2022 · 6 comments
Closed

New api/plan endpoint throwing errors due to trying to add status #2456

endriu0 opened this issue Aug 18, 2022 · 6 comments
Labels
bug Something isn't working waiting-on-response Waiting for a response from the user

Comments

@endriu0
Copy link

endriu0 commented Aug 18, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

New api/plan endpoint is working and creating a plan fine but response from atlantis is 500 instead of 201. In logs I see a bunch of errors about the branch being used instead of sha for the api call :

https://github/api/v3/repos/my-org/my-repo/statuses/my-branch

Reproduction Steps

  1. Enable api on atlantis / github
  2. Call the api with similar data :

{
"Repository": "my-org/my-repos",
"Ref": "my-branch",
"Type": "Github",
"Paths": [{
"Directory": "my-directory",
"Workspace": "default"
}]
}

  1. Plan gets returned but the call gives 500
  2. Observe in the logs a bunch of errors about sha being too short for the job.

Logs

Provide log files from Atlantis server

Logs
{"level":"error","ts":"2022-08-18T08:45:07.784Z","caller":"events/project_command_runner.go:165","msg":"updating project PR status%!(EXTRA *github.ErrorResponse=POST https://github/api/v3/repos/my-org/my-repo/statuses/my-branch: 422 Validation Failed [{Resource:Status Field:sha Code:custom Message:sha must be a 40 character SHA1}])","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*ProjectOutputWrapper).updateProjectPRStatus\n\tgithub.com/runatlantis/atlantis/server/events/project_command_runner.go:165\ngithub.com/runatlantis/atlantis/server/events.(*ProjectOutputWrapper).Plan\n\tgithub.com/runatlantis/atlantis/server/events/project_command_runner.go:149\ngithub.com/runatlantis/atlantis/server/events.RunAndEmitStats\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:39\ngithub.com/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandRunner).Plan\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:13\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).apiPlan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:151\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).Plan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:89\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2047\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\tgithub.com/gorilla/mux@v1.8.0/mux.go:210\ngithub.com/urfave/negroni.Wrap.func1\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:46\ngithub.com/urfave/negroni.HandlerFunc.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:29\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/runatlantis/atlantis/server.(*RequestLogger).ServeHTTP\n\tgithub.com/runatlantis/atlantis/server/middleware.go:68\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/urfave/negroni.(*Recovery).ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/recovery.go:193\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/urfave/negroni.(*Negroni).ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:96\nnet/http.serverHandler.ServeHTTP\n\tnet/http/server.go:2879\nnet/http.(*conn).serve\n\tnet/http/server.go:1930"}

{"level":"error","ts":"2022-08-18T08:45:07.784Z","caller":"events/project_command_runner.go:165","msg":"updating project PR status%!(EXTRA *github.ErrorResponse=POST https://github/api/v3/repos/my-org/my-repo/statuses/my-nranch: 422 Validation Failed [{Resource:Status Field:sha Code:custom Message:sha must be a 40 character SHA1}])","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*ProjectOutputWrapper).updateProjectPRStatus\n\tgithub.com/runatlantis/atlantis/server/events/project_command_runner.go:165\ngithub.com/runatlantis/atlantis/server/events.(*ProjectOutputWrapper).Plan\n\tgithub.com/runatlantis/atlantis/server/events/project_command_runner.go:149\ngithub.com/runatlantis/atlantis/server/events.RunAndEmitStats\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:39\ngithub.com/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandRunner).Plan\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:13\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).apiPlan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:151\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).Plan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:89\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2047\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\tgithub.com/gorilla/mux@v1.8.0/mux.go:210\ngithub.com/urfave/negroni.Wrap.func1\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:46\ngithub.com/urfave/negroni.HandlerFunc.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:29\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/runatlantis/atlantis/server.(*RequestLogger).ServeHTTP\n\tgithub.com/runatlantis/atlantis/server/middleware.go:68\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/urfave/negroni.(*Recovery).ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/recovery.go:193\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/urfave/negroni.(*Negroni).ServeHTTP\n\tgithub.com/urfave/negroni@v1.0.0/negroni.go:96\nnet/http.serverHandler.ServeHTTP\n\tnet/http/server.go:2879\nnet/http.(*conn).serve\n\tnet/http/server.go:1930"}

Environment details

If not already included, please provide the following:

  • Atlantis version: v0.19.8
  • If not running the latest Atlantis version have you tried to reproduce this issue on the latest version:
  • Atlantis flags: --enable-policy-checks

Atlantis server-side config file:

Too big to post here - everything working except the new api addition

Repo atlantis.yaml file:

# config file

Any other information you can provide about the environment/deployment.

Github: Github Enterprise server / Self-Hosted

Additional Context

Looks that all that needs to be done is the status-update call needs to be skipped if the call type is on api/plan / api/apply and that should hopefully stop the 500s or if we want to keep it then we should add new field to apicall for sha instead of branch.

@endriu0 endriu0 added the bug Something isn't working label Aug 18, 2022
@endriu0
Copy link
Author

endriu0 commented Aug 24, 2022

Update since a lot of investigation was ongoing in the background.

  1. This only throws 500 when policy checks are enabled. After disabling policy checks it gives 200 correctly even though the errors about not being able to update PR with status check are still there.
  2. My current suspicion is that because we run below in plan step :
                 - run: terraform${ATLANTIS_TERRAFORM_VERSION} plan -input=false -refresh -no-color -out $PLANFILE $CLEAN_ARGS
                  - run: terraform${ATLANTIS_TERRAFORM_VERSION} show -json $PLANFILE > $PLANFILE.json

This $PLANFILE.json is then used by some of our policy checks to including module version / tags etc. When running normal PR the files including .terraform are left there until PR is either closed / applied or unlocked so they can be used by policy checks. On api calls none of those files persist (atleast looking at the pod dir straight after api plan the directory only has default configs as if it was just cloned ). Are we cleaning up the directory after plan step is done or after policy checks are done ?

  1. Big thread with all the above investigation / information on Slack : https://atlantis-community.slack.com/archives/C5MGGAV0C/p1660813744175959

@jamengual jamengual added the waiting-on-response Waiting for a response from the user label Aug 25, 2022
@jamengual
Copy link
Contributor

@lilincmu

@github-actions github-actions bot added the Stale label Sep 26, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2022
@jamengual jamengual reopened this Oct 2, 2022
@github-actions github-actions bot removed the Stale label Oct 3, 2022
@github-actions
Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

@github-actions github-actions bot added the Stale label Mar 12, 2023
@parmouraly
Copy link
Contributor

parmouraly commented Mar 23, 2023

Hey any news on this one?
I'm impacted by the same issue, api/plan returns 500 and I can see the status update failure in the logs

This only throws 500 when policy checks are enabled

@endriu0 I don't think policy checks affect this outcome at the latest version of Atlantis. I still get the same error.

@nitrocode nitrocode removed the Stale label Mar 23, 2023
@nitrocode
Copy link
Member

@parmouraly no news. Feel free to propose a pr if you know of a fix and the maintainers would be happy to review 😄

@github-actions
Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

@github-actions github-actions bot added the Stale label Apr 24, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting-on-response Waiting for a response from the user
Projects
None yet
Development

No branches or pull requests

4 participants