This commit is contained in:
Charles Torre 2022-05-24 18:25:17 -07:00
Родитель 5667915b4f
Коммит 2b5eb1691a
6 изменённых файлов: 43 добавлений и 47 удалений

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>

Просмотреть файл

@ -22,7 +22,7 @@
</contentFiles>
<dependencies>
<dependency id="Microsoft.Logic.Guan" version="1.0.4" />
<dependency id="Microsoft.ServiceFabric.Services" version="5.0.516" />
<dependency id="Microsoft.ServiceFabric.Services" version="6.0.1017" />
</dependencies>
<projectUrl>https://github.com/microsoft/service-fabric-healer</projectUrl>
<tags>azure servicefabric fabrichealer fabricobserver auto-mitigation logic-programming guan</tags>

Просмотреть файл

@ -3,8 +3,11 @@
<ProjectGuid>{9A19103F-16F7-4668-BE54-9A1E7A4F7556}</ProjectGuid>
<RootNamespace>FabricHealer</RootNamespace>
<AssemblyName>FabricHealer</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
<ServerGarbageCollection>False</ServerGarbageCollection>
<TargetLatestRuntimePatch>False</TargetLatestRuntimePatch>
<OutputType>Exe</OutputType>
<!-- ***NOTE***:
If deploying to SF cluster directly from Visual Studio, you must use single target RID.
@ -15,7 +18,6 @@
<Version>1.1.0</Version>
<FileVersion>1.1.0</FileVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsServiceFabricServiceProject>true</IsServiceFabricServiceProject>
<StartupObject>FabricHealer.Program</StartupObject>
<SignAssembly>false</SignAssembly>
<DelaySign>false</DelaySign>
@ -24,16 +26,16 @@
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.17.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.20.0" />
<PackageReference Include="Microsoft.Logic.Guan" Version="1.0.4" />
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="5.0.516" />
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="6.0.1017" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NLog" Version="4.7.9" />
<PackageReference Include="Octokit" Version="0.50.0" />
<PackageReference Include="NLog" Version="5.0.0" />
<PackageReference Include="Octokit" Version="0.51.0" />
<PackageReference Include="System.Configuration.Abstractions" Version="2.0.2.45" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TelemetryLib\TelemetryLib.csproj" />

Просмотреть файл

@ -7,6 +7,7 @@ using Microsoft.Win32;
namespace FabricHealer.Utilities
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "This is only ever called when running on Windows..")]
public class WindowsServiceFabricConfiguration : ServiceFabricConfiguration
{
private const string ServiceFabricWindowsRegistryPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Service Fabric";
@ -15,14 +16,8 @@ namespace FabricHealer.Utilities
public override string FabricRoot => GetString(nameof(FabricRoot));
public override string GetString(string name)
{
return (string)Registry.GetValue(ServiceFabricWindowsRegistryPath, name, null);
}
public override string GetString(string name) => (string)Registry.GetValue(ServiceFabricWindowsRegistryPath, name, null);
public override int GetInt32(string name)
{
return (int)Registry.GetValue(ServiceFabricWindowsRegistryPath, name, 0);
}
public override int GetInt32(string name) => (int)Registry.GetValue(ServiceFabricWindowsRegistryPath, name, 0);
}
}

Просмотреть файл

@ -7,6 +7,8 @@ using System;
using System.Collections.Generic;
using System.Fabric.Health;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
@ -14,6 +16,7 @@ using System.Threading;
using System.Threading.Tasks;
using FabricHealer.Interfaces;
using Newtonsoft.Json;
using Octokit;
namespace FabricHealer.Utilities.Telemetry
{
@ -193,17 +196,26 @@ namespace FabricHealer.Utilities.Telemetry
return;
}
if (token.IsCancellationRequested)
{
return;
}
var requestUri = new Uri($"https://{WorkspaceId}.ods.opinsights.azure.com/api/logs?api-version={ApiVersion}");
string date = DateTime.UtcNow.ToString("r");
string signature = GetSignature("POST", payload.Length, "application/json", date, "/api/logs");
var request = (HttpWebRequest)WebRequest.Create(requestUri);
request.ContentType = "application/json";
request.Method = "POST";
request.Headers["Log-Type"] = LogType;
request.Headers["x-ms-date"] = date;
request.Headers["Authorization"] = signature;
byte[] content = Encoding.UTF8.GetBytes(payload);
var httpClient = new HttpClient();
var message = new HttpRequestMessage
{
Content = new ByteArrayContent(content),
Method = HttpMethod.Post,
RequestUri = requestUri,
};
httpClient.DefaultRequestHeaders.Add("ContentType", "application/json");
httpClient.DefaultRequestHeaders.Add("Log-Type", LogType);
httpClient.DefaultRequestHeaders.Add("x-ms-date", date);
httpClient.DefaultRequestHeaders.Add("Authorization", signature);
if (token.IsCancellationRequested)
{
@ -212,24 +224,9 @@ namespace FabricHealer.Utilities.Telemetry
try
{
using (var requestStreamAsync = await request.GetRequestStreamAsync())
{
if (token.IsCancellationRequested)
{
return;
}
using HttpResponseMessage response = await httpClient.SendAsync(message, token);
await requestStreamAsync.WriteAsync(content, 0, content.Length);
}
using var responseAsync = await request.GetResponseAsync() as HttpWebResponse;
if (token.IsCancellationRequested)
{
return;
}
if (responseAsync.StatusCode == HttpStatusCode.OK ||responseAsync.StatusCode == HttpStatusCode.Accepted)
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted)
{
retries = 0;
return;
@ -237,7 +234,7 @@ namespace FabricHealer.Utilities.Telemetry
logger.LogWarning(
$"Unexpected response from server in LogAnalyticsTelemetry.SendTelemetryAsync:{Environment.NewLine}" +
$"{responseAsync.StatusCode}: {responseAsync.StatusDescription}");
$"{response.StatusCode}: {response.ReasonPhrase}");
}
catch (Exception e)
{
@ -253,7 +250,7 @@ namespace FabricHealer.Utilities.Telemetry
}
retries++;
await Task.Delay(1000);
await Task.Delay(1000, token);
await SendTelemetryAsync(payload, token);
}
else

Просмотреть файл

@ -16,9 +16,11 @@
<files include="**" buildAction="None" copyToOutput="true" />
</contentFiles>
<dependencies>
<dependency id="Newtonsoft.Json" version="13.0.1" />
<dependency id="Microsoft.ServiceFabric.Services" version="5.0.516" />
<dependency id="Polly" version="7.2.3" />
<group targetFramework=".NETStandard2.0">
<dependency id="Newtonsoft.Json" version="13.0.1" />
<dependency id="Microsoft.ServiceFabric.Services" version="6.0.1017" />
<dependency id="Polly" version="7.2.3" />
</group>
</dependencies>
<projectUrl>https://github.com/microsoft/FabricHealerProxy</projectUrl>
<tags>FabricHealerProxy service-fabric netstandard20 netcore csharp</tags>