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

workaround for Windows path and update README about plugin path #32

Merged
merged 2 commits into from
Dec 21, 2023
Merged

Conversation

kmuto
Copy link
Collaborator

@kmuto kmuto commented Dec 14, 2023

This PR fixes 2 issues.

Update README:
Windows plugin will be installed to C:\Program Files\Mackerel\mackerel-agent\plugins\bin by mkr plugin install.
Linux plugin will be installed to /opt/mackerel-agent/bin.
Users must specify these paths explicitly.

Update handling DefaultConfig.Conffile:
config(from mackerel-agent library).DefaultConfig.Conffile's behaves dfferently in Linux and Windows.
On Linux, it refers to /etc/mackerel-agent.conf, regardless of the location of the plugin.
But on Windows, it mysteriously points to mackerel-agent.conf in the plugin path C:\Program Files\Mackerel\mackerel-agent\plugins\bin\mackerel-agent.conf (yes, this is an invalid location).
The code I put in run() is awkward, but it acts as a workaround.

@kmuto kmuto requested a review from tukaelu December 14, 2023 13:57
Copy link
Collaborator

@tukaelu tukaelu left a comment

Choose a reason for hiding this comment

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

I've made a note and one comment, but I think there were no issues.

@@ -85,7 +87,17 @@ func (opts *mackerelMetricOpts) run() *checkers.Checker {

conf, err := config.LoadConfig(config.DefaultConfig.Conffile)
if err != nil {
return checkers.Unknown(fmt.Sprintf("%v", err))
if runtime.GOOS == "windows" {
newpath := filepath.Join(config.DefaultConfig.Conffile, "../../../mackerel-agent.conf")
Copy link
Collaborator

Choose a reason for hiding this comment

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

[note]
It will probably be something like this:

C:\Program Files\Mackerel\mackerel-agent\plugins\bin\mackerel-agent.conf\..\..\..\mackerel-agent.conf
 ↓
C:\Program Files\Mackerel\mackerel-agent\mackerel-agent.conf

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes! it looks ugly workaround, but it is hard to change mackerel-agent config logic.

newpath := filepath.Join(config.DefaultConfig.Conffile, "../../../mackerel-agent.conf")
conf, err = config.LoadConfig(newpath)
if err != nil {
return checkers.Unknown(fmt.Sprintf("%v", err))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the following kind of code would also be good.

Suggested change
return checkers.Unknown(fmt.Sprintf("%v", err))
return checkers.Unknown(err.Error())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I'll apply it to other projects... 😻

@kmuto kmuto merged commit ee7b7e3 into main Dec 21, 2023
3 checks passed
@kmuto kmuto deleted the winpath branch December 21, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants