Conversation
saswatamcode
left a comment
There was a problem hiding this comment.
Looks amazing! 💫 Just some suggestions.
go.mod
Outdated
| 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.
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.
| 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.


https://share.polarsignals.com/a3b7db6/ Works with Thanos! 🙂
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
bwplotka
left a comment
There was a problem hiding this comment.
Nice, some suggestions only. Thanks for helping here!
main.go
Outdated
| logFormatCLILog = "clilog" | ||
| ) | ||
|
|
||
| type mdoxMetrics struct { |
There was a problem hiding this comment.
do we need extra struct?
There was a problem hiding this comment.
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.
I've kept it for the Print() function now. 🙂
main.go
Outdated
| 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.
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.
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.
Right I think we have to print it
There was a problem hiding this comment.
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.
Missed this, will add it in. 🙂
| 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.
What about doing it always and just never register/print metrics? (it will be much less distracting)
There was a problem hiding this comment.
So no --metrics flag and it would always be enabled then?
There was a problem hiding this comment.
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.
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.
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
| 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.
What about something simple: Always put that to the file,?
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
bwplotka
left a comment
There was a problem hiding this comment.
LGTM, just minor nits! 💪🏽
pkg/mdformatter/mdformatter.go
Outdated
| spin.Message(fn + "...") | ||
| } | ||
| errs.Add(func() error { | ||
| start_time := time.Now() |
There was a problem hiding this comment.
| start_time := time.Now() | |
| startTime := time.Now() |
pkg/mdformatter/mdformatter.go
Outdated
| if err != nil { | ||
| return errors.Wrapf(err, "write %v", fn) | ||
| } | ||
| time_taken := time.Since(start_time) |
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.
Let's use option - metrics are only used rarely potentially (not by default)
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
bwplotka
left a comment
There was a problem hiding this comment.
Let's go! Amazing, work and good example for everyone else. Let's write about it / blog / talk 🤩
main.go
Outdated
| 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.
| 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() |
main.go
Outdated
| 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.
Ditto for above changes (:
main.go
Outdated
| }, nil | ||
| } | ||
|
|
||
| func (m *mdoxMetrics) Print() error { |
There was a problem hiding this comment.
Are we printing here? (::
There was a problem hiding this comment.
I don't think you need struct.. just Dump(r prometheus.Registry, dir string) error would be more cleaner, WDYT?
|
|
||
| for _, mf := range mfs { | ||
| for _, metric := range mf.Metric { | ||
| unixTime := now.Unix() |
There was a problem hiding this comment.
Can we cache now, so we have consistent timestamp across all series?
There was a problem hiding this comment.
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.
| return err | ||
| } | ||
| } | ||
| if _, err = expfmt.FinalizeOpenMetrics(f); err != nil { |
There was a problem hiding this comment.
For future: Let's document how one can use those and import to Prometheus 🤗
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
Signed-off-by: Bartlomiej Plotka bwplotka@gmail.com