-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
- Loading branch information
Showing
8 changed files
with
468 additions
and
26 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
98 changes: 98 additions & 0 deletions
98
src/OpenTelemetry.Exporter.ZPages/Implementation/ZPagesSpanInformation.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,98 @@ | ||
// <copyright file="ZPagesSpanInformation.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using OpenTelemetry.Trace.Export; | ||
|
||
namespace OpenTelemetry.Exporter.ZPages.Implementation | ||
{ | ||
/// <summary> | ||
/// Stores the span information aggregated according to span name. | ||
/// </summary> | ||
public class ZPagesSpanInformation | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ZPagesSpanInformation"/> class. | ||
/// </summary> | ||
public ZPagesSpanInformation() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ZPagesSpanInformation"/> class when span data is provided. | ||
/// </summary> | ||
/// <param name="spanData">Input span data to be used for initialization.</param> | ||
public ZPagesSpanInformation(SpanData spanData) | ||
{ | ||
this.Name = spanData.Name; | ||
this.Count = 1; | ||
this.EndedCount = 0; | ||
this.LastUpdated = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds(); | ||
this.TotalLatency = 0; | ||
this.AvgLatencyTotal = 0; | ||
this.ErrorCount = 0; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the span. | ||
/// </summary> | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the total count of the span. | ||
/// </summary> | ||
public long Count { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the total count of the ended span. | ||
/// </summary> | ||
public long EndedCount { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the total error count of the span. | ||
/// </summary> | ||
public long ErrorCount { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the total average latency of the span. | ||
/// </summary> | ||
public long AvgLatencyTotal { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the total latency of all spans. | ||
/// </summary> | ||
public long TotalLatency { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the last updated timestamp. | ||
/// </summary> | ||
public long LastUpdated { get; set; } | ||
|
||
/// <summary> | ||
/// Calculates and returns the total average latency. | ||
/// </summary> | ||
/// <returns>Total average latency.</returns> | ||
public long GetTotalAverageLatency() | ||
{ | ||
this.AvgLatencyTotal = this.TotalLatency / this.EndedCount; | ||
this.LastUpdated = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds(); | ||
return this.AvgLatencyTotal; | ||
} | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
src/OpenTelemetry.Exporter.ZPages/Implementation/ZPagesSpans.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,123 @@ | ||
// <copyright file="ZPagesSpans.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Timers; | ||
|
||
namespace OpenTelemetry.Exporter.ZPages.Implementation | ||
{ | ||
/// <summary> | ||
/// Implements the ZPages Span Queue which stores all the required span information. | ||
/// </summary> | ||
public static class ZPagesSpans | ||
{ | ||
private static long startTime; | ||
|
||
/// <summary> | ||
/// Initializes static members of the <see cref="ZPagesSpans"/> class. | ||
/// </summary> | ||
static ZPagesSpans() | ||
{ | ||
ZQueue = new LinkedList<Dictionary<string, ZPagesSpanInformation>>(); | ||
ProcessingSpanList = new Dictionary<string, long>(); | ||
CurrentMinuteSpanList = new ConcurrentDictionary<string, ZPagesSpanInformation>(); | ||
CurrentHourSpanList = new ConcurrentDictionary<string, ZPagesSpanInformation>(); | ||
TotalSpanCount = new Dictionary<string, long>(); | ||
TotalEndedSpanCount = new Dictionary<string, long>(); | ||
TotalSpanErrorCount = new Dictionary<string, long>(); | ||
TotalSpanLatency = new Dictionary<string, long>(); | ||
startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets ZQueue which stores the minute-wise span information. | ||
/// </summary> | ||
public static LinkedList<Dictionary<string, ZPagesSpanInformation>> ZQueue { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the current minute span information list. | ||
/// </summary> | ||
public static ConcurrentDictionary<string, ZPagesSpanInformation> CurrentMinuteSpanList { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the current hour span information list. | ||
/// </summary> | ||
public static ConcurrentDictionary<string, ZPagesSpanInformation> CurrentHourSpanList { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the processing span information list. This holds the names of the spans which have not ended yet, along with the active count. | ||
/// </summary> | ||
public static Dictionary<string, long> ProcessingSpanList { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the count of spans name-wise. | ||
/// </summary> | ||
public static Dictionary<string, long> TotalSpanCount { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the count of ended spans name-wise. | ||
/// </summary> | ||
public static Dictionary<string, long> TotalEndedSpanCount { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the count of span errors according to span name. | ||
/// </summary> | ||
public static Dictionary<string, long> TotalSpanErrorCount { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the total latency of spans name-wise. | ||
/// </summary> | ||
public static Dictionary<string, long> TotalSpanLatency { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the retention time (in milliseconds) for the metrics. | ||
/// </summary> | ||
public static long RetentionTime { get; set; } | ||
|
||
/// <summary> | ||
/// Triggers Calculations every minute. | ||
/// </summary> | ||
/// <param name="source">Source.</param> | ||
/// <param name="e">Event Arguments.</param> | ||
public static void PurgeCurrentMinuteData(object source, ElapsedEventArgs e) | ||
{ | ||
// Enqueue the last minute's span information list to ZQueue | ||
ZQueue.AddFirst(new Dictionary<string, ZPagesSpanInformation>(CurrentMinuteSpanList)); | ||
|
||
// Clear the current minute span list to start recording new spans only | ||
CurrentMinuteSpanList.Clear(); | ||
|
||
// Remove the stale span information which is at the end of the list | ||
if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - startTime >= RetentionTime) | ||
{ | ||
ZQueue.RemoveLast(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Triggers Calculations every hour. | ||
/// </summary> | ||
/// <param name="source">Source.</param> | ||
/// <param name="e">Event Arguments.</param> | ||
public static void PurgeCurrentHourData(object source, ElapsedEventArgs e) | ||
{ | ||
// Clear the last hour's span information list | ||
CurrentHourSpanList.Clear(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.