Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filtering support for logs (#967)
* Add filter support * Add support for filter * Add tests * Add tests * Fix build * Fix build after merge
- Loading branch information
1 parent
e68f759
commit a8cdf8d
Showing
16 changed files
with
424 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/logs/ModuleLogFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Agent.Core.Logs | ||
{ | ||
using System.Text.RegularExpressions; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
using Newtonsoft.Json; | ||
|
||
public class ModuleLogFilter | ||
{ | ||
public ModuleLogFilter(Option<int> tail, Option<int> since, Option<int> logLevel, Option<string> regex) | ||
{ | ||
this.Tail = tail; | ||
this.Since = since; | ||
this.LogLevel = logLevel; | ||
this.Regex = regex.Map(r => new Regex(r)); | ||
} | ||
|
||
[JsonConstructor] | ||
ModuleLogFilter(int? tail, int? since, int? loglevel, string regex) | ||
: this(Option.Maybe(tail), Option.Maybe(since), Option.Maybe(loglevel), Option.Maybe(regex)) | ||
{ | ||
} | ||
|
||
public static ModuleLogFilter Empty = new ModuleLogFilter(Option.None<int>(), Option.None<int>(), Option.None<int>(), Option.None<string>()); | ||
|
||
public Option<int> Tail { get; } | ||
|
||
public Option<int> Since { get; } | ||
|
||
public Option<int> LogLevel { get; } | ||
|
||
public Option<Regex> Regex { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/logs/ModuleLogMessageData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Agent.Core.Logs | ||
{ | ||
extern alias akka; | ||
using System; | ||
using akka::Akka.IO; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
using Newtonsoft.Json; | ||
|
||
public class ModuleLogMessageData : ModuleLogMessage | ||
{ | ||
public ModuleLogMessageData( | ||
string iotHub, | ||
string deviceId, | ||
string moduleId, | ||
string stream, | ||
int logLevel, | ||
Option<DateTime> timeStamp, | ||
string text, | ||
ByteString fullFrame, | ||
string fullText) | ||
: base(iotHub, deviceId, moduleId, stream, logLevel, timeStamp, text) | ||
{ | ||
this.FullText = Preconditions.CheckNonWhiteSpace(fullText, fullText); | ||
this.FullFrame = Preconditions.CheckNotNull(fullFrame, nameof(fullFrame)); | ||
} | ||
|
||
[JsonIgnore] | ||
public ByteString FullFrame { get; } | ||
|
||
[JsonIgnore] | ||
public string FullText { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/logs/DockerFraming.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Agent.Core.Test.Logs | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
public class DockerFraming | ||
{ | ||
public static byte[] Frame(IEnumerable<string> logTexts) | ||
{ | ||
var outputBytes = new List<byte>(); | ||
foreach (string text in logTexts) | ||
{ | ||
outputBytes.AddRange(Frame(text)); | ||
} | ||
|
||
return outputBytes.ToArray(); | ||
} | ||
|
||
public static byte[] Frame(string text) | ||
{ | ||
byte streamByte = 01; | ||
var padding = new byte[3]; | ||
var outputBytes = new List<byte>(); | ||
byte[] textBytes = Encoding.UTF8.GetBytes(text); | ||
byte[] lenBytes = GetLengthBytes(textBytes.Length); | ||
outputBytes.Add(streamByte); | ||
outputBytes.AddRange(padding); | ||
outputBytes.AddRange(lenBytes); | ||
outputBytes.AddRange(textBytes); | ||
return outputBytes.ToArray(); | ||
} | ||
|
||
static byte[] GetLengthBytes(int len) | ||
{ | ||
byte[] intBytes = BitConverter.GetBytes(len); | ||
if (BitConverter.IsLittleEndian) | ||
{ | ||
Array.Reverse(intBytes); | ||
} | ||
|
||
byte[] result = intBytes; | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.