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

CLOUDP-70054: mongocli atlas|om|cm performanceAdvisor slowQueryLogs ls #447

Merged
merged 30 commits into from
Sep 21, 2020

Conversation

andreaangiolillo
Copy link
Collaborator

Proposed changes

Jira ticket: CLOUDP-70054

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code

Further comments

Atlas

./bin/mongocli atlas performanceAdvisor slowQueryLogs list --processName cluster0-shard-00-01.ajlj3.mongodb-dev.net:27017
NAMESPACE
sample_airbnb.listingsAndReviews
./bin/mongocli atlas performanceAdvisor slowQueryLogs list --processName cluster0-shard-00-01.ajlj3.mongodb-dev.net:27017 -o json
{
  "slowQueries": [
    {
      "namespace": "sample_airbnb.listingsAndReviews",
      "line": "2020-09-14T14:58:25.229+0000 I  COMMAND  [conn5061] command sample_airbnb.listingsAndReviews appName: \"MongoDB Automation Agent v10.19.0.6571 (git: e6facbc5ce6752d8c8b06a8a388a3a9398ddecc4)\" command: aggregate { aggregate: \"listingsAndReviews\", maxTimeMS: 15000, pipeline: [ { $sample: { size: 277 } } ], cursor: {}, lsid: { id: UUID(\"bd4e862f-bf84-4a29-bd1e-3c430a64bf7c\") }, $clusterTime: { clusterTime: Timestamp(1600095497, 1), signature: { hash: BinData(0, 53984E8709CA3237A0F9A625C16396C4556BC05E), keyId: 6872219484900294658 } }, $db: \"sample_airbnb\", $readPreference: { mode: \"primaryPreferred\" } } planSummary: MULTI_ITERATOR cursorid:5921298278566659851 keysExamined:0 docsExamined:0 numYields:11 nreturned:101 reslen:1953617 locks:{ ReplicationStateTransition: { acquireCount: { w: 13 } }, Global: { acquireCount: { r: 13 } }, Database: { acquireCount: { r: 13 } }, Collection: { acquireCount: { r: 13 } }, Mutex: { acquireCount: { r: 2 } } } storage:{ data: { bytesRead: 41306531, timeReadingMicros: 275540 } } protocol:op_msg 306ms"
    }
  ]
}

OM

./bin/mongocli om performanceAdvisor slowQueryLogs list --hostId 47bddeac69ab40bc578b0e5ae329f980 -P ops
NAMESPACE
admin.system.keys
local.oplog.rs
local.oplog.rs
local.oplog.rs
local.oplog.rs
admin.system.keys
local.oplog.rs
admin.system.keys

@andreaangiolillo andreaangiolillo marked this pull request as ready for review September 15, 2020 11:25
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

Couple of small things but great start

internal/cli/performanceadvisor/slowquerylogs/list.go Outdated Show resolved Hide resolved
internal/cli/performanceadvisor/slowquerylogs/list.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

in general the changes to share share some logic between commands feels like a step backwards
I left a couple of comments on the code smells and how to improve this but I wonder why didn't you follow a similar approach as we've done in other commands where we create a base struct we can embed in all the related commands?

type PerformanceAdvisorOpts struct {
	ProcessName string
	HostID      string
}

// all common functions

// embed 
type ListOpts struct {
	PerformanceAdvisorOpts
}

internal/cli/performanceadvisor/namespaces/list.go Outdated Show resolved Hide resolved
func (opts *ListOpts) host() (string, error) {
if opts.processName == "" {
return opts.hostID, nil
func Host(processName, hostID string) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the method name and the params doesn't tell me anything, the previous style had the approach of relaying on the state to get the correct value but now that you have to pass to values for the method to pick the correct one this feels awkward so I would get rid of this method and do this in each Run() method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will leave this as it was before then so that I don't have to add another param to use opts.store.PerformanceAdvisorSlowQueries(opts.ConfigProjectID(), host, opts.newSlowQueryOptions())

Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

almost there, just a couple of small questions

internal/cli/performance_advisor_opts.go Outdated Show resolved Hide resolved
internal/cli/performance_advisor_opts.go Outdated Show resolved Hide resolved
internal/cli/performanceadvisor/namespaces/list.go Outdated Show resolved Hide resolved
return func() error {
if config.Service() == config.CloudService {
return cmd.MarkFlagRequired(flag.ProcessName)
}
return cmd.MarkFlagRequired(flag.HostID)
}
}

// Host returns the correct processName or the hostId in accordance with the service
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Happy to change the name of this function if you find a better one. I definitely need to read something about naming golang function 😅

Copy link
Collaborator

@gssbzn gssbzn Sep 21, 2020

Choose a reason for hiding this comment

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

This name works, on what to read, Effective Go, is a great resource and here's a section on naming
https://golang.org/doc/effective_go.html#names

Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

two small nits and then we're good to go

Comment on lines 60 to 63
err := opts.validateProcessName()
if err != nil {
return "", err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] let's make this a oneliner

Suggested change
err := opts.validateProcessName()
if err != nil {
return "", err
}
if err := opts.validateProcessName(); err != nil {
return "", err
}

return func() error {
if config.Service() == config.CloudService {
return cmd.MarkFlagRequired(flag.ProcessName)
}
return cmd.MarkFlagRequired(flag.HostID)
}
}

// Host returns the correct processName or the hostId in accordance with the service
Copy link
Collaborator

@gssbzn gssbzn Sep 21, 2020

Choose a reason for hiding this comment

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

This name works, on what to read, Effective Go, is a great resource and here's a section on naming
https://golang.org/doc/effective_go.html#names

opts := new(PerformanceAdvisorOpts)
opts.ProcessName = tc.input
got := opts.validateProcessName()
if !reflect.DeepEqual(tc.want, got) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] this was auto generated but we can use assert which has a better interface for testing

Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for all the fixes

@andreaangiolillo andreaangiolillo merged commit 80b9b64 into master Sep 21, 2020
@andreaangiolillo andreaangiolillo deleted the CLOUDP-70054 branch September 21, 2020 09:49
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.

2 participants