Skip to content

Commit 64e65af

Browse files
committed
hide a few functions that do not need to be part of the public API
1 parent c3769c5 commit 64e65af

File tree

5 files changed

+51
-59
lines changed

5 files changed

+51
-59
lines changed

senders/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (sender *wavefrontSender) Start() {
7575
}
7676

7777
func (sender *wavefrontSender) SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error {
78-
line, err := MetricLine(name, value, ts, source, tags, sender.defaultSource)
78+
line, err := metricLine(name, value, ts, source, tags, sender.defaultSource)
7979
if err != nil {
8080
sender.pointsInvalid.Inc()
8181
return err
@@ -105,7 +105,7 @@ func (sender *wavefrontSender) SendDeltaCounter(name string, value float64, sour
105105

106106
func (sender *wavefrontSender) SendDistribution(name string, centroids []histogram.Centroid,
107107
hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string) error {
108-
line, err := HistoLine(name, centroids, hgs, ts, source, tags, sender.defaultSource)
108+
line, err := histogramLine(name, centroids, hgs, ts, source, tags, sender.defaultSource)
109109
if err != nil {
110110
sender.histogramsInvalid.Inc()
111111
return err
@@ -121,7 +121,7 @@ func (sender *wavefrontSender) SendDistribution(name string, centroids []histogr
121121

122122
func (sender *wavefrontSender) SendSpan(name string, startMillis, durationMillis int64, source, traceId, spanId string,
123123
parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error {
124-
line, err := SpanLine(name, startMillis, durationMillis, source, traceId, spanId, parents, followsFrom, tags, spanLogs, sender.defaultSource)
124+
line, err := spanLine(name, startMillis, durationMillis, source, traceId, spanId, parents, followsFrom, tags, spanLogs, sender.defaultSource)
125125
if err != nil {
126126
sender.spansInvalid.Inc()
127127
return err
@@ -135,7 +135,7 @@ func (sender *wavefrontSender) SendSpan(name string, startMillis, durationMillis
135135
}
136136

137137
if len(spanLogs) > 0 {
138-
logs, err := SpanLogJSON(traceId, spanId, spanLogs, line)
138+
logs, err := spanLogJSON(traceId, spanId, spanLogs, line)
139139
if err != nil {
140140
sender.spanLogsInvalid.Inc()
141141
return err
@@ -155,9 +155,9 @@ func (sender *wavefrontSender) SendEvent(name string, startMillis, endMillis int
155155
var line string
156156
var err error
157157
if sender.proxy {
158-
line, err = EventLine(name, startMillis, endMillis, source, tags, setters...)
158+
line, err = eventLine(name, startMillis, endMillis, source, tags, setters...)
159159
} else {
160-
line, err = EventLineJSON(name, startMillis, endMillis, source, tags, setters...)
160+
line, err = eventLineJSON(name, startMillis, endMillis, source, tags, setters...)
161161
}
162162
if err != nil {
163163
sender.eventsInvalid.Inc()

senders/direct.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (sender *directSender) Start() {
132132
}
133133

134134
func (sender *directSender) SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error {
135-
line, err := MetricLine(name, value, ts, source, tags, sender.defaultSource)
135+
line, err := metricLine(name, value, ts, source, tags, sender.defaultSource)
136136
if err != nil {
137137
sender.pointsInvalid.Inc()
138138
return err
@@ -162,7 +162,7 @@ func (sender *directSender) SendDeltaCounter(name string, value float64, source
162162

163163
func (sender *directSender) SendDistribution(name string, centroids []histogram.Centroid,
164164
hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string) error {
165-
line, err := HistoLine(name, centroids, hgs, ts, source, tags, sender.defaultSource)
165+
line, err := histogramLine(name, centroids, hgs, ts, source, tags, sender.defaultSource)
166166
if err != nil {
167167
sender.histogramsInvalid.Inc()
168168
return err
@@ -178,7 +178,7 @@ func (sender *directSender) SendDistribution(name string, centroids []histogram.
178178

179179
func (sender *directSender) SendSpan(name string, startMillis, durationMillis int64, source, traceId, spanId string,
180180
parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error {
181-
line, err := SpanLine(name, startMillis, durationMillis, source, traceId, spanId, parents, followsFrom, tags, spanLogs, sender.defaultSource)
181+
line, err := spanLine(name, startMillis, durationMillis, source, traceId, spanId, parents, followsFrom, tags, spanLogs, sender.defaultSource)
182182
if err != nil {
183183
sender.spansInvalid.Inc()
184184
return err
@@ -192,7 +192,7 @@ func (sender *directSender) SendSpan(name string, startMillis, durationMillis in
192192
}
193193

194194
if len(spanLogs) > 0 {
195-
logs, err := SpanLogJSON(traceId, spanId, spanLogs, line)
195+
logs, err := spanLogJSON(traceId, spanId, spanLogs, line)
196196
if err != nil {
197197
sender.spanLogsInvalid.Inc()
198198
return err
@@ -209,7 +209,7 @@ func (sender *directSender) SendSpan(name string, startMillis, durationMillis in
209209
}
210210

211211
func (sender *directSender) SendEvent(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) error {
212-
line, err := EventLineJSON(name, startMillis, endMillis, source, tags, setters...)
212+
line, err := eventLineJSON(name, startMillis, endMillis, source, tags, setters...)
213213
if err != nil {
214214
sender.eventsInvalid.Inc()
215215
return err

senders/formatter.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ import (
1717
var /* const */ quotation = regexp.MustCompile("\"")
1818
var /* const */ lineBreak = regexp.MustCompile("\\n")
1919

20-
// MetricLine is for internal use only.
21-
//
2220
// Gets a metric line in the Wavefront metrics data format:
2321
// <metricName> <metricValue> [<timestamp>] source=<source> [pointTags]
2422
// Example: "new-york.power.usage 42422.0 1533531013 source=localhost datacenter=dc1"
25-
func MetricLine(name string, value float64, ts int64, source string, tags map[string]string, defaultSource string) (string, error) {
23+
func metricLine(name string, value float64, ts int64, source string, tags map[string]string, defaultSource string) (string, error) {
2624
if name == "" {
2725
return "", errors.New("empty metric name")
2826
}
@@ -59,12 +57,10 @@ func MetricLine(name string, value float64, ts int64, source string, tags map[st
5957
return sb.String(), nil
6058
}
6159

62-
// HistoLine is for internal use only.
63-
//
6460
// Gets a histogram line in the Wavefront histogram data format:
6561
// {!M | !H | !D} [<timestamp>] #<count> <mean> [centroids] <histogramName> source=<source> [pointTags]
6662
// Example: "!M 1533531013 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"
67-
func HistoLine(name string, centroids histogram.Centroids, hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string, defaultSource string) (string, error) {
63+
func histogramLine(name string, centroids histogram.Centroids, hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string, defaultSource string) (string, error) {
6864
if name == "" {
6965
return "", errors.New("empty distribution name")
7066
}
@@ -122,14 +118,13 @@ func HistoLine(name string, centroids histogram.Centroids, hgs map[histogram.Gra
122118
return sbg.String(), nil
123119
}
124120

125-
// SpanLine is for internal use only.
126-
//
127121
// Gets a span line in the Wavefront span data format:
128122
// <tracingSpanName> source=<source> [pointTags] <start_millis> <duration_milli_seconds>
129123
// Example:
130124
// "getAllUsers source=localhost traceId=7b3bf470-9456-11e8-9eb6-529269fb1459 spanId=0313bafe-9457-11e8-9eb6-529269fb1459
131-
// parent=2f64e538-9457-11e8-9eb6-529269fb1459 application=Wavefront http.method=GET 1533531013 343500"
132-
func SpanLine(name string, startMillis, durationMillis int64, source, traceId, spanId string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog, defaultSource string) (string, error) {
125+
//
126+
// parent=2f64e538-9457-11e8-9eb6-529269fb1459 application=Wavefront http.method=GET 1533531013 343500"
127+
func spanLine(name string, startMillis, durationMillis int64, source, traceId, spanId string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog, defaultSource string) (string, error) {
133128
if name == "" {
134129
return "", errors.New("span name cannot be empty")
135130
}
@@ -194,8 +189,7 @@ func SpanLine(name string, startMillis, durationMillis int64, source, traceId, s
194189
return sb.String(), nil
195190
}
196191

197-
// SpanLogJSON is for internal use only.
198-
func SpanLogJSON(traceId, spanId string, spanLogs []SpanLog, span string) (string, error) {
192+
func spanLogJSON(traceId, spanId string, spanLogs []SpanLog, span string) (string, error) {
199193
l := SpanLogs{
200194
TraceId: traceId,
201195
SpanId: spanId,
@@ -209,11 +203,9 @@ func SpanLogJSON(traceId, spanId string, spanLogs []SpanLog, span string) (strin
209203
return string(out[:]) + "\n", nil
210204
}
211205

212-
// EventLine is for internal use only.
213-
//
214-
// EventLine encode the event to a wf proxy format
206+
// eventLine encode the event to a wf proxy format
215207
// set endMillis to 0 for a 'Instantaneous' event
216-
func EventLine(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) (string, error) {
208+
func eventLine(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) (string, error) {
217209
sb := internal.GetBuffer()
218210
defer internal.PutBuffer(sb)
219211

@@ -258,8 +250,8 @@ func EventLine(name string, startMillis, endMillis int64, source string, tags ma
258250
return sb.String(), nil
259251
}
260252

261-
// EventLineJSON is for internal use only.
262-
func EventLineJSON(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) (string, error) {
253+
// eventLineJSON encodes the event to a wf API format
254+
func eventLineJSON(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) (string, error) {
263255
annotations := map[string]string{}
264256
l := map[string]interface{}{
265257
"name": name,
@@ -329,7 +321,7 @@ func isUUIDFormat(str string) bool {
329321
return true
330322
}
331323

332-
//Sanitize string of metric name, source and key of tags according to the rule of Wavefront proxy.
324+
// Sanitize string of metric name, source and key of tags according to the rule of Wavefront proxy.
333325
func sanitizeInternal(str string) string {
334326
sb := internal.GetBuffer()
335327
defer internal.PutBuffer(sb)
@@ -378,7 +370,7 @@ func sanitizeInternal(str string) string {
378370
return sb.String()
379371
}
380372

381-
//Sanitize string of tags value, etc.
373+
// Sanitize string of tags value, etc.
382374
func sanitizeValue(str string) string {
383375
res := strings.TrimSpace(str)
384376
if strings.Contains(str, "\"") || strings.Contains(str, "'") {

senders/formatter_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,32 @@ func BenchmarkMetricLine(b *testing.B) {
4848

4949
var r string
5050
for n := 0; n < b.N; n++ {
51-
r, _ = MetricLine(name, value, ts, src, tags, "")
51+
r, _ = metricLine(name, value, ts, src, tags, "")
5252
}
5353
line = r
5454
}
5555

5656
func TestMetricLine(t *testing.T) {
57-
line, err := MetricLine("foo.metric", 1.2, 1533529977, "test_source",
57+
line, err := metricLine("foo.metric", 1.2, 1533529977, "test_source",
5858
map[string]string{"env": "test"}, "")
5959
expected := "\"foo.metric\" 1.2 1533529977 source=\"test_source\" \"env\"=\"test\"\n"
6060
assert.Nil(t, err)
6161
assert.Equal(t, expected, line)
6262

63-
line, err = MetricLine("foo.metric", 1.2, 1533529977, "",
63+
line, err = metricLine("foo.metric", 1.2, 1533529977, "",
6464
map[string]string{"env": "test"}, "default")
6565
expected = "\"foo.metric\" 1.2 1533529977 source=\"default\" \"env\"=\"test\"\n"
6666
assert.Nil(t, err)
6767
assert.Equal(t, expected, line)
6868

69-
line, err = MetricLine("foo.metric", 1.2, 1533529977, "1.2.3.4:8080",
69+
line, err = metricLine("foo.metric", 1.2, 1533529977, "1.2.3.4:8080",
7070
map[string]string{"env": "test"}, "default")
7171
expected = "\"foo.metric\" 1.2 1533529977 source=\"1.2.3.4:8080\" \"env\"=\"test\"\n"
7272
assert.Nil(t, err)
7373
assert.Equal(t, expected, line)
7474
}
7575

76-
func BenchmarkHistoLine(b *testing.B) {
76+
func BenchmarkHistogramLine(b *testing.B) {
7777
name := "request.latency"
7878
centroids := makeCentroids()
7979
hgs := map[histogram.Granularity]bool{histogram.MINUTE: true}
@@ -83,12 +83,12 @@ func BenchmarkHistoLine(b *testing.B) {
8383

8484
var r string
8585
for n := 0; n < b.N; n++ {
86-
r, _ = HistoLine(name, centroids, hgs, ts, src, tags, "")
86+
r, _ = histogramLine(name, centroids, hgs, ts, src, tags, "")
8787
}
8888
line = r
8989
}
9090

91-
func TestHistoLineCentroidsFormat(t *testing.T) {
91+
func TestHistogramLineCentroidsFormat(t *testing.T) {
9292
centroids := histogram.Centroids{
9393
{Value: 30.0, Count: 20},
9494
{Value: 5.1, Count: 10},
@@ -97,7 +97,7 @@ func TestHistoLineCentroidsFormat(t *testing.T) {
9797
{Value: 30.0, Count: 20},
9898
}
9999

100-
line, err := HistoLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
100+
line, err := histogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
101101
1533529977, "test_source", map[string]string{"env": "test"}, "")
102102

103103
assert.Nil(t, err)
@@ -117,34 +117,34 @@ func TestHistoLineCentroidsFormat(t *testing.T) {
117117
}
118118
}
119119

120-
func TestHistoLine(t *testing.T) {
120+
func TestHistogramLine(t *testing.T) {
121121
centroids := makeCentroids()
122122

123-
line, err := HistoLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
123+
line, err := histogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
124124
1533529977, "test_source", map[string]string{"env": "test"}, "")
125125
expected := "!M 1533529977 #20 30 \"request.latency\" source=\"test_source\" \"env\"=\"test\"\n"
126126
assert.Nil(t, err)
127127
assert.Equal(t, expected, line)
128128

129-
line, err = HistoLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: false},
129+
line, err = histogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: false},
130130
1533529977, "", map[string]string{"env": "test"}, "default")
131131
expected = "!M 1533529977 #20 30 \"request.latency\" source=\"default\" \"env\"=\"test\"\n"
132132
assert.Nil(t, err)
133133
assert.Equal(t, expected, line)
134134

135-
line, err = HistoLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.HOUR: true, histogram.MINUTE: false},
135+
line, err = histogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.HOUR: true, histogram.MINUTE: false},
136136
1533529977, "", map[string]string{"env": "test"}, "default")
137137
expected = "!H 1533529977 #20 30 \"request.latency\" source=\"default\" \"env\"=\"test\"\n"
138138
assert.Nil(t, err)
139139
assert.Equal(t, expected, line)
140140

141-
line, err = HistoLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.DAY: true},
141+
line, err = histogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.DAY: true},
142142
1533529977, "", map[string]string{"env": "test"}, "default")
143143
expected = "!D 1533529977 #20 30 \"request.latency\" source=\"default\" \"env\"=\"test\"\n"
144144
assert.Nil(t, err)
145145
assert.Equal(t, expected, line)
146146

147-
line, err = HistoLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: true, histogram.DAY: false},
147+
line, err = histogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: true, histogram.DAY: false},
148148
1533529977, "test_source", map[string]string{"env": "test"}, "")
149149
expected = "!M 1533529977 #20 30 \"request.latency\" source=\"test_source\" \"env\"=\"test\"\n" +
150150
"!H 1533529977 #20 30 \"request.latency\" source=\"test_source\" \"env\"=\"test\"\n"
@@ -162,29 +162,29 @@ func BenchmarkSpanLine(b *testing.B) {
162162

163163
var r string
164164
for n := 0; n < b.N; n++ {
165-
r, _ = SpanLine(name, start, dur, src, traceId, traceId, []string{traceId}, nil, nil, nil, "")
165+
r, _ = spanLine(name, start, dur, src, traceId, traceId, []string{traceId}, nil, nil, nil, "")
166166
}
167167
line = r
168168
}
169169

170170
func TestSpanLine(t *testing.T) {
171-
line, err := SpanLine("order.shirts", 1533531013, 343500, "test_source",
171+
line, err := spanLine("order.shirts", 1533531013, 343500, "test_source",
172172
"7b3bf470-9456-11e8-9eb6-529269fb1459", "7b3bf470-9456-11e8-9eb6-529269fb1459",
173173
[]string{"7b3bf470-9456-11e8-9eb6-529269fb1458"}, nil, nil, nil, "")
174174
expected := "\"order.shirts\" source=\"test_source\" traceId=7b3bf470-9456-11e8-9eb6-529269fb1459" +
175175
" spanId=7b3bf470-9456-11e8-9eb6-529269fb1459 parent=7b3bf470-9456-11e8-9eb6-529269fb1458 1533531013 343500\n"
176176
assert.Nil(t, err)
177177
assert.Equal(t, expected, line)
178178

179-
line, err = SpanLine("order.shirts", 1533531013, 343500, "test_source",
179+
line, err = spanLine("order.shirts", 1533531013, 343500, "test_source",
180180
"7b3bf470-9456-11e8-9eb6-529269fb1459", "7b3bf470-9456-11e8-9eb6-529269fb1459", nil,
181181
[]string{"7b3bf470-9456-11e8-9eb6-529269fb1458"}, []SpanTag{{Key: "env", Value: "test"}}, nil, "")
182182
expected = "\"order.shirts\" source=\"test_source\" traceId=7b3bf470-9456-11e8-9eb6-529269fb1459" +
183183
" spanId=7b3bf470-9456-11e8-9eb6-529269fb1459 followsFrom=7b3bf470-9456-11e8-9eb6-529269fb1458 \"env\"=\"test\" 1533531013 343500\n"
184184
assert.Nil(t, err)
185185
assert.Equal(t, expected, line)
186186

187-
line, err = SpanLine("order.shirts", 1533531013, 343500, "test_source",
187+
line, err = spanLine("order.shirts", 1533531013, 343500, "test_source",
188188
"7b3bf470-9456-11e8-9eb6-529269fb1459", "7b3bf470-9456-11e8-9eb6-529269fb1459", nil,
189189
[]string{"7b3bf470-9456-11e8-9eb6-529269fb1458"},
190190
[]SpanTag{{Key: "env", Value: "test"}, {Key: "env", Value: "dev"}}, nil, "")
@@ -197,24 +197,24 @@ func TestSpanLine(t *testing.T) {
197197
func TestSpanLineErrors(t *testing.T) {
198198
uuid := "00000000-0000-0000-0000-000000000000"
199199

200-
_, err := SpanLine("", 0, 0, "", uuid, uuid, nil, nil, nil, nil, "")
200+
_, err := spanLine("", 0, 0, "", uuid, uuid, nil, nil, nil, nil, "")
201201
require.Error(t, err)
202202
assert.Equal(t, "span name cannot be empty", err.Error())
203203

204-
_, err = SpanLine("a_name", 0, 0, "00-00", "x", uuid, nil, nil, nil, nil, "")
204+
_, err = spanLine("a_name", 0, 0, "00-00", "x", uuid, nil, nil, nil, nil, "")
205205
require.Error(t, err)
206206
assert.Equal(t, "traceId is not in UUID format: span=a_name traceId=x", err.Error())
207207

208-
_, err = SpanLine("a_name", 0, 0, "00-00", uuid, "x", nil, nil, nil, nil, "")
208+
_, err = spanLine("a_name", 0, 0, "00-00", uuid, "x", nil, nil, nil, nil, "")
209209
require.Error(t, err)
210210
assert.Equal(t, "spanId is not in UUID format: span=a_name spanId=x", err.Error())
211211

212-
_, err = SpanLine("a_name", 0, 0, "a_source", uuid, uuid, nil, nil,
212+
_, err = spanLine("a_name", 0, 0, "a_source", uuid, uuid, nil, nil,
213213
[]SpanTag{{Key: "", Value: ""}}, nil, "")
214214
require.Error(t, err)
215215
assert.Equal(t, "tag keys cannot be empty: span=a_name", err.Error())
216216

217-
_, err = SpanLine("a_name", 0, 0, "a_source", uuid, uuid, nil, nil,
217+
_, err = spanLine("a_name", 0, 0, "a_source", uuid, uuid, nil, nil,
218218
[]SpanTag{{Key: "a_tag", Value: ""}}, nil, "")
219219
require.Error(t, err)
220220
assert.Equal(t, "tag values cannot be empty: span=a_name tag=a_tag", err.Error())

0 commit comments

Comments
 (0)