Skip to content

Commit

Permalink
More clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Aug 31, 2023
1 parent 179f386 commit 59e1729
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 44 deletions.
20 changes: 0 additions & 20 deletions OTLPView/DataModel/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,11 @@ public string ShortApplicationName
public MeterResult GetOrAddMeter(string meterName, Func<string, MeterResult> itemFactory) => _meters.GetOrAdd(meterName, _ => itemFactory.Invoke(meterName));
#endregion


#region Traces

private readonly ConcurrentDictionary<string, TraceScope> _scopes = new();
public IReadOnlyDictionary<string, TraceScope> Scopes => _scopes;

public TraceScope GetOrAddTrace(string scopeName, Func<string, TraceScope> itemFactory) => _scopes.GetOrAdd(scopeName, _ => itemFactory.Invoke(scopeName));
#endregion




}

public static class CommonHelpers
{
public static string GetServiceId(this Resource resource)
{
foreach (var attribute in resource.Attributes)
{
if (attribute.Key == OtlpApplication.SERVICE_INSTANCE_ID)
{
return attribute.Value.ValueString();
}
}
return null;
}
}
6 changes: 6 additions & 0 deletions OTLPView/Extensions/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ namespace OTLPView.Extensions;

public static class Helpers
{
public static string? GetServiceId(this Resource resource) =>
resource.Attributes
.FirstOrDefault(attr => attr.Key == OtlpApplication.SERVICE_INSTANCE_ID)
?.Value
.ValueString();

public static bool FindStringValue(this RepeatedField<KeyValue> attributes, string key, out string? value)
{
value = null;
Expand Down
5 changes: 4 additions & 1 deletion OTLPView/Pages/Metrics.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public string IsMetricSelected(Counter o, string cssClass) =>

public void SelectedCounterChanged(object item)
{
State.SelectedMetric = item as Counter;
if (item is Counter counter)
{
State.SelectedMetric = counter;
}
}
}
20 changes: 11 additions & 9 deletions OTLPView/Shared/DimensionedCounterView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public sealed partial class DimensionedCounterView
private string[] chartLabels;
private List<ChartSeries> chartValues;

[Parameter]
public DimensionScope Dimension
[Parameter, EditorRequired]
public required DimensionScope Dimension
{
get => _dimension;
set
Expand All @@ -24,8 +24,8 @@ public DimensionScope Dimension
}
}

[Parameter]
public Counter Counter { get; set; }
[Parameter, EditorRequired]
public required Counter Counter { get; set; }

protected override void OnInitialized()
{
Expand All @@ -51,12 +51,14 @@ private double[] CalcChartValues(DimensionScope dimension)
var end = CalcOffset(point.End);
if (start is not null && end is not null)
{
for (int i = start.GetValueOrDefault(0); i <= end.GetValueOrDefault(17); i++)
for (var i = start.GetValueOrDefault(0); i <= end.GetValueOrDefault(17); i++)
{
if (point as MetricValue<long> != null)
{ values[i] = Math.Max((point as MetricValue<long>).Value, values[i]); }
else
{ values[i] = Math.Max((point as MetricValue<double>).Value, values[i]); }
values[i] = point switch
{
MetricValue<long> @longMetric => Math.Max(@longMetric.Value, values[i]),
MetricValue<double> doubleMetric => Math.Max(doubleMetric.Value, values[i]),
_ => values[i]
};
}
}
}
Expand Down
21 changes: 9 additions & 12 deletions OTLPView/Shared/DimensionedHistogramView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
@if (mValue is HistogramValue)
{
var hValue = mValue as HistogramValue;
<div class="HistogramValue">
<span class="HistogramValueProperty">Count:</span>
<span class="HistogramValuePropertyValue">@hValue.Count</span>
<span class="HistogramValueProperty">Sum:</span>
<span class="HistogramValuePropertyValue">@hValue.Sum</span>
<span class="HistogramValueProperty">Buckets:</span>
@if (hValue.Values is not null)
<div class="HistogramValue">
<span class="HistogramValueProperty">Count:</span>
<span class="HistogramValuePropertyValue">@hValue.Count</span>

Check warning on line 18 in OTLPView/Shared/DimensionedHistogramView.razor

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
<span class="HistogramValueProperty">Sum:</span>
<span class="HistogramValuePropertyValue">@hValue.Sum</span>
<span class="HistogramValueProperty">Buckets:</span>
@if (hValue.Values is not null)
{
foreach (var v in hValue.Values)
{
Expand All @@ -32,14 +32,11 @@
{
<span class="MetricPointValue">@mValue.ToString()</span>
}

}
</div>
</div>

@code {
[Parameter]
public DimensionScope Dimension { get; set; }


[Parameter, EditorRequired]
public required DimensionScope Dimension { get; set; }
}
2 changes: 0 additions & 2 deletions OTLPView/Shared/TraceSpanView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
</div>
</div>
<div class="ChildSpans">


@foreach (var s in Span.ChildSpans)
{
<TraceSpanView Span="@s" />
Expand Down

0 comments on commit 59e1729

Please sign in to comment.