Skip to content

Commit fb0d36c

Browse files
Merge pull request #85 from stackify/bug/RT-2393
RT-2393 StackifyLib overcalling AWS check
2 parents 03c196e + 30d61ba commit fb0d36c

File tree

4 files changed

+16
-47
lines changed

4 files changed

+16
-47
lines changed

Src/StackifyLib/Internal/Logs/LogClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private Models.LogMsgGroup CreateDefaultMsgGroup()
250250
}
251251
}
252252

253-
var env = EnvironmentDetail.Get(false);
253+
var env = EnvironmentDetail.Get();
254254

255255
//We use whatever the identity stuff says, otherwise we use the azure instance name and fall back to the machine name
256256
if (string.IsNullOrEmpty(group.ServerName))

Src/StackifyLib/Models/EnvironmentDetail.cs

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ public class EnvironmentDetail
1919
{
2020
private static EnvironmentDetail _CachedCopy = null;
2121

22-
public static EnvironmentDetail Get(bool refresh)
22+
public static EnvironmentDetail Get()
2323
{
24-
if (refresh || _CachedCopy == null)
25-
{
26-
_CachedCopy = new EnvironmentDetail(true);
27-
}
28-
29-
return _CachedCopy;
24+
return _CachedCopy ?? (_CachedCopy = new EnvironmentDetail());
3025
}
31-
26+
#if NETSTANDARD
27+
private static System.Net.Http.HttpClient Client => new System.Net.Http.HttpClient();
28+
#endif
3229
private static bool registryAccessFailure = false;
3330

3431
/// <summary>
@@ -209,43 +206,17 @@ public static async Task<string> GetEC2InstanceId()
209206
{
210207
string r = null;
211208

212-
// SF-6804: Frequent Calls to GetEC2InstanceId
213-
bool skipEc2InstanceIdUpdate = false;
214-
215-
if (Config.Ec2InstanceMetadataUpdateThresholdMinutes > 0)
216-
{
217-
var threshold = TimeSpan.FromMinutes(Config.Ec2InstanceMetadataUpdateThresholdMinutes);
218-
lock (ec2InstanceLock)
219-
{
220-
skipEc2InstanceIdUpdate = ec2InstanceIdLastUpdate != null && ec2InstanceIdLastUpdate < DateTimeOffset.UtcNow.Subtract(threshold);
221-
r = string.IsNullOrWhiteSpace(ec2InstanceId) ? null : ec2InstanceId;
222-
}
223-
}
224-
else
225-
{
226-
skipEc2InstanceIdUpdate = true;
227-
}
228-
229-
if (skipEc2InstanceIdUpdate)
230-
{
231-
return r;
232-
}
233-
234209
try
235210
{
211+
Client.Timeout = TimeSpan.FromSeconds(5);
212+
var content = await Client.GetAsync(EC2InstanceIdUrl);
236213

237-
using (var client = new System.Net.Http.HttpClient())
238-
{
239-
client.Timeout = TimeSpan.FromSeconds(5);
240-
var content = await client.GetAsync(EC2InstanceIdUrl);
241-
242-
int statusCode = (int)content.StatusCode;
214+
int statusCode = (int)content.StatusCode;
243215

244-
if (statusCode >= 200 && statusCode < 300)
245-
{
246-
string id = await content.Content.ReadAsStringAsync();
247-
r = string.IsNullOrWhiteSpace(id) ? null : id;
248-
}
216+
if (statusCode >= 200 && statusCode < 300)
217+
{
218+
string id = await content.Content.ReadAsStringAsync();
219+
r = string.IsNullOrWhiteSpace(id) ? null : id;
249220
}
250221

251222
}
@@ -317,10 +288,8 @@ private void IsWindowService()
317288
#endif
318289
}
319290

320-
public EnvironmentDetail(bool loadDetails)
291+
public EnvironmentDetail()
321292
{
322-
if (!loadDetails)
323-
return;
324293

325294
bool isWebRequest = false;
326295
#if NETFULL

Src/StackifyLib/StackifyError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private void Init()
114114
TimeSpan ts = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0));
115115
OccurredEpochMillis = (long)ts.TotalMilliseconds;
116116

117-
EnvironmentDetail = EnvironmentDetail.Get(false);
117+
EnvironmentDetail = EnvironmentDetail.Get();
118118
ServerVariables = new Dictionary<string, string>();
119119

120120
#if NETFULL

Src/StackifyLib/Utils/HttpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public bool IdentifyApp()
301301
return false;
302302
}
303303
StackifyAPILogger.Log("Calling to Identify App");
304-
EnvironmentDetail env = EnvironmentDetail.Get(true);
304+
EnvironmentDetail env = EnvironmentDetail.Get();
305305
string jsonData = JsonConvert.SerializeObject(env, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
306306

307307
var response =

0 commit comments

Comments
 (0)