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

Feature work/kafka - Revise byte count metric #1987

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
22 changes: 15 additions & 7 deletions .github/workflows/all_solutions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,10 @@ jobs:
with:
fetch-depth: 0

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@1ff57057b5cfdc39105cd07a01d78e9b0ea0c14c # v1.3.1

- name: Build FullAgent.sln
run: |
Write-Host "List NuGet Sources"
dotnet nuget list source # For unknown reasons, this step is necessary to avoid subsequent problems with NuGet package restore
Write-Host "MSBuild.exe -restore -m -p:Configuration=Release -p:AllowUnsafeBlocks=true ${{ env.fullagent_solution_path }}"
MSBuild.exe -restore -m -p:Configuration=Release -p:AllowUnsafeBlocks=true ${{ env.fullagent_solution_path }}
Write-Host "dotnet build --force --configuration Release -p:AllowUnsafeBlocks=true ${{ env.fullagent_solution_path }}"
dotnet build --force --configuration Release -p:AllowUnsafeBlocks=true ${{ env.fullagent_solution_path }}
shell: powershell

- name: Create agentVersion
Expand All @@ -75,6 +70,15 @@ jobs:
echo "version=$agentVersion" >> $env:GITHUB_OUTPUT
shell: powershell

- name: Archive Extensions/Providers DLLs
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: Providers
path: |
${{ github.workspace }}\src\Agent\NewRelic\Agent\Extensions\Providers\**\NewRelic.Providers.*.dll
${{ github.workspace }}\src\Agent\NewRelic\Agent\Extensions\Providers\**\*.xml
if-no-files-found: error

- name: Archive NewRelic.Agent.Extensions
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
Expand Down Expand Up @@ -110,6 +114,10 @@ jobs:
certutil.exe -f -user -p ${{ secrets.CERT_PASSPHRASE }} -importPFX ${{ steps.write_cert.outputs.filePath }} NoRoot
shell: powershell


- name: Add msbuild to PATH (required for MsiInstaller build)
uses: microsoft/setup-msbuild@1ff57057b5cfdc39105cd07a01d78e9b0ea0c14c # v1.3.1

- name: Build MsiInstaller.sln x86
run: |
Write-Host "MSBuild.exe -restore -m -p:Configuration=Release -p:AllowUnsafeBlocks=true -p:Platform=x86 ${{ env.msi_solution_path }}"
Expand Down
27 changes: 27 additions & 0 deletions build/build_home.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@ foreach ($storageDir in $storageDirs) {
}
}

Write-Host ""
Write-Host "NetFramework wrappers:"
foreach ($item in $netFrameworkWrapperHash.GetEnumerator())
{
Write-Host $item.Name
}

Write-Host ""
Write-Host "NetStandard wrappers:"
foreach ($item in $netstandard20WrapperHash.GetEnumerator())
{
Write-Host $item.Name
}

Write-Host ""
Write-Host "NetFramework storage:"
foreach ($item in $netFrameworkStorageArray.GetEnumerator())
{
Write-Host $item.Name
}

Write-Host ""
Write-Host "NetStandard storage:"
foreach ($item in $netstandard20StorageArray.GetEnumerator())
{
Write-Host $item.Name
}

#######################
# Create home folders #
Expand Down
5 changes: 5 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ public void RecordCountMetric(string metricName, long count = 1)
_agentHealthReporter.ReportCountMetric(metricName, count);
}

public void RecordByteMetric(string metricName, long totalBytes, long? exclusiveBytes = null)
{
_agentHealthReporter.ReportByteMetric(metricName, totalBytes, exclusiveBytes);
}

public void RecordLogMessage(string frameworkName, object logEvent, Func<object, DateTime> getTimestamp, Func<object, object> getLevel, Func<object, string> getLogMessage, Func<object, Exception> getLogException, Func<object, Dictionary<string, object>> getContextData, string spanId, string traceId)
{
_agentHealthReporter.ReportLogForwardingFramework(frameworkName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public void ReportCountMetric(string metricName, long count)
var metric = _metricBuilder.TryBuildCountMetric(metricName, count);
TrySend(metric);
}
public void ReportByteMetric(string metricName, long totalBytes, long? exclusiveBytes = null)
{
var metric = _metricBuilder.TryBuildByteMetric(metricName, totalBytes, exclusiveBytes);
TrySend(metric);
}



public void ReportDotnetVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,6 @@ public interface IAgentHealthReporter : IOutOfBandMetricSource
void ReportLoggingEventsDropped(int droppedCount);
void ReportLogForwardingFramework(string logFramework);
void ReportLogForwardingEnabledWithFramework(string logFramework);
void ReportByteMetric(string metricName, long totalBytes, long? exclusiveBytes = null);
}
}
1 change: 1 addition & 0 deletions src/Agent/NewRelic/Agent/Core/WireModels/IMetricBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,6 @@ public interface IMetricBuilder
MetricWireModel TryBuildSupportabilityLoggingEventsDroppedMetric(int droppedCount);

MetricWireModel TryBuildCountMetric(string metricName, long count);
MetricWireModel TryBuildByteMetric(string metricName, long totalBytes, long? exclusiveBytes = null);
}
}
6 changes: 6 additions & 0 deletions src/Agent/NewRelic/Agent/Core/WireModels/MetricWireModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,12 @@ public MetricWireModel TryBuildCountMetric(string metricName, long count)
return BuildMetric(_metricNameService, metricName, null, data);
}

public MetricWireModel TryBuildByteMetric(string metricName, long totalBytes, long? exclusiveBytes)
{
var data = MetricDataWireModel.BuildByteData(totalBytes, exclusiveBytes);
return BuildMetric(_metricNameService, metricName, null, data);
}

#endregion
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public interface IAgentExperimental
/// <param name="metricName"></param>
/// <param name="count"></param>
void RecordCountMetric(string metricName, long count = 1);
/// <summary>
/// Records a byte count metric with the given name
/// </summary>
/// <param name="metricName"></param>
/// <param name="totalBytes"></param>
/// <param name="exclusiveBytes"></param>
void RecordByteMetric(string metricName, long totalBytes, long? exclusiveBytes = null);

/// <summary>
/// Records the log message in the transaction to later be forwarded if log forwarding is enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static void ReportSizeMetrics(IAgent agent, ITransaction transaction, st
// Add metrics for bytes received and messages received
var agentExp = agent.GetExperimentalApi();
agentExp.RecordCountMetric($"Message/Kafka/Topic/Named/{topic}/Received/Messages", 1);
agentExp.RecordCountMetric($"Message/Kafka/Topic/Named/{topic}/Received/Bytes", totalSize);
agentExp.RecordByteMetric($"Message/Kafka/Topic/Named/{topic}/Received/Bytes", totalSize);
}

private static Func<object, string> GetTopicAccessorFunc(Type t) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,45 @@ public void ReportSupportabilityCountMetric_SuppliedCount()
);
}

[Test]
public void ReportCountMetric()
{
const string MetricName = "Some/Metric/Name";
_agentHealthReporter.ReportCountMetric(MetricName, 2);
Assert.AreEqual(1, _publishedMetrics.Count);
NrAssert.Multiple(
() => Assert.AreEqual(MetricName, _publishedMetrics[0].MetricName.Name),
() => Assert.AreEqual(2, _publishedMetrics[0].Data.Value0)
);
}

[Test]
public void ReportByteMetric()
{
const string MetricName = "Some/Metric/Name";
const long totalBytes = 1024 * 1024 * 1024;
_agentHealthReporter.ReportByteMetric(MetricName, totalBytes);
Assert.AreEqual(1, _publishedMetrics.Count);
NrAssert.Multiple(
() => Assert.AreEqual(MetricName, _publishedMetrics[0].MetricName.Name),
() => Assert.AreEqual(MetricDataWireModel.BuildByteData(totalBytes), _publishedMetrics[0].Data)
);
}

[Test]
public void ReportByteMetric_WithExclusiveBytes()
{
const string MetricName = "Some/Metric/Name";
const long totalBytes = 1024 * 1024 * 1024;
const long exclusiveBytes = 1024 * 1024 * 64;
_agentHealthReporter.ReportByteMetric(MetricName, totalBytes, exclusiveBytes);
Assert.AreEqual(1, _publishedMetrics.Count);
NrAssert.Multiple(
() => Assert.AreEqual(MetricName, _publishedMetrics[0].MetricName.Name),
() => Assert.AreEqual(MetricDataWireModel.BuildByteData(totalBytes, exclusiveBytes), _publishedMetrics[0].Data)
);
}

[Test]
public void CollectMetrics_ReportsAgentVersion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,52 @@ public void BuildSupportabilityLoggingEventsDroppedMetric()
);
}

[Test]
public void BuildCountMetric()
{
const string metricName = "Some/Metric/Name";
const int count = 999;

var actual = _metricBuilder.TryBuildCountMetric(metricName, count);

NrAssert.Multiple(
() => Assert.AreEqual(metricName, actual.MetricName.Name),
() => Assert.IsNull(actual.MetricName.Scope),
() => Assert.AreEqual(count, actual.Data.Value0)
);
}

[Test]
public void BuildByteMetric()
{
const string metricName = "Some/Metric/Name";
const long byteCount = 1024 * 1024 * 1024;

var actual = _metricBuilder.TryBuildByteMetric(metricName, byteCount);

NrAssert.Multiple(
() => Assert.AreEqual(metricName, actual.MetricName.Name),
() => Assert.IsNull(actual.MetricName.Scope),
() => Assert.AreEqual(MetricDataWireModel.BuildByteData(byteCount), actual.Data)
);
}

[Test]
public void BuildByteMetric_WithExclusiveBytes()
{
const string metricName = "Some/Metric/Name";
const long totalBytes = 1024 * 1024 * 1024;
const long exclusiveBytes = 1024 * 1024 * 128;

var actual = _metricBuilder.TryBuildByteMetric(metricName, totalBytes, exclusiveBytes);

NrAssert.Multiple(
() => Assert.AreEqual(metricName, actual.MetricName.Name),
() => Assert.IsNull(actual.MetricName.Scope),
() => Assert.AreEqual(MetricDataWireModel.BuildByteData(totalBytes, exclusiveBytes), actual.Data)
);
}

#endregion

#region DistributedTracing
Expand Down
Loading