Permalink
Browse files

upgrading app metrics to 2.x (#909)

* first iteration

* fix tags

* bump api version

* removed graphite reporter

* removed graphite reporter project ref
  • Loading branch information...
Yshayy committed Aug 26, 2018
1 parent 44c5de5 commit 30468bacf127176a417ed54b50726dff7649121b
@@ -17,7 +17,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "api-build",
"program": "${workspaceRoot}/services/api/Tweek.ApiService/bin/Debug/netcoreapp2.0/Tweek.ApiService.dll",
"program": "${workspaceRoot}/services/api/Tweek.ApiService/bin/Debug/netcoreapp2.1/Tweek.ApiService.dll",
"args": [],
"cwd": "${workspaceRoot}/services/api/Tweek.ApiService",
"stopAtEntry": false,
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
@@ -42,8 +42,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tweek.Drivers.Context.Redis
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tweek.Addons.ApplicationInsights", "addons\ApplicationInsights\Tweek.Addons.ApplicationInsights\Tweek.Addons.ApplicationInsights.csproj", "{90AD5C6D-668E-4703-BCE9-17AB584881EE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tweek.Addons.AppMetrics.GraphiteReporter", "addons\AppMetrics\Tweek.Addons.AppMetrics.GraphiteReporter\Tweek.Addons.AppMetrics.GraphiteReporter.csproj", "{34154EAB-9A1B-4D59-A967-73DAFD05580D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tweek.Drivers.ContextIntegrationTests", "addons\Context\Tweek.Drivers.ContextIntegrationTests\Tweek.Drivers.ContextIntegrationTests.csproj", "{B5070CC9-BBD8-483E-849F-2950A63C9FFE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tweek.Drivers.Context.Redis.IntegrationTests", "addons\Context\Tweek.Drivers.Context.Redis.IntegrationTests\Tweek.Drivers.Context.Redis.IntegrationTests.csproj", "{03E847A8-5A6E-47A1-B07E-F6148FBC587D}"
@@ -184,18 +182,6 @@ Global
{90AD5C6D-668E-4703-BCE9-17AB584881EE}.Release|x64.Build.0 = Release|Any CPU
{90AD5C6D-668E-4703-BCE9-17AB584881EE}.Release|x86.ActiveCfg = Release|Any CPU
{90AD5C6D-668E-4703-BCE9-17AB584881EE}.Release|x86.Build.0 = Release|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Debug|x64.ActiveCfg = Debug|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Debug|x64.Build.0 = Debug|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Debug|x86.ActiveCfg = Debug|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Debug|x86.Build.0 = Debug|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Release|Any CPU.Build.0 = Release|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Release|x64.ActiveCfg = Release|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Release|x64.Build.0 = Release|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Release|x86.ActiveCfg = Release|Any CPU
{34154EAB-9A1B-4D59-A967-73DAFD05580D}.Release|x86.Build.0 = Release|Any CPU
{B5070CC9-BBD8-483E-849F-2950A63C9FFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5070CC9-BBD8-483E-849F-2950A63C9FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5070CC9-BBD8-483E-849F-2950A63C9FFE}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -310,7 +296,6 @@ Global
{BD1E6B57-18E1-46E9-B16F-B531E88FB9E3} = {2407B11F-BCC6-46BC-85B0-CF64D74A441D}
{70ACAF9B-A91A-46CB-A7EF-F4D2A0736510} = {BD1E6B57-18E1-46E9-B16F-B531E88FB9E3}
{90AD5C6D-668E-4703-BCE9-17AB584881EE} = {2407B11F-BCC6-46BC-85B0-CF64D74A441D}
{34154EAB-9A1B-4D59-A967-73DAFD05580D} = {2407B11F-BCC6-46BC-85B0-CF64D74A441D}
{B5070CC9-BBD8-483E-849F-2950A63C9FFE} = {BD1E6B57-18E1-46E9-B16F-B531E88FB9E3}
{03E847A8-5A6E-47A1-B07E-F6148FBC587D} = {BD1E6B57-18E1-46E9-B16F-B531E88FB9E3}
{6BBFF719-3F6E-4296-8E08-7FE0B99A361E} = {BD1E6B57-18E1-46E9-B16F-B531E88FB9E3}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -7,7 +7,7 @@

namespace Tweek.Drivers.Context.Couchbase
{
public class BucketConnectionHealthCheck : HealthCheck
internal class BucketConnectionHealthCheck : HealthCheck
{
private DateTime _lastSuccessCheck;

@@ -22,7 +22,7 @@ public class BucketConnectionHealthCheck : HealthCheck

private HealthCheckResult _state = HealthCheckResult.Unhealthy();

public BucketConnectionHealthCheck(Func<string, IBucket> getBucket, string bucketNameToCheck, TimeSpan timeout, int retryCount, ILogger logger)
internal BucketConnectionHealthCheck(Func<string, IBucket> getBucket, string bucketNameToCheck, TimeSpan timeout, int retryCount, ILogger logger)
: base("CouchbaseConnection")
{
_getBucket = getBucket;
@@ -32,7 +32,7 @@ public BucketConnectionHealthCheck(Func<string, IBucket> getBucket, string bucke
_logger = logger;
}

protected override async Task<HealthCheckResult> CheckAsync(
protected override async ValueTask<HealthCheckResult> CheckAsync(
CancellationToken cancellationToken = new CancellationToken())
{
if (DateTime.UtcNow - _lastSuccessCheck > TimeSpan.FromSeconds(1))
@@ -50,6 +50,7 @@ public void Configure(IServiceCollection services, IConfiguration configuration)

var contextDriver = new CouchBaseDriver(ClusterHelper.GetBucket, contextBucketName);
services.AddSingleton<IContextDriver>(contextDriver);

services.AddSingleton<HealthCheck>(ctx =>
{
ctx.GetService<StaticCouchbaseDisposer>();
@@ -11,6 +11,7 @@
<NuspecFile>$([System.IO.Path]::Combine($(MSBuildProjectDirectory),$(MSBuildProjectName))).nuspec</NuspecFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="App.Metrics.Health.Abstractions" Version="2.0.0" />
<PackageReference Include="CouchbaseNetClient" Version="2.6.1" />
<PackageReference Include="FSharpUtils.Newtonsoft.JsonValue" Version="0.2.6" />
<PackageReference Include="System.Collections.Immutable" version="1.4.0" />
@@ -11,9 +11,9 @@
<NuspecFile>$([System.IO.Path]::Combine($(MSBuildProjectDirectory),$(MSBuildProjectName))).nuspec</NuspecFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="App.Metrics" Version="1.3.0" />
<PackageReference Include="App.Metrics" Version="2.1.0" />
<PackageReference Include="FSharpUtils.Newtonsoft.JsonValue" Version="0.2.6" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0" />
@@ -10,8 +10,8 @@ public class EnvironmentHealthCheck : HealthCheck
{
public EnvironmentHealthCheck() : base("EnvironmentDetails") { }

protected override Task<HealthCheckResult> CheckAsync(CancellationToken cancellationToken = new CancellationToken()) => Task.FromResult(
HealthCheckResult.Healthy($"Host = {Environment.MachineName}, Version = {AppVersion}"));
protected async override ValueTask<HealthCheckResult> CheckAsync(CancellationToken cancellationToken = new CancellationToken()) =>
HealthCheckResult.Healthy($"Host = {Environment.MachineName}, Version = {AppVersion}");

public static readonly string AppVersion =
Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()
@@ -13,19 +13,18 @@ namespace Tweek.ApiService.Diagnostics
{
public class QueryHealthCheck : HealthCheck
{
private readonly IServiceProvider _serviceProvider;

private readonly ITweek _tweek;
private readonly IContextDriver _contextDriver;
private HealthCheckResult _state = HealthCheckResult.Unhealthy();

public QueryHealthCheck(IServiceProvider serviceProvider) : base("QueryHealthCheck"){
_serviceProvider = serviceProvider;
public QueryHealthCheck(ITweek tweek, IContextDriver contextDriver) : base("QueryHealthCheck"){
_tweek = tweek;
_contextDriver = contextDriver;
}

protected async override Task<HealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)){
var driver = _serviceProvider.GetService<IContextDriver>();
var engine = _serviceProvider.GetService<ITweek>();
protected async override ValueTask<HealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)){
try{
await engine.GetContextAndCalculate("@tweek/_", new System.Collections.Generic.HashSet<Identity> { new Identity("health_check", "test") }, driver);
await _tweek.GetContextAndCalculate("@tweek/_", new System.Collections.Generic.HashSet<Identity> { new Identity("health_check", "test") }, _contextDriver);
_state = HealthCheckResult.Healthy();
} catch (Exception ex){
_state = HealthCheckResult.Unhealthy("Querying is not avilabile:" + ex.Message);
@@ -25,7 +25,7 @@ public RulesRepositoryHealthCheck(IRulesRepository repository, IConfiguration co
_serviceProvider = serviceProvider;
}

protected override async Task<HealthCheckResult> CheckAsync(
protected override async ValueTask<HealthCheckResult> CheckAsync(
CancellationToken cancellationToken = new CancellationToken())
{
try
@@ -1,5 +1,5 @@
using App.Metrics;
using App.Metrics.Core.Options;
using App.Metrics.Timer;
using FSharpUtils.Newtonsoft;
using System.Collections.Generic;
using System.Threading.Tasks;
Oops, something went wrong.

0 comments on commit 30468ba

Please sign in to comment.