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

Commit 70c4912

Browse files
Sergey KanzhelevSergey Kanzhelev
authored andcommitted
fix non-document warnings
1 parent 33f6f9d commit 70c4912

25 files changed

Lines changed: 397 additions & 391 deletions

OpenCensus.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Tests", "test\Op
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B7408D66-487A-40E1-BDB7-BC17BD28F721}"
1111
ProjectSection(SolutionItems) = preProject
12+
.travis.yml = .travis.yml
13+
CHANGELOG.md = CHANGELOG.md
14+
CONTRIBUTING.md = CONTRIBUTING.md
1215
NuGet.config = NuGet.config
16+
README.md = README.md
1317
EndProjectSection
1418
EndProject
1519
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E-03FA-4FFF-89A5-C51F107623FD}"

src/OpenCensus/Impl/Stats/CumulativeMutableViewData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ namespace OpenCensus.Stats
2222

2323
internal class CumulativeMutableViewData : MutableViewData
2424
{
25+
private readonly IDictionary<TagValues, MutableAggregation> tagValueAggregationMap = new Dictionary<TagValues, MutableAggregation>();
2526
private ITimestamp start;
26-
private IDictionary<TagValues, MutableAggregation> tagValueAggregationMap = new Dictionary<TagValues, MutableAggregation>();
2727

2828
internal CumulativeMutableViewData(IView view, ITimestamp start)
2929
: base(view)
@@ -59,8 +59,8 @@ internal override IViewData ToViewData(ITimestamp now, StatsCollectionState stat
5959
return ViewData.Create(
6060
this.View,
6161
new Dictionary<TagValues, IAggregationData>(),
62-
ZERO_TIMESTAMP,
63-
ZERO_TIMESTAMP);
62+
ZeroTimestamp,
63+
ZeroTimestamp);
6464
}
6565
}
6666

src/OpenCensus/Impl/Stats/CurrentStatsState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace OpenCensus.Stats
2020

2121
public sealed class CurrentStatsState
2222
{
23-
private StatsCollectionState currentState = StatsCollectionState.ENABLED;
2423
private readonly object lck = new object();
24+
private StatsCollectionState currentState = StatsCollectionState.ENABLED;
2525
private bool isRead;
2626

2727
public StatsCollectionState Value

src/OpenCensus/Impl/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 IList<IMeasurement> measurements = new List<IMeasurement>();
25+
private readonly IList<IMeasurement> measurements = new List<IMeasurement>();
2626

2727
internal static MeasureMapBuilder Builder()
2828
{

src/OpenCensus/Impl/Stats/MeasureToViewMap.cs

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,18 @@ internal sealed class MeasureToViewMap
2727
private readonly object lck = new object();
2828
private readonly IDictionary<string, IList<MutableViewData>> mutableMap = new Dictionary<string, IList<MutableViewData>>();
2929

30-
private IDictionary<IViewName, IView> registeredViews = new Dictionary<IViewName, IView>();
30+
private readonly IDictionary<IViewName, IView> registeredViews = new Dictionary<IViewName, IView>();
3131

3232
// TODO(songya): consider adding a Measure.Name class
33-
private IDictionary<string, IMeasure> registeredMeasures = new Dictionary<string, IMeasure>();
33+
private readonly IDictionary<string, IMeasure> registeredMeasures = new Dictionary<string, IMeasure>();
3434

3535
// Cached set of exported views. It must be set to null whenever a view is registered or
3636
// unregistered.
3737
private volatile ISet<IView> exportedViews;
3838

39-
// Returns the subset of the given views that should be exported
40-
private static ISet<IView> FilterExportedViews(ICollection<IView> allViews)
41-
{
42-
return ImmutableHashSet.CreateRange(allViews);
43-
}
44-
45-
/** Returns a {@link ViewData} corresponding to the given {@link View.Name}. */
46-
internal IViewData GetView(IViewName viewName, IClock clock, StatsCollectionState state)
47-
{
48-
lock (this.lck)
49-
{
50-
MutableViewData view = this.GetMutableViewData(viewName);
51-
return view == null ? null : view.ToViewData(clock.Now, state);
52-
}
53-
}
54-
39+
/// <summary>
40+
/// Gets a {@link ViewData} corresponding to the given {@link View.Name}.
41+
/// </summary>
5542
internal ISet<IView> ExportedViews
5643
{
5744
get
@@ -69,6 +56,15 @@ internal ISet<IView> ExportedViews
6956
}
7057
}
7158

59+
internal IViewData GetView(IViewName viewName, IClock clock, StatsCollectionState state)
60+
{
61+
lock (this.lck)
62+
{
63+
MutableViewData view = this.GetMutableViewData(viewName);
64+
return view?.ToViewData(clock.Now, state);
65+
}
66+
}
67+
7268
/** Enable stats collection for the given {@link View}. */
7369
internal void RegisterView(IView view, IClock clock)
7470
{
@@ -106,50 +102,6 @@ internal void RegisterView(IView view, IClock clock)
106102
}
107103
}
108104

109-
private void AddMutableViewData(string name, MutableViewData mutableViewData)
110-
{
111-
if (this.mutableMap.ContainsKey(name))
112-
{
113-
this.mutableMap[name].Add(mutableViewData);
114-
}
115-
else
116-
{
117-
this.mutableMap.Add(name, new List<MutableViewData>() { mutableViewData });
118-
}
119-
}
120-
121-
private MutableViewData GetMutableViewData(IViewName viewName)
122-
{
123-
lock (this.lck)
124-
{
125-
this.registeredViews.TryGetValue(viewName, out IView view);
126-
if (view == null)
127-
{
128-
return null;
129-
}
130-
131-
this.mutableMap.TryGetValue(view.Measure.Name, out IList<MutableViewData> views);
132-
if (views != null)
133-
{
134-
foreach (MutableViewData viewData in views)
135-
{
136-
if (viewData.View.Name.Equals(viewName))
137-
{
138-
return viewData;
139-
}
140-
}
141-
}
142-
143-
throw new InvalidOperationException(
144-
"Internal error: Not recording stats for view: \""
145-
+ viewName
146-
+ "\" registeredViews="
147-
+ this.registeredViews
148-
+ ", mutableMap="
149-
+ this.mutableMap);
150-
}
151-
}
152-
153105
// Records stats with a set of tags.
154106
internal void Record(ITagContext tags, IList<IMeasurement> stats, ITimestamp timestamp)
155107
{
@@ -217,5 +169,55 @@ internal void ResumeStatsCollection(ITimestamp now)
217169
}
218170
}
219171
}
172+
173+
// Returns the subset of the given views that should be exported.
174+
private static ISet<IView> FilterExportedViews(ICollection<IView> allViews)
175+
{
176+
return ImmutableHashSet.CreateRange(allViews);
177+
}
178+
179+
private void AddMutableViewData(string name, MutableViewData mutableViewData)
180+
{
181+
if (this.mutableMap.ContainsKey(name))
182+
{
183+
this.mutableMap[name].Add(mutableViewData);
184+
}
185+
else
186+
{
187+
this.mutableMap.Add(name, new List<MutableViewData>() { mutableViewData });
188+
}
189+
}
190+
191+
private MutableViewData GetMutableViewData(IViewName viewName)
192+
{
193+
lock (this.lck)
194+
{
195+
this.registeredViews.TryGetValue(viewName, out IView view);
196+
if (view == null)
197+
{
198+
return null;
199+
}
200+
201+
this.mutableMap.TryGetValue(view.Measure.Name, out IList<MutableViewData> views);
202+
if (views != null)
203+
{
204+
foreach (MutableViewData viewData in views)
205+
{
206+
if (viewData.View.Name.Equals(viewName))
207+
{
208+
return viewData;
209+
}
210+
}
211+
}
212+
213+
throw new InvalidOperationException(
214+
"Internal error: Not recording stats for view: \""
215+
+ viewName
216+
+ "\" registeredViews="
217+
+ this.registeredViews
218+
+ ", mutableMap="
219+
+ this.mutableMap);
220+
}
221+
}
220222
}
221223
}

src/OpenCensus/Impl/Stats/MutableCount.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ namespace OpenCensus.Stats
2020

2121
internal sealed class MutableCount : MutableAggregation
2222
{
23-
internal long Count { get; private set; } = 0;
24-
2523
internal MutableCount()
2624
{
2725
}
2826

27+
internal long Count { get; private set; } = 0;
28+
2929
internal static MutableCount Create()
3030
{
3131
return new MutableCount();

src/OpenCensus/Impl/Stats/MutableViewData.cs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ namespace OpenCensus.Stats
2424

2525
internal abstract class MutableViewData
2626
{
27-
private const long MILLIS_PER_SECOND = 1000L;
28-
private const long NANOS_PER_MILLI = 1000 * 1000;
27+
internal static readonly ITagValue UnknownTagValue = null;
28+
29+
internal static readonly ITimestamp ZeroTimestamp = Timestamp.Create(0, 0);
30+
31+
private const long MillisPerSecond = 1000L;
32+
private const long NanosPerMilli = 1000 * 1000;
33+
34+
protected MutableViewData(IView view)
35+
{
36+
this.View = view;
37+
}
38+
39+
internal IView View { get; }
2940

3041
private static Func<ISum, MutableAggregation> CreateMutableSum { get; } = (s) => { return MutableSum.Create(); };
3142

@@ -60,46 +71,10 @@ internal abstract class MutableViewData
6071
boxedBucketCounts);
6172
};
6273

63-
internal static readonly ITagValue UNKNOWN_TAG_VALUE = null;
64-
65-
internal static readonly ITimestamp ZERO_TIMESTAMP = Timestamp.Create(0, 0);
66-
67-
internal IView View { get; }
68-
69-
protected MutableViewData(IView view)
70-
{
71-
this.View = view;
72-
}
73-
74-
internal static MutableViewData Create(IView view, ITimestamp start)
75-
{
76-
return new CumulativeMutableViewData(view, start);
77-
}
78-
79-
/** Record double stats with the given tags. */
80-
internal abstract void Record(ITagContext context, double value, ITimestamp timestamp);
81-
82-
/** Record long stats with the given tags. */
83-
internal void Record(ITagContext tags, long value, ITimestamp timestamp)
84-
{
85-
// TODO(songya): shall we check for precision loss here?
86-
this.Record(tags, (double)value, timestamp);
87-
}
88-
89-
/** Convert this {@link MutableViewData} to {@link ViewData}. */
90-
internal abstract IViewData ToViewData(ITimestamp now, StatsCollectionState state);
91-
92-
// Clear recorded stats.
93-
internal abstract void ClearStats();
94-
95-
// Resume stats collection, and reset Start Timestamp (for CumulativeMutableViewData), or refresh
96-
// bucket list (for InternalMutableViewData).
97-
internal abstract void ResumeStatsCollection(ITimestamp now);
98-
9974
internal static IDictionary<ITagKey, ITagValue> GetTagMap(ITagContext ctx)
10075
{
10176
if (ctx is TagContext)
102-
{
77+
{
10378
return ((TagContext)ctx).Tags;
10479
}
10580
else
@@ -126,7 +101,7 @@ internal static IList<ITagValue> GetTagValues(IDictionary<ITagKey, ITagValue> ta
126101
if (!tags.ContainsKey(tagKey))
127102
{
128103
// replace not found key values by null.
129-
tagValues.Add(UNKNOWN_TAG_VALUE);
104+
tagValues.Add(UnknownTagValue);
130105
}
131106
else
132107
{
@@ -140,7 +115,7 @@ internal static IList<ITagValue> GetTagValues(IDictionary<ITagKey, ITagValue> ta
140115
// Returns the milliseconds representation of a Duration.
141116
internal static long ToMillis(IDuration duration)
142117
{
143-
return (duration.Seconds * MILLIS_PER_SECOND) + (duration.Nanos / NANOS_PER_MILLI);
118+
return (duration.Seconds * MillisPerSecond) + (duration.Nanos / NanosPerMilli);
144119
}
145120

146121
internal static MutableAggregation CreateMutableAggregation(IAggregation aggregation)
@@ -172,7 +147,7 @@ internal static IAggregationData CreateAggregationData(MutableAggregation aggreg
172147
{
173148
throw new ArgumentException();
174149
});
175-
},
150+
},
176151
CreateCountData,
177152
CreateMeanData,
178153
CreateDistributionData,
@@ -210,5 +185,30 @@ internal static IDictionary<TagValues, IAggregationData> CreateAggregationMap(ID
210185

211186
return map;
212187
}
188+
189+
internal static MutableViewData Create(IView view, ITimestamp start)
190+
{
191+
return new CumulativeMutableViewData(view, start);
192+
}
193+
194+
/** Record double stats with the given tags. */
195+
internal abstract void Record(ITagContext context, double value, ITimestamp timestamp);
196+
197+
/** Record long stats with the given tags. */
198+
internal void Record(ITagContext tags, long value, ITimestamp timestamp)
199+
{
200+
// TODO(songya): shall we check for precision loss here?
201+
this.Record(tags, (double)value, timestamp);
202+
}
203+
204+
/** Convert this {@link MutableViewData} to {@link ViewData}. */
205+
internal abstract IViewData ToViewData(ITimestamp now, StatsCollectionState state);
206+
207+
// Clear recorded stats.
208+
internal abstract void ClearStats();
209+
210+
// Resume stats collection, and reset Start Timestamp (for CumulativeMutableViewData), or refresh
211+
// bucket list (for InternalMutableViewData).
212+
internal abstract void ResumeStatsCollection(ITimestamp now);
213213
}
214214
}

src/OpenCensus/Impl/Stats/ViewName.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ namespace OpenCensus.Stats
2121

2222
public sealed class ViewName : IViewName
2323
{
24-
internal const int NAME_MAX_LENGTH = 255;
25-
26-
public string AsString { get; }
24+
internal const int NameMaxLength = 255;
2725

2826
internal ViewName(string asString)
2927
{
3028
this.AsString = asString ?? throw new ArgumentNullException(nameof(asString));
3129
}
3230

31+
public string AsString { get; }
32+
3333
public static IViewName Create(string name)
3434
{
3535
if (name == null)
3636
{
3737
throw new ArgumentNullException(nameof(name));
3838
}
3939

40-
if (!(StringUtil.IsPrintableString(name) && name.Length <= NAME_MAX_LENGTH))
40+
if (!(StringUtil.IsPrintableString(name) && name.Length <= NameMaxLength))
4141
{
4242
throw new ArgumentOutOfRangeException(
4343
"Name should be a ASCII string with a length no greater than "
44-
+ NAME_MAX_LENGTH
44+
+ NameMaxLength
4545
+ " characters.");
4646
}
4747

src/OpenCensus/Impl/Tags/CurrentTaggingState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace OpenCensus.Tags
2020

2121
public sealed class CurrentTaggingState
2222
{
23-
private TaggingState currentState = TaggingState.ENABLED;
2423
private readonly object lck = new object();
24+
private TaggingState currentState = TaggingState.ENABLED;
2525
private bool isRead;
2626

2727
public TaggingState Value

0 commit comments

Comments
 (0)