Invalid response from metadata service: incorrect Metadata-Flavor header
See original GitHub issueAfter reviewing as much as I could online to see how I could solve the issue, I wasn’t able to come to a solution, this is an issue apparently with how the JSON file holding the credentials to GCloud.
“Invalid response from metadata service: incorrect Metadata-Flavor header”
That is normally the error that keeps throwing the client when I invoke the alert function of the client.
Environment details
- OS: macOS Mojave
- Node.js version: v10.15.2
- npm version: 6.10.0
@google-cloud/loggingversion: 5.2.1
Steps to reproduce
- Generate a quick Angular project using the CLI
- Make sure to have a JSON file with service account credentials properly downloaded.
- Generate a quick service that looks somehow like it follows, inject it, and call the function that performs the logging.
`import { Logging } from ‘@google-cloud/logging’; @Injectable() export class GCloudLogService { constructor( private readonly logging: Logging, ) {}
async saveLog(logPayload: IServerExceptionLog) {
try {
const metadata = {
resource: { type: 'global' },
};
const entry = this.logging.entry(metadata, logPayload);
const log = this.logging.log(logName);
await log.alert(entry);
return;
} catch (err) {
console.log(`ERR ${err.message}`);
}
} }`
No matter how many versions of the code I try I keep getting the error:
“Invalid response from metadata service: incorrect Metadata-Flavor header.”
I tried setting the project manually,
await this.logging.setProjectId({ projectId, });
but still nothing.
I did make sure that the environment variable GOOGLE_APPLICATION_CREDENTIALS was set up and it is.
Please help, I have expended too many hours trying to figure it out but still nothing.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (6 by maintainers)
Top Related StackOverflow Question
Just wanted to add that I had this happen to me after factory resetting a PC and it turns out it was ATT’s DNS catch-all that was causing issues (paired with the internal auth/metadata module’s expectations around querying the metadata server).
I compared each and every setting that I could think of between a machine where things were working and on one that wasn’t. Everything seemed to match, so I stepped through the code line by line and realized that it was failing in
google-auth-library\build\src\auth\envDetect.jswhere it tried to figure out what type of GCP environment, if any, the code is running in.When it got to the
isComputeEngine()check, it would call thegcpMetadata.isAvailable()method which attempts a network call to the metadata service and tries to fail fast if it’s unavailable. Unfortunately, ATT’s DNS ‘Assist’ that was catching all unknown DNS calls and returning a search result instead of just failing the network request.I changed my DNS entries on that PC over to Google’s DNS (
8.8.8.8and8.8.4.4) and the issue is now resolved for me.I fully agree with you @dustingraham and with what @jtyers mentioned. As a way to validate that idea a bit, I cloned my repo on another machine and the whole thing worked just fine. There is some local configuration that either we are missing or have different that causes this issue.