-
Notifications
You must be signed in to change notification settings - Fork 166
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
feat!: use lineage instead of path to link states on overview #179
Conversation
c3a05eb
to
abd2349
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments
main.go
Outdated
@@ -183,6 +183,7 @@ func main() { | |||
http.HandleFunc(util.GetFullPath("api/version"), getVersion) | |||
http.HandleFunc(util.GetFullPath("api/user"), api.GetUser) | |||
http.HandleFunc(util.GetFullPath("api/states"), handleWithDB(api.ListStates, database)) | |||
http.HandleFunc(util.GetFullPath("api/states_lineages"), handleWithDB(api.ListStatesWithLineages, database)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not api/lineages
directly?
In fact, I'd use api/lineages/<lineage>/states
to list states by lineage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint is a little bit particular and it's not aimed to recover all states of a lineage
His purpose is to return a list of all state's paths with the associated lineage in order to fill the nav select since we need lineage to access to state view (/lineage/<lineage>?versionid=<versionid>
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm I think we'll need to talk about that. I'm not sure to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's me who explains very badly ^^
This is a new endpoint which return something like this:
[
{
"path": "terraform_0.12.28.tfstate",
"lineage": "b7d2aa5a-812a-2d1f-e5e6-835215928e00",
"version_id": "1234"
},
{
"path": "terraform_0.13.5.tfstate",
"lineage": "b7d2aa5a-812a-2d1f-e5e6-835215928e00",
"version_id": "5678"
},
...
]
And I'm using that to populate the state quick access (top-right select element on Terraboard).
I put the path as item label and the whole object as value to be able to build the correct URL when a user select a path to view it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. How about /api/lineages/last
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem very relevant to me since this endpoint returns all the states and not just the last ones.
The drop-down menu that it populates is really intended to list all the path existing in the database (without duplicates however) to allow the user to quickly access a specific state file now that we only list the last by lineage on the overview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's only list lineages and ignore potentially renamed paths.
api/api.go
Outdated
@@ -83,17 +98,17 @@ func ListStateStats(w http.ResponseWriter, r *http.Request, d *db.Database) { | |||
// GetState provides information on a State | |||
func GetState(w http.ResponseWriter, r *http.Request, d *db.Database) { | |||
w.Header().Set("Access-Control-Allow-Origin", "*") | |||
st := util.TrimBasePath(r, "api/state/") | |||
lineage := util.TrimBasePath(r, "api/state/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be /api/lineage
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I don't really know, for me this endpoint as well as api/state/compare/
are always used to perform operations on states, lineages are only one parameter used.
But if you find it more suitable to replace state by lineage, no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that's two different ways of organizing the API. Any preference @cryptobioz ?
api/api.go
Outdated
// JSONError(w, "Failed to retrieve default version", err) | ||
// return | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code obsolete now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it took the path in argument.
However I not removed it because I didn't know what this piece of code was for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell, this retrieves the default version when it is not passed as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep it?
I don't really see cases where the GetState api might not have a versionID and, moreover, we no longer pass the path there, so we would have to retrieve it from the lineage only and I don't know if this is possible (in the possibility that there can be different paths for the same lineage)
api/api.go
Outdated
@@ -124,13 +139,13 @@ func GetStateActivity(w http.ResponseWriter, r *http.Request, d *db.Database) { | |||
// StateCompare compares two versions ('from' and 'to') of a State | |||
func StateCompare(w http.ResponseWriter, r *http.Request, d *db.Database) { | |||
w.Header().Set("Access-Control-Allow-Origin", "*") | |||
st := util.TrimBasePath(r, "api/state/compare/") | |||
lineage := util.TrimBasePath(r, "api/state/compare/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in api/lineage/compare
now, or maybe in api/lineage/<lineage>/compare
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I don't really know, for me this endpoint as well as api/state/compare/ are always used to perform operations on states, lineages are only one parameter used.
But if you find it more suitable to replace state by lineage, no problem.
@@ -131,7 +131,7 @@ func (db *Database) stateS3toDB(sf *statefile.File, path string, versionID strin | |||
Version: version, | |||
TFVersion: sf.TerraformVersion.String(), | |||
Serial: int64(sf.Serial), | |||
LineageID: sql.NullInt64{Int64: int64(lineage.ID)}, | |||
LineageID: sql.NullInt64{Int64: int64(lineage.ID), Valid: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this Valid: true
parameter do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql.NullInt64 or sql.NullString are types which handle null values for SQL operations.
Since we can't asign nil to int or string, the Valid
field is here for that.
Valid: true
means that it's not NULL, at false
it's a NULL value
main.go
Outdated
@@ -183,6 +183,7 @@ func main() { | |||
http.HandleFunc(util.GetFullPath("api/version"), getVersion) | |||
http.HandleFunc(util.GetFullPath("api/user"), api.GetUser) | |||
http.HandleFunc(util.GetFullPath("api/states"), handleWithDB(api.ListStates, database)) | |||
http.HandleFunc(util.GetFullPath("api/states_lineages"), handleWithDB(api.ListStatesWithLineages, database)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm I think we'll need to talk about that. I'm not sure to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that adding an exclamation mark to the PR message is enough. I guess you have to do it on a commit message.
If I'm not wrong, since @raphink squash and rebase PRs and not merge them it's the PR title which is used on the rebase commit. But I'm not totally sure. |
e81d8c4
to
9fa3851
Compare
* rename GetStateActivity functions to GetLineageActivity * change /api/state/activity to /api/lineage/activity * restore dynamic lock status on overview * fix missing version_id attribute in states quick access links * remove lineage display from overview
* refactor(api): update some endpoints path to match new lineage system * feat(server): add CORS middleware to abstract headers modifications * refactor(api): update DefaultVersion function to use lineage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
With this PR, the Terraboard overview looks like this:
We can access lineage associated states by clicking on it and we get that view (url: /lineage/b7d2aa5a-812a-2d1f-e5e6-835215928e00):
I also updated search view with lineage column and a associated filter field:
Is that good?