Giter Site home page Giter Site logo

Comments (5)

pingleig avatar pingleig commented on August 14, 2024

😅 The logic is

But I think it won't get triggered if the agent is configured as onPrem using -m onPremise I think you are using default, which is auto detection without validation

func initEC2UtilSingleton() (newInstance *ec2Util) {
	newInstance = &ec2Util{Region: "", PrivateIP: ""}
	if context.CurrentContext().Mode() == config.ModeOnPrem {
		return
	}

	if info, e := md.GetMetadata("hostname"); e == nil {
		newInstance.Hostname = info
	} else {
		log.Println("E! getting hostname from EC2 metadata fail: ", e)
	}
}

https://github.com/aws/amazon-cloudwatch-agent/blob/master/packaging/dependencies/amazon-cloudwatch-agent-ctl#L56-L59

        -m: mode
            ec2:                                    indicate this is on ec2 host.
            onPremise:                              indicate this is on onPremise host.
            auto:                                   use ec2 metadata to determine the environment, may not be accurate if ec2 metadata is not available for some reason on EC2.

There are some inconsistencies in our logic, the credential has fall backed to static creds instead of using ec2 instance profile, while the hostname logic took wifi logic page as valid ec2 metadata api response. I think we can add a logic to avoid case like this, though the best approach for your use case should be specifying onPremise

btw: in aws go sdk, the ec2metadata API just copy the content without decoding

from amazon-cloudwatch-agent.

farrantch avatar farrantch commented on August 14, 2024

Ahh, I can definitely move forward with the -m option. Thank you!!

from amazon-cloudwatch-agent.

farrantch avatar farrantch commented on August 14, 2024

So turns out I was already using the -m onPremise option :( So I am going to re-open this ticket.

Perhaps potential solution now is to verify -m onPremise uses os.hostname by default?

from amazon-cloudwatch-agent.

jhnlsn avatar jhnlsn commented on August 14, 2024

I'm assuming that the current logic relies on the request to the metadata endpoint to fail as the decision to use alternative means to lookup the hostname. This should be pretty easy to replicate by spoofing the response from the metadata endpoint ip to verify this behavior.

from amazon-cloudwatch-agent.

SaxyPandaBear avatar SaxyPandaBear commented on August 14, 2024

@farrantch Have you tried using the {local_hostname} placeholder instead of {hostname}?

I didn't know about this until just now as I was looking at the code in ./translator/translate/util/placeholderUtil.go

func getHostName() string {
	if hostname, err := os.Hostname(); err == nil {
		return hostname
	} else {
		log.Println("E! getHostName: ", err)
		return unknownHostname
	}
}

from amazon-cloudwatch-agent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.