Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove Microsoft.Extensions.Logging from flagd provider #233

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
<!-- The schema.proto file referenced here will be used to automatically generate the Grpc client when executing 'dotnet build' -->
<!-- The generated files will be placed in ./obj/Debug/netstandard2.0/Protos -->
<PackageReference Include="JsonLogic.Net" Version="1.1.11" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="murmurhash" Version="1.0.3" />
<PackageReference Include="Semver" Version="2.3.0" />
<Protobuf Include="schemas\protobuf\flagd\evaluation\v1\evaluation.proto" GrpcServices="Client" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Text;
using JsonLogic.Net;
using Microsoft.Extensions.Logging;
using Murmur;
using Newtonsoft.Json.Linq;
using Semver;
Expand All @@ -13,21 +12,8 @@ namespace OpenFeature.Contrib.Providers.Flagd.Resolver.InProcess.CustomEvaluator
/// <inheritdoc/>
public class FractionalEvaluator
{

internal ILogger Logger { get; set; }

internal FractionalEvaluator()
{
var loggerFactory = LoggerFactory.Create(
builder => builder
// add console as logging target
.AddConsole()
// add debug output as logging target
.AddDebug()
// set minimum level to log
.SetMinimumLevel(LogLevel.Debug)
);
Logger = loggerFactory.CreateLogger<FractionalEvaluator>();
}

class FractionalEvaluationDistribution
Expand Down Expand Up @@ -118,7 +104,6 @@ internal object Evaluate(IProcessJsonLogic p, JToken[] args, object data)
}
}

Logger.LogDebug("No matching bucket found");
return "";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using JsonLogic.Net;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json.Linq;
using Semver;

Expand All @@ -10,23 +8,10 @@ namespace OpenFeature.Contrib.Providers.Flagd.Resolver.InProcess.CustomEvaluator
/// <inheritdoc/>
public class SemVerEvaluator
{
internal ILogger Logger { get; set; }

internal SemVerEvaluator()
{
var loggerFactory = LoggerFactory.Create(
builder => builder
// add console as logging target
.AddConsole()
// add debug output as logging target
.AddDebug()
// set minimum level to log
.SetMinimumLevel(LogLevel.Debug)
);
Logger = loggerFactory.CreateLogger<SemVerEvaluator>();
}


const string OperatorEqual = "=";
const string OperatorNotEqual = "!=";
const string OperatorLess = "<";
Expand All @@ -53,37 +38,32 @@ internal object Evaluate(IProcessJsonLogic p, JToken[] args, object data)
var targetVersionString = p.Apply(args[2], data).ToString();

//convert to semantic versions
try
if (!SemVersion.TryParse(versionString, SemVersionStyles.Strict, out var version) ||
!SemVersion.TryParse(targetVersionString, SemVersionStyles.Strict, out var targetVersion))
{
var version = SemVersion.Parse(versionString, SemVersionStyles.Strict);
var targetVersion = SemVersion.Parse(targetVersionString, SemVersionStyles.Strict);

switch (semVerOperator)
{
case OperatorEqual:
return version.CompareSortOrderTo(targetVersion) == 0;
case OperatorNotEqual:
return version.CompareSortOrderTo(targetVersion) != 0;
case OperatorLess:
return version.CompareSortOrderTo(targetVersion) < 0;
case OperatorLessOrEqual:
return version.CompareSortOrderTo(targetVersion) <= 0;
case OperatorGreater:
return version.CompareSortOrderTo(targetVersion) > 0;
case OperatorGreaterOrEqual:
return version.CompareSortOrderTo(targetVersion) >= 0;
case OperatorMatchMajor:
return version.Major == targetVersion.Major;
case OperatorMatchMinor:
return version.Major == targetVersion.Major && version.Minor == targetVersion.Minor;
default:
return false;
}
return false;
}
catch (Exception e)

switch (semVerOperator)
{
Logger?.LogDebug("Exception during SemVer evaluation: " + e.Message);
return false;
case OperatorEqual:
return version.CompareSortOrderTo(targetVersion) == 0;
case OperatorNotEqual:
return version.CompareSortOrderTo(targetVersion) != 0;
case OperatorLess:
return version.CompareSortOrderTo(targetVersion) < 0;
case OperatorLessOrEqual:
return version.CompareSortOrderTo(targetVersion) <= 0;
case OperatorGreater:
return version.CompareSortOrderTo(targetVersion) > 0;
case OperatorGreaterOrEqual:
return version.CompareSortOrderTo(targetVersion) >= 0;
case OperatorMatchMajor:
return version.Major == targetVersion.Major;
case OperatorMatchMinor:
return version.Major == targetVersion.Major && version.Minor == targetVersion.Minor;
default:
return false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Runtime.InteropServices;
using JsonLogic.Net;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json.Linq;
using OpenFeature.Error;
using OpenFeature.Model;
Expand All @@ -11,20 +9,8 @@ namespace OpenFeature.Contrib.Providers.Flagd.Resolver.InProcess.CustomEvaluator
{
internal class StringEvaluator
{
internal ILogger Logger { get; set; }

internal StringEvaluator()
{
var loggerFactory = LoggerFactory.Create(
builder => builder
// add console as logging target
.AddConsole()
// add debug output as logging target
.AddDebug()
// set minimum level to log
.SetMinimumLevel(LogLevel.Debug)
);
Logger = loggerFactory.CreateLogger<StringEvaluator>();
}

internal object StartsWith(IProcessJsonLogic p, JToken[] args, object data)
Expand Down