Skip to content

Commit

Permalink
Removing new ExecutionReason.Portal, and instead adding a new TraceLe…
Browse files Browse the repository at this point in the history
…vel property on FunctionStartedMessage to control this.
  • Loading branch information
mathewc committed Jan 11, 2016
1 parent 899cf03 commit c5477e3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host.Executors;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task<string> LogFunctionStartedAsync(FunctionStartedMessage message
throw new ArgumentNullException("message");
}

if (message.Reason == ExecutionReason.Portal)
if (message.LogLevel == TraceLevel.Verbose)
{
FunctionStatusMessage statusMessage = CreateFunctionStatusMessage(message);
await LogFunctionStatusAsync(statusMessage, cancellationToken);
Expand All @@ -56,7 +57,7 @@ public async Task LogFunctionCompletedAsync(FunctionCompletedMessage message, Ca
throw new ArgumentNullException("message");
}

if (message.Reason == ExecutionReason.Portal)
if (message.LogLevel == TraceLevel.Verbose)
{
FunctionStatusMessage statusMessage = CreateFunctionStatusMessage(message);
await LogFunctionStatusAsync(statusMessage, cancellationToken);
Expand Down
5 changes: 1 addition & 4 deletions src/Microsoft.Azure.WebJobs.Protocols/ExecutionReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ internal enum ExecutionReason
HostCall,

/// <summary>Indicates a function executed because of a request from a dashboard user.</summary>
Dashboard,

/// <summary>Indicates a function executed because of a request from an Azure Portal user.</summary>
Portal
Dashboard
}
}
19 changes: 19 additions & 0 deletions src/Microsoft.Azure.WebJobs.Protocols/FunctionStartedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

#if PUBLICPROTOCOL
namespace Microsoft.Azure.WebJobs.Protocols
Expand All @@ -21,6 +24,14 @@ internal class FunctionStartedMessage : HostOutputMessage
/// <summary>The name of the key used to store the function instance ID in metadata.</summary>
protected const string FunctionInstanceIdKey = "FunctionInstanceId";

/// <summary>
/// Constructs a new instance.
/// </summary>
public FunctionStartedMessage()
{
LogLevel = TraceLevel.Info;
}

/// <summary>Gets or sets the function instance ID.</summary>
public Guid FunctionInstanceId { get; set; }

Expand Down Expand Up @@ -48,6 +59,14 @@ internal class FunctionStartedMessage : HostOutputMessage
/// <summary>Gets or sets the path of the blob containing per-parameter logging data.</summary>
public LocalBlobDescriptor ParameterLogBlob { get; set; }

/// <summary>
/// Gets or sets the <see cref="TraceLevel"/> for the function invocation. The default
/// is <see cref="TraceLevel.Info"/>. When set to <see cref="TraceLevel.Verbose"/> additional
/// logging information will be written to storage.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public TraceLevel LogLevel { get; set; }

internal override void AddMetadata(IDictionary<string, string> metadata)
{
metadata.Add(MessageTypeKeyName, "FunctionStarted");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public static string FormatReason(this FunctionStartedMessage message)
return "This function was programmatically called via the host APIs.";
case ExecutionReason.Dashboard:
return message.ParentId.HasValue ? "Replayed from Dashboard." : "Ran from Dashboard.";
case ExecutionReason.Portal:
return message.ParentId.HasValue ? "Replayed from Portal." : "Ran from Portal.";
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host.Executors;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void CreateFunctionStatusMessage_FunctionComplete_CreatesExpectedMessage(
}

[Fact]
public async Task LogFunctionStartedAsync_Portal_WritesExpectedBlob()
public async Task LogFunctionStartedAsync_LogLevelVerbose_WritesExpectedBlob()
{
FunctionStartedMessage startMessage = new FunctionStartedMessage
{
Expand All @@ -97,7 +98,7 @@ public async Task LogFunctionStartedAsync_Portal_WritesExpectedBlob()
StartTime = DateTime.Now,
OutputBlob = new LocalBlobDescriptor(),
ParameterLogBlob = new LocalBlobDescriptor(),
Reason = ExecutionReason.Portal
LogLevel = TraceLevel.Verbose
};
FunctionStatusMessage statusMessage = FunctionStatusLogger.CreateFunctionStatusMessage(startMessage);

Expand All @@ -116,7 +117,7 @@ public async Task LogFunctionStartedAsync_Portal_WritesExpectedBlob()
}

[Fact]
public async Task LogFunctionStartedAsync_NonPortal_DoesNotWriteBlob()
public async Task LogFunctionStartedAsync_LogLevelDefault_DoesNotWriteBlob()
{
FunctionStartedMessage startMessage = new FunctionStartedMessage
{
Expand All @@ -143,7 +144,7 @@ public async Task LogFunctionCompletedAsync_Portal_WritesExpectedBlob()
EndTime = DateTime.Now,
OutputBlob = new LocalBlobDescriptor(),
ParameterLogBlob = new LocalBlobDescriptor(),
Reason = ExecutionReason.Portal
LogLevel = TraceLevel.Verbose
};
FunctionStatusMessage statusMessage = FunctionStatusLogger.CreateFunctionStatusMessage(completedMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,5 @@ public void FormatReason_ReasonDetailsAlreadySet_ReturnsExpectedReason()
string result = message.FormatReason();
Assert.Equal("The trigger fired!", result);
}

[Fact]
public void FormatReason_Portal_ReturnsExpectedReason()
{
FunctionStartedMessage message = new FunctionStartedMessage();
message.Reason = ExecutionReason.Portal;

Assert.Equal("Ran from Portal.", message.FormatReason());

message.ParentId = Guid.NewGuid();
Assert.Equal("Replayed from Portal.", message.FormatReason());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Diagnostics;
using Microsoft.Azure.WebJobs.Host.Protocols;
using Newtonsoft.Json;
using Xunit;

namespace Microsoft.Azure.WebJobs.Host.UnitTests.Protocols
{
public class FunctionStartedMessageTests
{
[Fact]
public void LogLevel_IsStringEnumSerialized()
{
FunctionStartedMessage message = new FunctionStartedMessage()
{
LogLevel = TraceLevel.Verbose
};
string json = JsonConvert.SerializeObject(message);
Assert.True(json.Contains("\"LogLevel\":\"Verbose\""));

FunctionStartedMessage result = JsonConvert.DeserializeObject<FunctionStartedMessage>(json);
Assert.Equal(TraceLevel.Verbose, result.LogLevel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<Compile Include="Loggers\TraceWriterFunctionInstanceLoggerTests.cs" />
<Compile Include="NullExtensionTypeLocator.cs" />
<Compile Include="Protocols\FunctionStartedMessageExtensionsTests.cs" />
<Compile Include="Protocols\FunctionStartedMessageTests.cs" />
<Compile Include="Protocols\ProtocolSerializationTests.cs" />
<Compile Include="Queues\QueueListenerTests.cs" />
<Compile Include="Queues\QueueProcessorFactoryContextTests.cs" />
Expand Down

0 comments on commit c5477e3

Please sign in to comment.