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

feat!: use lineage instead of path to link states on overview #179

Merged
merged 9 commits into from Jul 29, 2021

Conversation

hbollon
Copy link
Member

@hbollon hbollon commented Jun 30, 2021

With this PR, the Terraboard overview looks like this:
Capture d’écran de 2021-06-30 10-56-14

We can access lineage associated states by clicking on it and we get that view (url: /lineage/b7d2aa5a-812a-2d1f-e5e6-835215928e00):
Capture d’écran de 2021-06-30 10-56-48

I also updated search view with lineage column and a associated filter field:
Capture d’écran de 2021-06-30 15-49-51

Is that good?

@coveralls
Copy link

coveralls commented Jun 30, 2021

Coverage Status

Coverage increased (+0.1%) to 57.556% when pulling f79f764 on hbollon:lineages-states into e44ebce on camptocamp:master.

Copy link
Contributor

@raphink raphink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments

api/api.go Outdated Show resolved Hide resolved
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))
Copy link
Contributor

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

Copy link
Member Author

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>)

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

static/main.html Show resolved Hide resolved
static/search.html Outdated Show resolved Hide resolved
api/api.go Outdated Show resolved Hide resolved
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/")
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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
// }
// }
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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/")
Copy link
Contributor

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?

Copy link
Member Author

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},
Copy link
Contributor

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?

Copy link
Member Author

@hbollon hbollon Jul 15, 2021

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

db/db.go Show resolved Hide resolved
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))
Copy link
Contributor

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.

static/lineage.html Outdated Show resolved Hide resolved
@raphink raphink changed the title feat: use lineage instead of path to link states on overview feat!: use lineage instead of path to link states on overview Jul 15, 2021
Copy link
Contributor

@mcanevet mcanevet left a 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.

@hbollon
Copy link
Member Author

hbollon commented Jul 15, 2021

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.

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@hbollon hbollon requested a review from raphink July 23, 2021 13:55
* 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
Copy link
Contributor

@raphink raphink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants