Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Make hostname a stored variable so it is not retrieved for each metri… #1215

Merged
merged 1 commit into from
Sep 22, 2016
Merged

Make hostname a stored variable so it is not retrieved for each metri… #1215

merged 1 commit into from
Sep 22, 2016

Conversation

jtlisi
Copy link
Contributor

@jtlisi jtlisi commented Sep 19, 2016

Fixes #

Summary of changes:

  • Moved the retrieval of the hostname out the addStandardAndWorkflowTags so that it is not iterated for each metric at every collection.

Testing done:

  • Checked the stack trace of a running agent to ensure calls to os.hostname() are not present

@intelsdi-x/snap-maintainers

…c when tags are applied

"error": err.Error(),
}).Error("Unable to determine hostname")
}
hostnameReader = &hostnameReaderType{hostname: h}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is going to result in only calling once per run of snapd since init will only be run at that time, instead of the intended once per collect call.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the argument against using a simple hostname global set once when snapd starts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just that it was the intention of the PR. Is there a case where the hostname would change more regularly than snapd would be restarting?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that I am aware of.

@jtlisi I would recommend simplifying this down to a global var for hostname. No need for the hostnamer interface IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, I'll change it accordingly

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this means a hostname change requires a restart of snapd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lynxbat I believe so, I can move the hostname out into the metrics.go file and have it run every collection. This would also have to be done at control/plugin_manager.go

Copy link
Contributor

Choose a reason for hiding this comment

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

I think requiring a restart is nasty and we should avoid that one.

Maybe having a TTL that is pretty long (60min)? And have it invalidate and refresh past that. You can just have the accessor function hide this behavior. This way we prevent too much churn (imagine a 10ms interval) but prevent hard locked restart.

We would just need to add comments to the README to call out the 60min refresh. We could postpone exposing that as config until someone asks for it.

}

type hostnamer interface {
Hostname() (name string, err error)
Hostname() (name string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need the hostnamer interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe not, I'll take that out as well.

@jtlisi
Copy link
Contributor Author

jtlisi commented Sep 20, 2016

Hey does anyone know why the legacy build is failing on 1.5. I didn't touch the segment of code that seems to be failing.

Edit. Nevermind seems all the checks have passed

@IRCody
Copy link
Contributor

IRCody commented Sep 21, 2016

@jtlisi: It was failing because there is a flakey tests that hasn't been tracked down yet. Was definitely unrelated to your change. I restarted the test when I saw your comment. Sorry for not commenting at the time.

@IRCody
Copy link
Contributor

IRCody commented Sep 21, 2016

@jtlisi: I think this looks good. Can you rebase it down to 1 commit that starts the message off as "Fixes #1214:...." so that github will close that issue when this is merged?

The only thing I think could be changed is what happens when there is an error with the hostname. In addition to logging it, would it make sense to change the returned hostname to something like "Unknown"?

…ing tags, unknown hosts will be labeled not_found
@IRCody
Copy link
Contributor

IRCody commented Sep 22, 2016

Thanks for updating this @jtlisi.

@jcooklin: Do you have any other concerns before merging?

@jcooklin
Copy link
Collaborator

LGTM

@jcooklin jcooklin merged commit cc27afd into intelsdi-x:master Sep 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants