pyrra icon indicating copy to clipboard operation
pyrra copied to clipboard

Add generate command

Open ArthurSens opened this issue 2 years ago β€’ 6 comments

Fixes #314

Just took a quick try into 314... Fixes the issue but I basically copied code from filesystem.go, so I believe the code can still be improved to reduce duplicated codeπŸ˜…

Opening the PR early just in case you were imagining something different here πŸ™‚

ArthurSens avatar Jul 06 '22 01:07 ArthurSens

Alrighty, refactored a bit to avoid duplicated code. Should be ready for review πŸ™‚

ArthurSens avatar Jul 06 '22 14:07 ArthurSens

It would appear to me that the change in its current form does not parse multiple objects per yaml (like the examples/nginx.yaml has). Is that a bug?

Also, any chance for some forward movement on this PR?

mmazur avatar Aug 01 '22 11:08 mmazur

It would appear to me that the change in its current form does not parse multiple objects per yaml (like the examples/nginx.yaml has). Is that a bug?

Also, any chance for some forward movement on this PR?

ah, interesting, I didn't notice this multiple objects per yaml problem. I'll try to take a look at it this week! Tips on how to solve are appreciated 😝

ArthurSens avatar Aug 01 '22 15:08 ArthurSens

That was definitely a bug in the examples/nginx.yaml :sweat_smile: It's fixed now, thanks to @mmazur :tada:

metalmatze avatar Aug 11 '22 22:08 metalmatze

That was definitely a bug in the examples/nginx.yaml πŸ˜… It's fixed now, thanks to @mmazur πŸŽ‰

Nice! Thanks for solving this one πŸ₯³

I'm stuck at another problem now, but seems like this problem also exists on main.

I'm trying to run those commands, and both fail with the same error:

gitpod /workspace/pyrra (main) $ ./pyrra filesystem --config-files examples/*.yaml
pyrra: error: unexpected argument examples/prometheus-http.yaml
gitpod /workspace/pyrra (main) $ ./pyrra generate --config-files examples/*.yaml
pyrra: error: unexpected argument examples/prometheus-http.yaml

But if I use a direct path to a single file, it works as expected (only permission issues with the output folder):

gitpod /workspace/pyrra (main) $ ./pyrra filesystem --config-files examples/nginx.yaml
level=info ts=2022-08-12T00:17:01.716103492Z caller=main.go:119 msg="using Prometheus" url=http://localhost:9090
level=info ts=2022-08-12T00:17:01.716181202Z caller=filesystem.go:128 msg="watching directory for changes" directory=examples
level=info ts=2022-08-12T00:17:01.716410362Z caller=filesystem.go:245 msg="starting up HTTP API" address=:9444
level=debug ts=2022-08-12T00:17:01.716517122Z caller=filesystem.go:170 msg=reading file=examples/nginx.yaml
level=error ts=2022-08-12T00:17:01.720097441Z caller=filesystem.go:253 msg="failed to run" err="failed to create rule file \"examples/nginx.yaml\": failed to write file \"/etc/prometheus/pyrra/nginx.yaml\": open /etc/prometheus/pyrra/nginx.yaml: permission denied"
gitpod /workspace/pyrra (main) $ ./pyrra generate --config-files examples/nginx.yaml
level=info ts=2022-08-12T00:17:17.616300781Z caller=main.go:119 msg="using Prometheus" url=http://localhost:9090
level=error ts=2022-08-12T00:17:17.618056421Z caller=generate.go:36 msg="generating rule files" err="failed to write file \"/etc/prometheus/pyrra/nginx.yaml\": open /etc/prometheus/pyrra/nginx.yaml: permission denied"

On main the same behavior is happening for the filesystem command πŸ€”. Is that expected?

ArthurSens avatar Aug 12 '22 00:08 ArthurSens

This should work since the code uses filepath.Glob to discover files in a directory. I'll check out this PR locally to take a look.

metalmatze avatar Aug 26 '22 08:08 metalmatze

Sorry for taking so long, but PR rebased! I believe it should be ready for a review πŸ™‚

ArthurSens avatar Jan 11 '23 19:01 ArthurSens