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

Traffic Ops Rewrite: /api/1.2/servers endpoint - with sqlx #1146

Merged
merged 37 commits into from
Sep 15, 2017

Conversation

dewrich
Copy link
Contributor

@dewrich dewrich commented Sep 8, 2017

No description provided.

@asfgit
Copy link
Contributor

asfgit commented Sep 8, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/212/

@rob05c
Copy link
Member

rob05c commented Sep 8, 2017

-1 on including sqlx. It uses illegible Reflection, it's slow, and it introduces a large dependency, which will require fixing every single endpoint when that dependency stops being maintained. For a small gain, of slightly reducing the line length of Scan statements.

The cost far outweighs the benefit.

@asfgit
Copy link
Contributor

asfgit commented Sep 8, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/171/

@dewrich dewrich changed the title Traffic Ops Rewrite: /api/1.2/servers endpoint Traffic Ops Rewrite: /api/1.2/servers endpoint - WIP Sep 11, 2017
@dewrich dewrich assigned dewrich and unassigned dewrich Sep 11, 2017
@dewrich dewrich added the WIP "Work-in-Progress" - do not merge! (use 'draft' pull requests from now on) label Sep 11, 2017
@dewrich dewrich changed the title Traffic Ops Rewrite: /api/1.2/servers endpoint - WIP Traffic Ops Rewrite: /api/1.2/servers endpoint Sep 11, 2017
rob05c
rob05c previously requested changes Sep 11, 2017
"net/url"

"github.com/apache/incubator-trafficcontrol/traffic_monitor_golang/common/log"
. "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/tcstructs"
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't use unqualified imports. I know it's less typing, but Unqualified imports poison the namespace, and make it hard to figure out where things are coming from.

I'd support a shorter package name, e.g. tc for tc.Server.

cdns := []Cdn{}

if err != nil {
panic(err.Error()) // proper error handling instead of panic in your app
Copy link
Member

Choose a reason for hiding this comment

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

Need to return the error, not panic and crash the app.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, this whole function is never executed, because the err is previously checked and returned. Needs removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

must have been a cut/paste issue


const HiddenField = "********"
if err != nil {
panic(err.Error()) // proper error handling instead of panic in your app
Copy link
Member

Choose a reason for hiding this comment

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

Err check is never hit, check and panic need removed.

COALESCE(s.ilo_ip_netmask, '') as ilo_ip_netmask,
COALESCE(s.ilo_password, '') as ilo_password,
COALESCE(s.ilo_username, '') as ilo_username,
COALESCE(s.interface_mtu, 9000) as interface_mtu,
Copy link
Member

Choose a reason for hiding this comment

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

Can you put 9000 in a const somewhere?

@@ -23,14 +23,15 @@ import (
"database/sql"

"github.com/apache/incubator-trafficcontrol/traffic_monitor_golang/common/log"
"github.com/jmoiron/sqlx"
Copy link
Member

Choose a reason for hiding this comment

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

Sqlx should be removed; cost of a large, pervasive, slow dependency outweighs shorter Scan lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Developer's are error prone, and the cost of introducing this dependency is much less costly than the cost of consistent bug introduction

Choose a reason for hiding this comment

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

Scan lines for large structs, 42 fields, could easily be improperly ordered, either when adding a new field or just pulling the object at some point.
Using structs, even anonymous ones declared in the function when you don't need every field, with annotations mean you just need to verify the fields' db annotations are named properly.

Copy link
Member

Choose a reason for hiding this comment

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

I agree it's better. It's just not worth the cost. Not convinced annotations are easier to get right than Scan, though.

Again, when-not-if the library stops being maintained, it'll require fixing every single endpoint. More likely, like Goose, we just won't do it, and we'll live with unmaintained and vulnerable code for years.

The performance is also an issue. It's not a huge slowdown, but it does use slow Reflection. If we keep making small choices against performance, we'll end up where we are with Perl via Death By A Thousand Cuts.

Copy link
Member

@rob05c rob05c Sep 11, 2017

Choose a reason for hiding this comment

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

the cost of consistent bug introduction

easily be improperly ordered

If your fields are improperly ordered, if they're different types, it will immediately fail when run. Even if the types are the same, the values will be wrong, and immediately obvious when testing your code. But even if someone is pushing code without running it, we're requiring tests for every endpoint, right? Those tests should fail.

In short, I don't buy the "more bugs" argument, it would take a long cascade chain of failures, and complete lack of testing or tests, and pushing code without ever running it. You could make the same argument of any code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know how much of a performance hit we're discussing? Can we toss together some quick benchmarks? Performance is pretty important here, but if it's a non-issue it'd be nice to know.

Copy link
Member

@rob05c rob05c Sep 11, 2017

Choose a reason for hiding this comment

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

@alficles Agree. Tangentially, we need to performance test Prepared queries too. Though the maintenance cost is the bigger issue.

@@ -36,6 +36,10 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
return []Route{
{1.2, http.MethodGet, "cdns/{cdn}/configs/monitoring", wrapHeaders(wrapAuth(monitoringHandler(d.DB), d.Insecure, d.TOSecret, rd.PrivLevelStmt, MonitoringPrivLevel))},
{1.2, http.MethodGet, "cdns/{cdn}/configs/monitoring.json", wrapHeaders(wrapAuth(monitoringHandler(d.DB), d.Insecure, d.TOSecret, rd.PrivLevelStmt, MonitoringPrivLevel))},
{1.2, http.MethodGet, "servers", wrapHeaders(wrapAuthWithData(serversHandler(d.DB), d.Insecure, d.TOSecret, rd.PrivLevelStmt, ServersPrivLevel))},
{1.2, http.MethodGet, "servers.json", wrapHeaders(wrapAuthWithData(serversHandler(d.DB), d.Insecure, d.TOSecret, rd.PrivLevelStmt, ServersPrivLevel))},
{1.2, http.MethodGet, "cdns", wrapHeaders(wrapAuthWithData(cdnsHandler(d.DB), d.Insecure, d.TOSecret, rd.PrivLevelStmt, ServersPrivLevel))},
Copy link
Member

Choose a reason for hiding this comment

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

The cdns endpoint should have its own CdnsPrivLevel

return s[i].Name < s[j].Name
}

func sortCdns(p []Cdn) []Cdn {
Copy link
Member

Choose a reason for hiding this comment

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

I'd vote not using this func, and directly calling sort.Sort(SortableCdns(p)), because it's deceptive, it looks like it's a pure function that takes and returns without mutating, but it actually modifies the input. And it's a single line.

for rows.Next() {
var s Cdn
err = rows.StructScan(&s)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: this can be collapsed to if err := rows.StructScan(&s); err != nil {

if err != nil {
//TODO: drichardson - send back an alert if the Query Count is larger than 1
// Test for bad Query Parameters
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

Error context would help debugging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to support the existing TO API which supports the "alerts" json response in the event of an error to report to the API Client


const HiddenField = "********"
if err != nil {
panic(err.Error()) // proper error handling instead of panic in your app
Copy link
Member

Choose a reason for hiding this comment

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

Check is unused, check and panic need removed

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/218/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/220/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/222/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/177/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/223/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/224/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/225/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/226/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/179/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/180/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/181/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/182/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/183/

@asfgit
Copy link
Contributor

asfgit commented Sep 11, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/184/

@asfgit
Copy link
Contributor

asfgit commented Sep 12, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/240/

@dewrich dewrich changed the title Traffic Ops Rewrite: /api/1.2/servers endpoint Traffic Ops Rewrite: /api/1.2/servers endpoint - with sqlx Sep 12, 2017
@asfgit
Copy link
Contributor

asfgit commented Sep 12, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/198/

@asfgit
Copy link
Contributor

asfgit commented Sep 15, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/261/

@asfgit
Copy link
Contributor

asfgit commented Sep 15, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/219/

@asfgit
Copy link
Contributor

asfgit commented Sep 15, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/262/

@asfgit
Copy link
Contributor

asfgit commented Sep 15, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/222/

@asfgit
Copy link
Contributor

asfgit commented Sep 15, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/265/

@dangogh dangogh merged commit 622c0a5 into apache:master Sep 15, 2017
@asfgit
Copy link
Contributor

asfgit commented Sep 15, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR-trafficops-test/223/

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

Successfully merging this pull request may close these issues.

None yet

6 participants