Skip to content

Commit

Permalink
Simplify deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
joegoldman2 committed Jun 6, 2024
1 parent 09d1785 commit 5442c3f
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/OpenTelemetry.Resources.Container/ContainerDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private static string RemovePrefixAndSuffixIfNeeded(string input, int startIndex

using var httpClientHandler = ServerCertificateValidationHandler.Create(K8sCertificatePath, ContainerResourceEventSource.Log);
var response = ResourceDetectorUtils.SendOutRequest(url, "GET", new KeyValuePair<string, string>("Authorization", credentials), httpClientHandler).GetAwaiter().GetResult();
var pod = DeserializeK8sResponse(response);
var pod = ResourceDetectorUtils.DeserializeFromString(response, SourceGenerationContext.Default.K8sPod);
if (pod?.Status?.ContainerStatuses == null)
{
return null;
Expand All @@ -221,14 +221,5 @@ private static string RemovePrefixAndSuffixIfNeeded(string input, int startIndex
}

return null;

static K8sPod? DeserializeK8sResponse(string response)
{
#if NET6_0_OR_GREATER
return ResourceDetectorUtils.DeserializeFromString(response, SourceGenerationContext.Default.K8sPod);
#else
return ResourceDetectorUtils.DeserializeFromString<K8sPod>(response);
#endif
}
}
}

0 comments on commit 5442c3f

Please sign in to comment.