-
Notifications
You must be signed in to change notification settings - Fork 38
PMM-3336 Filter by service_id #97
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import ( | |
| "time" | ||
|
|
||
| "github.com/go-sql-driver/mysql" | ||
| "github.com/pkg/errors" | ||
| "gopkg.in/reform.v1" | ||
| ) | ||
|
|
||
|
|
@@ -211,3 +212,40 @@ func (q *QanAgent) DSN(service *MySQLService) string { | |
| // TODO Other parameters? | ||
| return cfg.FormatDSN() | ||
| } | ||
|
|
||
| // AgentFilters represents filters for agents list. | ||
| type AgentFilters struct { | ||
| ServiceID *string | ||
| } | ||
|
|
||
| // AgentsByFilters returns agents providing insights for a given filters. | ||
| func AgentsByFilters(q *reform.Querier, filters AgentFilters) ([]*AgentRow, error) { | ||
BupycHuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var agentIDs []interface{} | ||
| var structs []reform.Struct | ||
| var err error | ||
| if filters.ServiceID != nil { | ||
| agentServices, err := q.SelectAllFrom(AgentServiceView, "WHERE service_id = ? ORDER BY ID", *filters.ServiceID) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no That code branch is not covered by tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but that code can't work: there is no
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests worked and failed. https://travis-ci.org/percona/pmm-managed/jobs/480284133 |
||
| if err != nil { | ||
| return nil, errors.WithStack(err) | ||
| } | ||
| for _, str := range agentServices { | ||
| agentIDs = append(agentIDs, str.(*AgentService).AgentID) | ||
| } | ||
|
|
||
| if len(agentIDs) == 0 { | ||
| return []*AgentRow{}, nil | ||
| } | ||
|
|
||
| structs, err = q.FindAllFrom(AgentRowTable, "id", agentIDs...) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ineffectual assignment to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The real problem there: |
||
| } else { | ||
| structs, err = q.SelectAllFrom(AgentRowTable, "ORDER BY ID") | ||
| } | ||
| if err != nil { | ||
| return nil, errors.WithStack(err) | ||
| } | ||
| agents := make([]*AgentRow, len(structs)) | ||
| for i, str := range structs { | ||
| agents[i] = str.(*AgentRow) | ||
| } | ||
| return agents, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.