-
Notifications
You must be signed in to change notification settings - Fork 110
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
RSDK-8819: Finish FTDC #4579
base: main
Are you sure you want to change the base?
RSDK-8819: Finish FTDC #4579
Conversation
// `ftdcDirectory`. | ||
func New(ftdcDirectory string, logger logging.Logger) *FTDC { | ||
ret := newFTDC(logger) | ||
ret.maxFileSizeBytes = 1_000_000 |
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.
Made the settings a more formal division. One either passes in a directory and all these variables about managing files are initialized. Or one passes in a writer and none of those variables matter.
ftdc/ftdc.go
Outdated
@@ -536,7 +553,7 @@ func (ftdc *FTDC) checkAndDeleteOldFiles() error { | |||
// deletion testing. Filename generation uses padding such that we can rely on there before 2/4 | |||
// digits for every numeric value. | |||
// | |||
//nolint | |||
// nolint |
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 joys me that our linter lints our linter
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.
Or maybe this was gofmt. The linter complained and it's now back to its unindented state.
ftdc.ftdcDir = ftdcFileDir | ||
// We must not use `NewWithWriter`. Forcing a writer for FTDC data is not compatible with FTDC | ||
// file rotation. | ||
ftdc := New(ftdcFileDir, logger.Sublogger("ftdc")) |
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.
The "refactor" of New
vs NewWithWriter
resulted in changing the order here. First create the directory, then pass it to the constructor.
robot/impl/local_robot.go
Outdated
@@ -416,7 +416,8 @@ func newWithResources( | |||
|
|||
var ftdcWorker *ftdc.FTDC | |||
if rOpts.enableFTDC { | |||
ftdcWorker = ftdc.New(logger.Sublogger("ftdc")) | |||
// CloudID is also known as the robot part id. | |||
ftdcWorker = ftdc.New(ftdc.DefaultDirectory(config.ViamDotDir, cfg.Cloud.ID), logger.Sublogger("ftdc")) |
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.
Technically has a bug -- cfg.Cloud.ID is nil for local configs. Fixed in last commit.
ftdc/cmd/parser.go
Outdated
@@ -36,6 +39,31 @@ type gnuplotWriter struct { | |||
options graphOptions | |||
} | |||
|
|||
type KVPair[K, V any] struct { |
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 expect you'll enjoy this @benjirewis
ftdc/cmd/parser.go
Outdated
nolintPrintln("Expected an FTDC filename. E.g: go run parser.go <path-to>/viam-server.ftdc") | ||
return | ||
} | ||
|
||
data, err := ftdc.Parse(ftdcFile) | ||
logger := logging.NewDebugLogger("parser") | ||
logger.SetLevel(logging.WARN) |
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.
Replaced with a simple NewLogger
and removed the SetLevel
-- using the INFO default.
@@ -416,8 +416,12 @@ func newWithResources( | |||
|
|||
var ftdcWorker *ftdc.FTDC | |||
if rOpts.enableFTDC { | |||
partID := "local-config" | |||
if cfg.Cloud != nil { |
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.
bug fix
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 bug was this? Just looks like starting FTDC within a ~/.viam/[part-id|"local-config"]
as a new feature.
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.
Oh nvm I see your other comment.
@@ -48,7 +48,7 @@ type Arguments struct { | |||
OutputTelemetry bool `flag:"output-telemetry,usage=print out telemetry data (metrics and spans)"` | |||
DisableMulticastDNS bool `flag:"disable-mdns,usage=disable server discovery through multicast DNS"` | |||
DumpResourcesPath string `flag:"dump-resources,usage=dump all resource registrations as json to the provided file path"` | |||
EnableFTDC bool `flag:"ftdc,usage=enable fulltime data capture for diagnostics [beta feature]"` | |||
EnableFTDC bool `flag:"ftdc,default=true,usage=enable fulltime data capture for diagnostics"` |
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.
Stole from WebRTC
above on line 45. Hand tested that -ftdc=false
turns this off.
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.
Nice! Some questions.
Val V | ||
} | ||
|
||
func sorted[K cmp.Ordered, V any](mp map[K]V) []kvPair[K, V] { |
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.
Hah love it. Normally I've seen
- Build a slice of the keys
sort.Strings
that slice- Iterate through sorted slice to access map in key order
But this definitely also works.
nolintPrintln("Expected an FTDC filename. E.g: go run parser.go <path-to>/viam-server.ftdc") | ||
return | ||
} | ||
|
||
data, err := ftdc.Parse(ftdcFile) | ||
logger := logging.NewLogger("parser") | ||
data, err := ftdc.ParseWithLogger(ftdcFile, logger) |
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.
Does the parser main
program here get a lot of info-level-and-above logs 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.
IIRC, there are no info logs. Just debug for item by item details and warn/error for problems.
// "other" users. | ||
// | ||
//nolint:gosec | ||
if err = os.MkdirAll(ftdc.ftdcDir, 0o755); err != nil { |
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.
Won't this recreate the FTDC directory on every attempt to create a single new FTDC file?
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.
MkdirAll has the same behavior as mkdir -p
. Where it's a no-op + no error if the directory already exists.
FWIW, the case you're describing is exercised in a test.
@@ -416,8 +416,12 @@ func newWithResources( | |||
|
|||
var ftdcWorker *ftdc.FTDC | |||
if rOpts.enableFTDC { | |||
partID := "local-config" | |||
if cfg.Cloud != nil { |
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 bug was this? Just looks like starting FTDC within a ~/.viam/[part-id|"local-config"]
as a new feature.
@@ -188,6 +188,8 @@ type Service interface { | |||
|
|||
// Returns the unix socket path the module server listens on. | |||
ModuleAddress() string | |||
|
|||
Stats() any |
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.
Surprised linter does not care about lack of comment here.
No description provided.