Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
fix(ec2.js): ignore cases of irrelevant response (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranrib authored Apr 5, 2021
1 parent 1596350 commit 100227a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/containers/ec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const eventIterface = require('../event');
let currentEC2Labels = null;

const URL = 'http://169.254.169.254/latest/meta-data/';
const RESPONSE_LEN_THRESHOLD = 100;
const attributeToGet = ['instance-id', 'instance-type', 'local-ipv4', 'public-hostname', 'public-ipv4'];
const EPSAGON_EC2_REQUEST_TIMEOUT = process.env.EPSAGON_EC2_REQUEST_TIMEOUT || 3000;

Expand All @@ -16,7 +17,6 @@ const EPSAGON_EC2_REQUEST_TIMEOUT = process.env.EPSAGON_EC2_REQUEST_TIMEOUT || 3
module.exports.loadEC2Metadata = function loadEC2Metadata() {
if (currentEC2Labels) return Promise.resolve(currentEC2Labels);


const promises = [];
utils.debugLog('Loading EC2 metadata');
attributeToGet.forEach((attribute) => {
Expand All @@ -29,7 +29,8 @@ module.exports.loadEC2Metadata = function loadEC2Metadata() {
cancelToken: source.token,
}).then((response) => {
utils.debugLog(`Received response for ${attribute}`);
if (response.status === 200) {
// In some cases a long, irrelevant HTML response is being returned
if (response.status === 200 && response.data.length < RESPONSE_LEN_THRESHOLD) {
const attributeKey = attribute.replace('-', '_');
const attributeData = response.data;
if (!currentEC2Labels) currentEC2Labels = {};
Expand Down

0 comments on commit 100227a

Please sign in to comment.