Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

[Design] Add overloads for IsEnabled #65

Merged
merged 4 commits into from
Apr 21, 2017
Merged

Conversation

jbagga
Copy link
Contributor

@jbagga jbagga commented Apr 18, 2017

Addresses #61

Are there test cases I should add? I don't have enough context yet.

cc @rynowak

@dnfclas
Copy link

dnfclas commented Apr 18, 2017

@jbagga,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@@ -54,6 +69,25 @@ private static Listener EnlistTarget(object target, Func<string, bool> isEnabled
return listener;
}

private static Listener EnlistTarget(object target, Func<string, object, object, bool> isEnabled)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can turn a Func<string, bool> into a Func<string, object, object, bool> so then you only need one 'real' code path.

Func<string, bool> original = ...;
Func<string, object, object, bool> adapter = (a, b, c) => original(a);

(_listener.IsEnabled == null || _listener.IsEnabled(diagnosticName, null, null));
}

public bool IsEnabled(string diagnosticName, object arg1, object arg2 = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little bit of a wonky signature. Where does it come from?


return listener;
}

public bool IsEnabled(string diagnosticName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this one call the longer o/l

public Listener(object target, Func<string, bool> isEnabled)
{
Target = target;
IsEnabled = (isEnabled == null) ? (Func<string, object, object, bool>) null : (a, b, c) => isEnabled(a);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you figured it out 👍 - flow this up one level of abstraction and that will dedupe some code

@@ -79,7 +125,7 @@ public void Write(string diagnosticName, object parameters)
return;
}

if (_listener.IsEnabled != null && !_listener.IsEnabled(diagnosticName))
if (_listener.IsEnabled != null && !_listener.IsEnabled(diagnosticName, null, null))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we just always call this with null, null then we're not really supporting it. Where are we supposed to get these values from?

Copy link
Contributor Author

@jbagga jbagga Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure. I think it can be any context we want to associate with the events. https://github.com/dotnet/corefx/issues/15984#issuecomment-278692599 I was hoping to hear your thoughts on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this can now be a part of the event context instead of a class?

@jbagga
Copy link
Contributor Author

jbagga commented Apr 20, 2017

Updated. Spoke to @rynowak offline and made some behavior changes to the Write method by removing https://github.com/aspnet/EventNotification/blob/dev/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticSourceAdapter.cs#L82-L85

cc @Eilon

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks right. A few small points of feedback

public DiagnosticSourceAdapter(
object target,
Func<string, bool> isEnabled,
IDiagnosticSourceMethodAdapter methodAdapter)
{
_methodAdapter = methodAdapter;
_listener = EnlistTarget(target, (isEnabled == null) ? (Func<string, object, object, bool>)null : (a, b, c) => isEnabled(a));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this constructor chain to the one at L42?

IsEnabled = (isEnabled == null) ? (Func<string, object, object, bool>) null : (a, b, c) => isEnabled(a);

Subscriptions = new Dictionary<string, Subscription>(StringComparer.Ordinal);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete this constructor, and keep the one at L154.

@@ -33,10 +33,13 @@ public class OneTarget
{
public int OneCallCount { get; private set; }

public object TargetInfo { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?

Assert.Equal("Target info", arg1);
callCount++;
return true;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test where you register a Func<string, bool> but call `IsEnabled(string, object, object)

@jbagga
Copy link
Contributor Author

jbagga commented Apr 21, 2017

Filed an issue #66 for tracking the change to the Write method. @rynowak @Eilon

@jbagga
Copy link
Contributor Author

jbagga commented Apr 21, 2017

@rynowak Updated

@jbagga jbagga merged commit ea21426 into dev Apr 21, 2017
@jbagga jbagga deleted the jbagga/DiagnosticSourceAPI61 branch April 21, 2017 17:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants