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

Rework how we create/save revisions and desired state #318

Closed
romangithub1024 opened this issue May 21, 2018 · 2 comments
Closed

Rework how we create/save revisions and desired state #318

romangithub1024 opened this issue May 21, 2018 · 2 comments
Assignees
Labels

Comments

@romangithub1024
Copy link
Contributor

romangithub1024 commented May 21, 2018

We need to start saving desired state, so that:

  1. We don't have to calculate it every single time
  2. History of all desired states is preserved

We should also consider creating revisions on policy upload.

Need to figure out to do this efficiently in Bolt.

@romangithub1024 romangithub1024 added this to the Version 0.2 - Tasks milestone May 21, 2018
@romangithub1024 romangithub1024 changed the title Save desired state in store for every revision Rework how we create/save revisions and desired state Jun 5, 2018
@romangithub1024 romangithub1024 self-assigned this Jun 6, 2018
@romangithub1024
Copy link
Contributor Author

romangithub1024 commented Jun 6, 2018

Decided that:

  • revisions should be created on policy update
  • desired state needs to be saved for every revision
  • enforcer should just enforce revisions
  • every policy version should have at least one revision tied to it

@romangithub1024
Copy link
Contributor Author

romangithub1024 commented Jun 6, 2018

Also, taking last policy and new revision = last revision + 1 logic is currently incorrect when you have policies without any revisions.

So, e.g. when deleting a dependency this happens:

ERRO[4887] Error while serving request: runtime error: invalid memory address or nil pointer dereference  request="&{DELETE /api/v1/policy HTTP/1.1 1 1 map[Origin:[http://localhost:27866] Content-Type:[application/yaml] Accept:[*/*] Content-Length:[188] Connection:[keep-alive] Authorization:[Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYWRtaW4iLCJleHAiOjE1Mjc5OTMzMzIsImlhdCI6MTUyNTQwMTMzMn0.cnRV8rz775DWk-0u7j5VrpjEpLcLgLcYgrfL3e7gJso] User-Agent:[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36] Referer:[http://localhost:27866/] Accept-Encoding:[gzip, deflate, br] Accept-Language:[en-US,en;q=0.9,ru;q=0.8] Cookie:[_ga=GA1.1.1658362583.1509052047; ATC-Authorization=\"Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjc3JmIjoiYzYzMDY4MzMxMTA4Zjc5NTczZGViNjk2NTkxZDI4NjI1MzU3MTJiMWQzYWMwYTFjNWZmMjhiNDQ3NTZjNTIwMSIsImV4cCI6MTUyNzg4NzMxNCwiaXNBZG1pbiI6dHJ1ZSwidGVhbU5hbWUiOiJtYWluIn0.gof5lF0BwIn7nXP99b9uPtC1lL_zLITG2MzBeIR12Yp5hGz8niDUsYLb5EKD8K-EG6QJhtIWC88l3TE0_NsrJemgV7S1VJQoBNrRWbbotmZ8NrKjcFqy5p74G2yqTMc2IzEIRLLes5GtxwXu4oZ_1g6BMLA-Un77Pe7j2nYfSuu1nkcChBqtHHBWC8_u1hvPhdV1vhLzKK75XJxcqzbt12D6nuXP3nCGd6SrbSZP0tRVbqAR9rCUZi8DRgA4ODKMy3aXY2UscRo3lM60pRuotB8VYNahO270r7sjvgiuvLzIpbJtbvEUDdhHKYTlm4eNRx4b8uyqsM2lLvVBGez-kg\"]] 0xc425720a00 <nil> 188 [] false localhost:27866 map[] map[] <nil> map[] [::1]:52050 /api/v1/policy <nil> <nil> <nil> 0xc424978600}"
DEBU[4887] goroutine 21137 [running]:
runtime/debug.Stack(0xc400000005, 0x2cf6609, 0x1f)
	/usr/local/Cellar/go/1.10.2/libexec/src/runtime/debug/stack.go:24 +0xa7
github.com/Aptomi/aptomi/pkg/api/middleware.(*panicHandler).ServeHTTP.func1(0xc424db6600, 0xc420370960, 0x2e872a0, 0xc422546fc0)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/pkg/api/middleware/recovery.go:30 +0x26b
panic(0x2a45e80, 0x40b5bf0)
	/usr/local/Cellar/go/1.10.2/libexec/src/runtime/panic.go:502 +0x229
github.com/Aptomi/aptomi/pkg/engine.(*Revision).GetGeneration(...)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/pkg/engine/revision.go:74
github.com/Aptomi/aptomi/pkg/api.(*coreAPI).handlePolicyDelete(0xc4200b6ff0, 0x48818e0, 0xc424978510, 0xc424db6600, 0x0, 0x0, 0x0)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/pkg/api/policy.go:310 +0xaad
github.com/Aptomi/aptomi/pkg/api.(*coreAPI).(github.com/Aptomi/aptomi/pkg/api.handlePolicyDelete)-fm(0x48818e0, 0xc424978510, 0xc424db6600, 0x0, 0x0, 0x0)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/pkg/api/api.go:57 +0x66
github.com/Aptomi/aptomi/pkg/api.(*coreAPI).auth.func1(0x48818e0, 0xc424978510, 0xc424db6600, 0x0, 0x0, 0x0)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/pkg/api/auth.go:100 +0x209
github.com/Aptomi/aptomi/vendor/github.com/julienschmidt/httprouter.(*Router).ServeHTTP(0xc42095db90, 0x48818e0, 0xc424978510, 0xc424db6600)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/vendor/github.com/julienschmidt/httprouter/router.go:299 +0x6c1
github.com/Aptomi/aptomi/vendor/github.com/gorilla/handlers.combinedLoggingHandler.ServeHTTP(0x2e6b400, 0xc4200b4008, 0x2e657e0, 0xc42095db90, 0x2e872a0, 0xc422546fc0, 0xc424db6600)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/vendor/github.com/gorilla/handlers/handlers.go:77 +0x123
github.com/Aptomi/aptomi/pkg/api/middleware.(*panicHandler).ServeHTTP(0xc420370960, 0x2e872a0, 0xc422546fc0, 0xc424db6600)
	/Users/ralekseenkov-mini/go/src/github.com/Aptomi/aptomi/pkg/api/middleware/recovery.go:39 +0x99
net/http.serverHandler.ServeHTTP(0xc420d5bc70, 0x2e872a0, 0xc422546fc0, 0xc424db6600)
	/usr/local/Cellar/go/1.10.2/libexec/src/net/http/server.go:2694 +0xbc
net/http.(*conn).serve(0xc420e281e0, 0x2e8a860, 0xc4237ba000)
	/usr/local/Cellar/go/1.10.2/libexec/src/net/http/server.go:1830 +0x651
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.10.2/libexec/src/net/http/server.go:2795 +0x27b

romangithub1024 added a commit that referenced this issue Jun 12, 2018
- store revision on policy update/delete/enforce
- enforces just takes a revision and applies it

Fixes #336 - state enforce creates a new special revision instead of
erasing actual state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants