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

RSDK-8819: Finish FTDC #4579

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

dgottlieb
Copy link
Member

No description provided.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Nov 21, 2024
// `ftdcDirectory`.
func New(ftdcDirectory string, logger logging.Logger) *FTDC {
ret := newFTDC(logger)
ret.maxFileSizeBytes = 1_000_000
Copy link
Member Author

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
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 joys me that our linter lints our linter

Copy link
Member Author

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"))
Copy link
Member Author

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.

@@ -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"))
Copy link
Member Author

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.

@@ -36,6 +39,31 @@ type gnuplotWriter struct {
options graphOptions
}

type KVPair[K, V any] struct {
Copy link
Member Author

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

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)
Copy link
Member Author

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 {
Copy link
Member Author

Choose a reason for hiding this comment

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

bug fix

Copy link
Member

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.

Copy link
Member

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"`
Copy link
Member Author

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.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 21, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 21, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 21, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 21, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 22, 2024
Copy link
Member

@benjirewis benjirewis left a 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] {
Copy link
Member

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

  1. Build a slice of the keys
  2. sort.Strings that slice
  3. 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)
Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Member

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants