-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add profile. #53
Add profile. #53
Conversation
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.
Looks amazing! 💫 Just some suggestions.
go.mod
Outdated
@@ -7,6 +7,7 @@ require ( | |||
github.com/antchfx/xmlquery v1.3.4 // indirect | |||
github.com/efficientgo/tools/core v0.0.0-20210609125236-d73259166f20 | |||
github.com/efficientgo/tools/extkingpin v0.0.0-20210609125236-d73259166f20 | |||
github.com/felixge/fgprof v0.9.1 // indirect |
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.
Will need to run go mod tidy
as linter fails here. 🙂
main.go
Outdated
if err := os.MkdirAll(filepath.Join(dir, "now"), os.ModePerm); err != nil { | ||
return nil, err | ||
} | ||
f, err := os.OpenFile(filepath.Join(dir, "now", "fgprof.pprof"), os.O_TRUNC|os.O_WRONLY, os.ModePerm) |
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.
f, err := os.OpenFile(filepath.Join(dir, "now", "fgprof.pprof"), os.O_TRUNC|os.O_WRONLY, os.ModePerm) | |
f, err := os.OpenFile(filepath.Join(dir, "now", "fgprof.pprof"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.ModePerm) |
This would create a new file if none exists, which is why there was error before. 🙂
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.
https://share.polarsignals.com/a3b7db6/ Works with Thanos! 🙂
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
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 suggestions only. Thanks for helping here!
main.go
Outdated
@@ -34,6 +42,10 @@ const ( | |||
logFormatCLILog = "clilog" | |||
) | |||
|
|||
type mdoxMetrics 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.
do we need extra 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 was kind of keeping the struct there since I was facing issues using just reg
variable(metrics not registering due to how CLI operates). Will try out something else and see if I can remove.
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've kept it for the Print()
function now. 🙂
main.go
Outdated
@@ -66,14 +78,28 @@ func main() { | |||
Default("info").Enum("error", "warn", "info", "debug") | |||
logFormat := app.Flag("log.format", "Log format to use."). | |||
Default(logFormatCLILog).Enum(logFormatLogfmt, logFormatJson, logFormatCLILog) | |||
// Profiling and metrics. | |||
profilesPath := app.Flag("debug.profiles", "Path to which CPU and heap profiles are saved").Hidden().String() | |||
metrics := app.Flag("metrics", "Enable metrics and view them at https://localhost:9091/metrics").Hidden().Bool() |
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.
Why not printing at the end? It's changing behaviour if we suddenly need to block the whole CLI process 🤔
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.
Someday we could talk about things like this like https://groups.google.com/g/prometheus-developers/c/FPe0LsTfo2E
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.
Right I think we have to print it
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.
Done!
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 about something simple: Always put that to the file,?
main.go
Outdated
} | ||
|
||
func snapshotProfiles(dir string) (func() error, error) { | ||
// TODO: now -> date |
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.
?
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.
Missed this, will add it in. 🙂
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.
Done!
@@ -286,6 +360,9 @@ func (v *validator) visit(filepath string, dest string, lineNumbers string) { | |||
v.destFutures[k] = &futureResult{cases: 1, resultFn: func() error { return nil }} | |||
matches := remoteLinkPrefixRe.FindAllStringIndex(dest, 1) | |||
if matches == nil { | |||
if v.l != 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 about doing it always and just never register/print metrics? (it will be much less distracting)
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.
So no --metrics
flag and it would always be enabled then?
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.
Now it does this always but doesn't register if flag not provided! 🙂
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
main.go
Outdated
enc := expfmt.NewEncoder(os.Stdout, expfmt.FmtProtoText) | ||
|
||
for _, mf := range mfs { | ||
if err := enc.Encode(mf); 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.
We might want to make sure time is encoded too. By default there is no time encoded but in order to walk through those files at some point and load into block, we want timestamps
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.
Yes, I've thought of a few ways of adding timestamps! The server is removed and metrics are written to a file now with timestamps but all timestamps are same as it's only called once. Will try to implement something better!
main.go
Outdated
@@ -66,14 +78,28 @@ func main() { | |||
Default("info").Enum("error", "warn", "info", "debug") | |||
logFormat := app.Flag("log.format", "Log format to use."). | |||
Default(logFormatCLILog).Enum(logFormatLogfmt, logFormatJson, logFormatCLILog) | |||
// Profiling and metrics. | |||
profilesPath := app.Flag("debug.profiles", "Path to which CPU and heap profiles are saved").Hidden().String() | |||
metrics := app.Flag("metrics", "Enable metrics and view them at https://localhost:9091/metrics").Hidden().Bool() |
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 about something simple: Always put that to the file,?
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
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.
LGTM, just minor nits! 💪🏽
pkg/mdformatter/mdformatter.go
Outdated
@@ -257,6 +281,9 @@ func format(ctx context.Context, logger log.Logger, files []string, diffs *Diffs | |||
spin.Message(fn + "...") | |||
} | |||
errs.Add(func() error { | |||
start_time := time.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.
start_time := time.Now() | |
startTime := time.Now() |
pkg/mdformatter/mdformatter.go
Outdated
@@ -288,6 +315,9 @@ func format(ctx context.Context, logger log.Logger, files []string, diffs *Diffs | |||
if err != nil { | |||
return errors.Wrapf(err, "write %v", fn) | |||
} | |||
time_taken := time.Since(start_time) |
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.
ditto
pkg/mdformatter/mdformatter.go
Outdated
} | ||
|
||
// IsFormatted tries to formats given markdown files and return Diff if files are not formatted. | ||
// If diff is empty it means all files are formatted. | ||
func IsFormatted(ctx context.Context, logger log.Logger, files []string, opts ...Option) (diffs Diffs, err error) { | ||
func IsFormatted(ctx context.Context, logger log.Logger, files []string, reg *prometheus.Registry, opts ...Option) (diffs Diffs, err error) { |
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.
Let's use option - metrics are only used rarely potentially (not by default)
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
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.
Let's go! Amazing, work and good example for everyone else. Let's write about it / blog / talk 🤩
main.go
Outdated
@@ -66,14 +79,33 @@ func main() { | |||
Default("info").Enum("error", "warn", "info", "debug") | |||
logFormat := app.Flag("log.format", "Log format to use."). | |||
Default(logFormatCLILog).Enum(logFormatLogfmt, logFormatJson, logFormatCLILog) | |||
// Profiling and metrics. | |||
profilesPath := app.Flag("debug.profiles", "Path to which CPU and heap profiles are saved").Hidden().String() |
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.
profilesPath := app.Flag("debug.profiles", "Path to which CPU and heap profiles are saved").Hidden().String() | |
profilesPath := app.Flag("profiles.path", "Path to directory where CPU and heap profiles will be saved; If empty, no profiling will be enabled. ").ExistingDir() |
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.
Done!
main.go
Outdated
@@ -66,14 +79,33 @@ func main() { | |||
Default("info").Enum("error", "warn", "info", "debug") | |||
logFormat := app.Flag("log.format", "Log format to use."). | |||
Default(logFormatCLILog).Enum(logFormatLogfmt, logFormatJson, logFormatCLILog) | |||
// Profiling and metrics. | |||
profilesPath := app.Flag("debug.profiles", "Path to which CPU and heap profiles are saved").Hidden().String() | |||
metrics := app.Flag("metrics", "Path to which metrics are saved in OpenMetrics format").Hidden().String() |
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.
Ditto for above changes (:
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.
Done!
main.go
Outdated
}, nil | ||
} | ||
|
||
func (m *mdoxMetrics) Print() error { |
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.
Are we printing here? (::
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 don't think you need struct.. just Dump(r prometheus.Registry, dir string) error
would be more cleaner, WDYT?
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.
Done!
|
||
for _, mf := range mfs { | ||
for _, metric := range mf.Metric { | ||
unixTime := now.Unix() |
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.
Can we cache now, so we have consistent timestamp across all series?
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 think we do this already! now
is defined when constructing dir name and is used across all metrics. So it's the same across all series.
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.
all good!
return err | ||
} | ||
} | ||
if _, err = expfmt.FinalizeOpenMetrics(f); 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.
For future: Let's document how one can use those and import to Prometheus 🤗
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.
Sure!
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
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! Let's go 💪🏽
Signed-off-by: Bartlomiej Plotka bwplotka@gmail.com