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

Cosmovisor: be able to silence cosmovisor logs when running commands #15359

Closed
freak12techno opened this issue Mar 10, 2023 · 10 comments · Fixed by #15362
Closed

Cosmovisor: be able to silence cosmovisor logs when running commands #15359

freak12techno opened this issue Mar 10, 2023 · 10 comments · Fixed by #15362
Assignees
Labels
C:Cosmovisor Issues and PR related to Cosmovisor T:feature-request

Comments

@freak12techno
Copy link
Contributor

Summary

I have some tools that are running some cosmovisor subcommands and are expecting a valid JSON in a response, and when I use the binary itself without cosmovisor, it returns a valid json, but with cosmovisor, it adds its own logs, making the result an invalid JSON. Example: querying for version (note the running app line):

$ cosmovisor run version --long --output json
10:47PM INF running app args=["version","--long","--output","json"] module=cosmovisor path=/home/validator/.gaia/cosmovisor/upgrades/v8-rho/bin/gaiad
{"name":"gaia","server_name":"gaiad","version":"v8.0.1","commit":"890ab3aa2e5788537b0d2ebc9bafdc968340e0e5","build_tags":"netgo ledger,","go":"go version go1.18.5 linux/amd64","build_deps":["cosmossdk.io/[email protected]","cosmossdk.io/[email protected]","cosmossdk.io/[email protected]","filippo.io/[email protected]","github.com/99designs/[email protected] =\u003e github.com/cosmos/[email protected]","github.com/ChainSafe/[email protected]","github.com/Workiva/[email protected]","github.com/armon/[email protected]","github.com/beorn7/[email protected]","github.com/bgentry/[email protected]","github.com/btcsuite/[email protected] =\u003e github.com/btcsuite/[email protected]","github.com/btcsuite/btcd/btcec/[email protected]","github.com/cenkalti/backoff/[email protected]","github.com/cespare/xxhash/[email protected]","github.com/coinbase/[email protected]","github.com/confio/ics23/[email protected] =\u003e github.com/confio/ics23/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected] =\u003e github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/ibc-go/[email protected] =\u003e github.com/cosmos/ibc-go/[email protected]","github.com/cosmos/[email protected]","github.com/creachadair/[email protected]","github.com/davecgh/[email protected]","github.com/decred/dcrd/dcrec/secp256k1/[email protected]","github.com/desertbit/[email protected]","github.com/dvsekhvalnov/[email protected]","github.com/felixge/[email protected]","github.com/fsnotify/[email protected]","github.com/go-kit/[email protected]","github.com/go-kit/[email protected]","github.com/go-logfmt/[email protected]","github.com/godbus/[email protected]","github.com/gogo/[email protected]","github.com/gogo/[email protected] =\u003e github.com/regen-network/[email protected]","github.com/golang/[email protected]","github.com/golang/[email protected]","github.com/google/[email protected]","github.com/google/[email protected]","github.com/gorilla/[email protected]","github.com/gorilla/[email protected]","github.com/gorilla/[email protected]","github.com/gravity-devs/[email protected]","github.com/grpc-ecosystem/[email protected]","github.com/grpc-ecosystem/[email protected]","github.com/grpc-ecosystem/grpc-gateway/[email protected]","github.com/gsterjov/[email protected]","github.com/gtank/[email protected]","github.com/gtank/[email protected]","github.com/hashicorp/[email protected]","github.com/hashicorp/[email protected]","github.com/hashicorp/[email protected]","github.com/hdevalence/[email protected]","github.com/improbable-eng/[email protected]","github.com/klauspost/[email protected]","github.com/lib/[email protected]","github.com/libp2p/[email protected]","github.com/magiconair/[email protected]","github.com/mattn/[email protected]","github.com/mattn/[email protected]","github.com/matttproud/[email protected]","github.com/mimoo/[email protected]","github.com/minio/[email protected]","github.com/mitchellh/[email protected]","github.com/mtibben/[email protected]","github.com/pelletier/go-toml/[email protected]","github.com/pkg/[email protected]","github.com/pmezard/[email protected]","github.com/prometheus/[email protected]","github.com/prometheus/[email protected]","github.com/prometheus/[email protected]","github.com/prometheus/[email protected]","github.com/rakyll/[email protected]","github.com/rcrowley/[email protected]","github.com/regen-network/[email protected]","github.com/rs/[email protected]","github.com/rs/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/strangelove-ventures/packet-forward-middleware/[email protected]","github.com/stretchr/[email protected]","github.com/subosito/[email protected]","github.com/syndtr/[email protected]","github.com/tendermint/[email protected]","github.com/tendermint/[email protected] =\u003e github.com/informalsystems/[email protected]","github.com/tendermint/[email protected]","github.com/tidwall/[email protected]","github.com/zondax/[email protected]","github.com/zondax/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","google.golang.org/[email protected]","google.golang.org/[email protected] =\u003e google.golang.org/[email protected]","google.golang.org/[email protected]","gopkg.in/[email protected]","gopkg.in/[email protected]","gopkg.in/[email protected]","nhooyr.io/[email protected]"],"cosmos_sdk_version":"v0.45.14"}
$ gaiad version --long --output json
{"name":"gaia","server_name":"gaiad","version":"v8.0.1","commit":"890ab3aa2e5788537b0d2ebc9bafdc968340e0e5","build_tags":"netgo ledger,","go":"go version go1.18.5 linux/amd64","build_deps":["cosmossdk.io/[email protected]","cosmossdk.io/[email protected]","cosmossdk.io/[email protected]","filippo.io/[email protected]","github.com/99designs/[email protected] =\u003e github.com/cosmos/[email protected]","github.com/ChainSafe/[email protected]","github.com/Workiva/[email protected]","github.com/armon/[email protected]","github.com/beorn7/[email protected]","github.com/bgentry/[email protected]","github.com/btcsuite/[email protected] =\u003e github.com/btcsuite/[email protected]","github.com/btcsuite/btcd/btcec/[email protected]","github.com/cenkalti/backoff/[email protected]","github.com/cespare/xxhash/[email protected]","github.com/coinbase/[email protected]","github.com/confio/ics23/[email protected] =\u003e github.com/confio/ics23/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected] =\u003e github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/[email protected]","github.com/cosmos/ibc-go/[email protected] =\u003e github.com/cosmos/ibc-go/[email protected]","github.com/cosmos/[email protected]","github.com/creachadair/[email protected]","github.com/davecgh/[email protected]","github.com/decred/dcrd/dcrec/secp256k1/[email protected]","github.com/desertbit/[email protected]","github.com/dvsekhvalnov/[email protected]","github.com/felixge/[email protected]","github.com/fsnotify/[email protected]","github.com/go-kit/[email protected]","github.com/go-kit/[email protected]","github.com/go-logfmt/[email protected]","github.com/godbus/[email protected]","github.com/gogo/[email protected]","github.com/gogo/[email protected] =\u003e github.com/regen-network/[email protected]","github.com/golang/[email protected]","github.com/golang/[email protected]","github.com/google/[email protected]","github.com/google/[email protected]","github.com/gorilla/[email protected]","github.com/gorilla/[email protected]","github.com/gorilla/[email protected]","github.com/gravity-devs/[email protected]","github.com/grpc-ecosystem/[email protected]","github.com/grpc-ecosystem/[email protected]","github.com/grpc-ecosystem/grpc-gateway/[email protected]","github.com/gsterjov/[email protected]","github.com/gtank/[email protected]","github.com/gtank/[email protected]","github.com/hashicorp/[email protected]","github.com/hashicorp/[email protected]","github.com/hashicorp/[email protected]","github.com/hdevalence/[email protected]","github.com/improbable-eng/[email protected]","github.com/klauspost/[email protected]","github.com/lib/[email protected]","github.com/libp2p/[email protected]","github.com/magiconair/[email protected]","github.com/mattn/[email protected]","github.com/mattn/[email protected]","github.com/matttproud/[email protected]","github.com/mimoo/[email protected]","github.com/minio/[email protected]","github.com/mitchellh/[email protected]","github.com/mtibben/[email protected]","github.com/pelletier/go-toml/[email protected]","github.com/pkg/[email protected]","github.com/pmezard/[email protected]","github.com/prometheus/[email protected]","github.com/prometheus/[email protected]","github.com/prometheus/[email protected]","github.com/prometheus/[email protected]","github.com/rakyll/[email protected]","github.com/rcrowley/[email protected]","github.com/regen-network/[email protected]","github.com/rs/[email protected]","github.com/rs/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/spf13/[email protected]","github.com/strangelove-ventures/packet-forward-middleware/[email protected]","github.com/stretchr/[email protected]","github.com/subosito/[email protected]","github.com/syndtr/[email protected]","github.com/tendermint/[email protected]","github.com/tendermint/[email protected] =\u003e github.com/informalsystems/[email protected]","github.com/tendermint/[email protected]","github.com/tidwall/[email protected]","github.com/zondax/[email protected]","github.com/zondax/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","golang.org/x/[email protected]","google.golang.org/[email protected]","google.golang.org/[email protected] =\u003e google.golang.org/[email protected]","google.golang.org/[email protected]","gopkg.in/[email protected]","gopkg.in/[email protected]","gopkg.in/[email protected]","nhooyr.io/[email protected]"],"cosmos_sdk_version":"v0.45.14"}

Would be nice to have the way to omit such logs, see below for suggestions.

I am all in for implementing it by myself as I want to get my hands on cosmos-sdk as a contributor, just saying ;) I'd need some guidance for it though.

Problem Definition

Adding the way to silence cosmovisor logs would make it easier for other tools that rely on a plain output to be a valid JSON to use it.
I do not see any disadvantages on being able to set it up.

Proposal

I suggest having an environmental variable (like DAEMON_DISABLE_LOGS) that will silence logs if set to true.

@github-actions github-actions bot added the needs-triage Issue that needs to be triaged label Mar 10, 2023
@julienrbrt
Copy link
Member

julienrbrt commented Mar 11, 2023

This is already the case. Which Cosmovisor version are you using?

You have to run:

$ cosmovisor version --output json

When using the run command, it will always show logs.

@julienrbrt julienrbrt added S:needs more info This bug can't be addressed until more information is provided by the reporter. C:Cosmovisor Issues and PR related to Cosmovisor and removed needs-triage Issue that needs to be triaged labels Mar 11, 2023
@freak12techno
Copy link
Contributor Author

freak12techno commented Mar 11, 2023

@julienrbrt when running your command, it indeed works correctly (though I am running in another issue I've described here #15360 (comment), but this is not the subject of this issue). But this only solves part of the problem, while it allows silencing logs querying for version, it still displays them for every other command, for example:

$ cosmovisor run q staking params --output json
11:52PM INF running app args=["q","staking","params","--output","json"] module=cosmovisor path=/home/validator/.bitsongd/cosmovisor/upgrades/v014/bin/bitsongd
{"unbonding_time":"1814400s","max_validators":100,"max_entries":7,"historical_entries":10000,"bond_denom":"ubtsg"}

and this also results in the response not being a valid JSON (while it is a valid JSON if running this command without Cosmovisor).

I assume checking for every command in cosmovisor run <something> if it has --output json is too expensive and complicated, therefore I guess the env variable solution might be nice. What do you think?

This is already the case. Which Cosmovisor version are you using?

1.3.0, also tested with 1.4.0

@julienrbrt
Copy link
Member

I think your proposal makes sense. Disabling cosmovisor logger altogether could be an option.

@julienrbrt julienrbrt added T:feature-request and removed S:needs more info This bug can't be addressed until more information is provided by the reporter. labels Mar 12, 2023
@julienrbrt julienrbrt self-assigned this Mar 12, 2023
@freak12techno
Copy link
Contributor Author

I may help implementing it, if needed, just need some guidance on how to do it in a better way. @julienrbrt jfyi

@julienrbrt
Copy link
Member

julienrbrt commented Mar 12, 2023

I may help implementing it, if needed, just need some guidance on how to do it in a better way. @julienrbrt jfyi

Sure, if you want to 👍
You need to change the logger created with the NoOp logger when that environment variable is present.

@freak12techno
Copy link
Contributor Author

@julienrbrt okay I am mostly done, I have one issue though. In tools/cosmovisor/process.go#NewLauncher, it casts logger into zerolog.Logger, which would fail if it's not zerolog.Logger (which isn't true if it's noopLogger), and zerolog.Logger and noopLogger are not compatible as they have different methods and signatures. I see the following solutions here:

  • update log/* and update Logger signatures to be the same as the ones in zerolog.Logger (so all of the methods should return Logger, and there should be also methods like Msg, Int, Str etc.), then remove casting to zerolog.Logger and use Logger interface directly there
  • update process.go to check if there's a logger (or if it can be casted into zerolog.Logger) on every place we use it.

What do you think would be better approach, or do you maybe know some better ways to deal with it?

@julienrbrt
Copy link
Member

julienrbrt commented Mar 12, 2023

No, you do not need to modify anything in log/*.
You can indeed choose to type cast everything when Impl() is used or use zerolog no-op logger with logger := log.NewCustomLogger(zerolog.Nop()).
We should not need to have zerolog.Logger type anywhere I think actually, if not yet done, we can change it do log.Logger`.

@freak12techno
Copy link
Contributor Author

@julienrbrt okay submitted this #15362, can you review please?
also pretty sure we also need to update at least docs here https://docs.cosmos.network/main/tooling/cosmovisor#command-line-arguments-and-environment-variables to add this, not sure where should I put it

@julienrbrt
Copy link
Member

@julienrbrt okay submitted this #15362, can you review please?

also pretty sure we also need to update at least docs here https://docs.cosmos.network/main/tooling/cosmovisor#command-line-arguments-and-environment-variables to add this, not sure where should I put it

I'll have a look, thank you!
You can update the README and it will update on the website afterwards.

@freak12techno
Copy link
Contributor Author

You can update the README and it will update on the website afterwards.

Done, thanks for letting me know.

One thing I am not sure are tests, they fail even without my PR, so it's not something I broke within my changes I assume, so I didn't bother fixing them:

--- FAIL: TestInitTestSuite (0.02s)
    --- FAIL: TestInitTestSuite/TestInitializeCosmovisorNegativeValidation (0.00s)
        init_test.go:60: Clearing environment variables.
        --- FAIL: TestInitTestSuite/TestInitializeCosmovisorNegativeValidation/no_args (0.00s)
            testing.go:1319: race detected during execution of test
        init_test.go:74: Restoring environment variables.
        init_test.go:92: done unsetting DAEMON_HOME
        init_test.go:92: done unsetting DAEMON_NAME
        testing.go:1319: race detected during execution of test
    testing.go:1319: race detected during execution of test
cosmovisor version: (devel)
FAIL
FAIL	cosmossdk.io/tools/cosmovisor/cmd/cosmovisor	0.765s
ok  	cosmossdk.io/tools/cosmovisor/errors	(cached)
FAIL
make: *** [test] Error 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Cosmovisor Issues and PR related to Cosmovisor T:feature-request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants