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

Commit 3da91ae

Browse files
bvwellsrghetia
authored andcommitted
Simplify use of time package (#1167)
1 parent ce85b6d commit 3da91ae

9 files changed

Lines changed: 10 additions & 10 deletions

File tree

examples/derived_gauges/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func doWork() {
295295
func main() {
296296
// Using logexporter but you can choose any supported exporter.
297297
exporter, err := exporter.NewLogExporter(exporter.Options{
298-
ReportingInterval: time.Duration(10 * time.Second),
298+
ReportingInterval: 10 * time.Second,
299299
MetricsLogFile: metricsLogFile,
300300
})
301301
if err != nil {

examples/derived_gauges/derived_gauge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func doWork() {
172172
func main() {
173173
// Using logexporter but you can choose any supported exporter.
174174
exporter, err := exporter.NewLogExporter(exporter.Options{
175-
ReportingInterval: time.Duration(10 * time.Second),
175+
ReportingInterval: 10 * time.Second,
176176
MetricsLogFile: metricsLogFile,
177177
})
178178
if err != nil {

examples/gauges/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func work() {
253253
func main() {
254254
// Using log exporter to export metrics but you can choose any supported exporter.
255255
exporter, err := exporter.NewLogExporter(exporter.Options{
256-
ReportingInterval: time.Duration(10 * time.Second),
256+
ReportingInterval: 10 * time.Second,
257257
MetricsLogFile: metricsLogFile,
258258
})
259259
if err != nil {

examples/gauges/gauge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func work() {
148148
func main() {
149149
// Using log exporter to export metrics but you can choose any supported exporter.
150150
exporter, err := exporter.NewLogExporter(exporter.Options{
151-
ReportingInterval: time.Duration(10 * time.Second),
151+
ReportingInterval: 10 * time.Second,
152152
MetricsLogFile: metricsLogFile,
153153
})
154154
if err != nil {

examples/helloworld/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func main() {
4444

4545
// Register an exporter to be able to retrieve
4646
// the data from the subscribed views.
47-
e, err := exporter.NewLogExporter(exporter.Options{ReportingInterval: time.Duration(time.Second)})
47+
e, err := exporter.NewLogExporter(exporter.Options{ReportingInterval: time.Second})
4848
if err != nil {
4949
log.Fatal(err)
5050
}

examples/http/helloworld_server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func main() {
4343

4444
// Using log exporter to export metrics but you can choose any supported exporter.
4545
exporter, err := exporter.NewLogExporter(exporter.Options{
46-
ReportingInterval: time.Duration(10 * time.Second),
46+
ReportingInterval: 10 * time.Second,
4747
MetricsLogFile: metricsLogFile,
4848
TracesLogFile: tracesLogFile,
4949
})

examples/quickstart/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func main() {
100100

101101
// Using log exporter here to export metrics but you can choose any supported exporter.
102102
exporter, err := exporter.NewLogExporter(exporter.Options{
103-
ReportingInterval: time.Duration(10 * time.Second),
103+
ReportingInterval: 10 * time.Second,
104104
MetricsLogFile: metricsLogFile,
105105
})
106106
if err != nil {

plugin/ochttp/trace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func serveHTTP(handler *Handler, done chan struct{}, wait chan time.Time, status
353353
// Simulate a slow-responding server.
354354
sleepUntil := <-wait
355355
for time.Now().Before(sleepUntil) {
356-
time.Sleep(sleepUntil.Sub(time.Now()))
356+
time.Sleep(time.Until(sleepUntil))
357357
}
358358

359359
io.WriteString(w, "expected-response")

stats/view/view_to_metric_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func initMetricDescriptors() {
252252
}
253253

254254
func Test_ViewToMetric(t *testing.T) {
255-
startTime := time.Now().Add(-time.Duration(60 * time.Second))
255+
startTime := time.Now().Add(-60 * time.Second)
256256
now := time.Now()
257257
tests := []*testToMetrics{
258258
{
@@ -460,7 +460,7 @@ func Test_ViewToMetric(t *testing.T) {
460460
// Test to verify that a metric converted from a view with Aggregation Count should always
461461
// have Dimensionless unit.
462462
func TestUnitConversionForAggCount(t *testing.T) {
463-
startTime := time.Now().Add(-time.Duration(60 * time.Second))
463+
startTime := time.Now().Add(-60 * time.Second)
464464
now := time.Now()
465465
tests := []*struct {
466466
name string

0 commit comments

Comments
 (0)