Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit d087855

Browse files
Next iteration of cleaning APIs from IList (#94)
* links are IEnumerable * added retry into flacky test * no ILists in StackDriver * removed comments * fix running span storages * few more fixes * fix failed test
1 parent a0ad255 commit d087855

29 files changed

+169
-243
lines changed

src/OpenCensus.Abstractions/Trace/Export/ILinks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface ILinks
2626
/// <summary>
2727
/// Gets the list of links.
2828
/// </summary>
29-
IList<ILink> Links { get; }
29+
IEnumerable<ILink> Links { get; }
3030

3131
/// <summary>
3232
/// Gets the number of dropped links due to exceeding the maximum links count limit.

src/OpenCensus.Abstractions/Trace/Export/IRunningSpanStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface IRunningSpanStore
3333
/// </summary>
3434
/// <param name="filter">Filter to apply to query running spans.</param>
3535
/// <returns>List of currently running spans.</returns>
36-
IList<ISpanData> GetRunningSpans(IRunningSpanStoreFilter filter);
36+
IEnumerable<ISpanData> GetRunningSpans(IRunningSpanStoreFilter filter);
3737

3838
/// <summary>
3939
/// Called when span got started.

src/OpenCensus.Abstractions/Trace/Export/ISampledSpanStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public interface ISampledSpanStore
3838
/// </summary>
3939
/// <param name="filter">Filter to use to query sampled store.</param>
4040
/// <returns>List of spans satisfying filtering criteria.</returns>
41-
IList<ISpanData> GetLatencySampledSpans(ISampledSpanStoreLatencyFilter filter);
41+
IEnumerable<ISpanData> GetLatencySampledSpans(ISampledSpanStoreLatencyFilter filter);
4242

4343
/// <summary>
4444
/// Gets the list of error spans using provided error filter.
4545
/// </summary>
4646
/// <param name="filter">Filter to use to query store.</param>
4747
/// <returns>List of sampled spans satisfying filtering criteria.</returns>
48-
IList<ISpanData> GetErrorSampledSpans(ISampledSpanStoreErrorFilter filter);
48+
IEnumerable<ISpanData> GetErrorSampledSpans(ISampledSpanStoreErrorFilter filter);
4949

5050
/// <summary>
5151
/// Registers span names for collection.

src/OpenCensus.Abstractions/Trace/Export/ITimedEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface ITimedEvents<T>
2727
/// <summary>
2828
/// Gets ths list of timed events.
2929
/// </summary>
30-
IList<ITimedEvent<T>> Events { get; }
30+
IEnumerable<ITimedEvent<T>> Events { get; }
3131

3232
/// <summary>
3333
/// Gets the number of dropped events due to active limits.

src/OpenCensus.Exporter.Prometheus/Implementation/PrometheusMetricBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,30 @@ internal class PrometheusMetricBuilder
3232
{
3333
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
3434
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
35-
'_', ':'
35+
'_', ':',
3636
};
3737

3838
private static char[] nameCharset = new char[]
3939
{
4040
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
4141
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
4242
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
43-
'_', ':'
43+
'_', ':',
4444
};
4545

4646
private static char[] firstCharacterLabelCharset = new char[]
4747
{
4848
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
4949
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
50-
'_'
50+
'_',
5151
};
5252

5353
private static char[] labelCharset = new char[]
5454
{
5555
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
5656
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
5757
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
58-
'_'
58+
'_',
5959
};
6060

6161
private readonly IList<PrometheusMetricValueBuilder> values = new List<PrometheusMetricValueBuilder>();

src/OpenCensus.Exporter.Stackdriver/Utils/CommonUtils.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,29 @@ namespace OpenCensus.Exporter.Stackdriver.Utils
2626
public static class CommonUtils
2727
{
2828
/// <summary>
29-
/// Divide the source list into batches of lists of given size
29+
/// Divide the source list into batches of lists of given size.
3030
/// </summary>
3131
/// <typeparam name="T">The type of the list</typeparam>
3232
/// <param name="source">The list</param>
3333
/// <param name="size">Size of the batch</param>
3434
/// <returns></returns>
35-
public static IEnumerable<List<T>> Partition<T>(this IList<T> source, Int32 size)
35+
public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> source, int size)
3636
{
37-
for (int i = 0; i < Math.Ceiling(source.Count / (double)size); i++)
37+
using (var enumerator = source.GetEnumerator())
3838
{
39-
yield return new List<T>(source.Skip(size * i).Take(size));
39+
while (enumerator.MoveNext())
40+
{
41+
yield return WalkPartition(enumerator, size - 1);
42+
}
43+
}
44+
}
45+
46+
private static IEnumerable<T> WalkPartition<T>(IEnumerator<T> source, int size)
47+
{
48+
yield return source.Current;
49+
for (int i = 0; i < size && source.MoveNext(); i++)
50+
{
51+
yield return source.Current;
4052
}
4153
}
4254
}

src/OpenCensus/Common/Duration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override string ToString()
7272
+ "}";
7373
}
7474

75-
/// <inheritdoc/>
75+
/// <inheritdoc/>
7676
public override bool Equals(object o)
7777
{
7878
if (o == this)
@@ -89,7 +89,7 @@ public override bool Equals(object o)
8989
return false;
9090
}
9191

92-
/// <inheritdoc/>
92+
/// <inheritdoc/>
9393
public override int GetHashCode()
9494
{
9595
long h = 1;

src/OpenCensus/Stats/CumulativeMutableViewData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal CumulativeMutableViewData(IView view, ITimestamp start)
3333

3434
internal override void Record(ITagContext context, double value, ITimestamp timestamp)
3535
{
36-
IList<ITagValue> values = GetTagValues(GetTagMap(context), this.View.Columns);
36+
var values = GetTagValues(GetTagMap(context), this.View.Columns);
3737
var tagValues = TagValues.Create(values);
3838
if (!this.tagValueAggregationMap.ContainsKey(tagValues))
3939
{

src/OpenCensus/Stats/IntervalBucket.cs

Lines changed: 0 additions & 99 deletions
This file was deleted.

src/OpenCensus/Stats/MeasureMapBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace OpenCensus.Stats
2222

2323
internal class MeasureMapBuilder
2424
{
25-
private readonly IList<IMeasurement> measurements = new List<IMeasurement>();
25+
private readonly List<IMeasurement> measurements = new List<IMeasurement>();
2626

2727
internal static MeasureMapBuilder Builder()
2828
{

0 commit comments

Comments
 (0)