golang.org/x/playground@v0.0.0-20230418134305-14ebe15bcd59/metrics.go (about) 1 // Copyright 2021 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "go.opencensus.io/stats" 9 "go.opencensus.io/stats/view" 10 "go.opencensus.io/tag" 11 ) 12 13 var ( 14 BuildLatencyDistribution = view.Distribution(1, 5, 10, 15, 20, 25, 50, 75, 100, 125, 150, 200, 250, 300, 400, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 20000, 30000) 15 kGoBuildSuccess = tag.MustNewKey("go-playground/frontend/go_build_success") 16 kGoRunSuccess = tag.MustNewKey("go-playground/frontend/go_run_success") 17 kGoVetSuccess = tag.MustNewKey("go-playground/frontend/go_vet_success") 18 mGoBuildLatency = stats.Float64("go-playground/frontend/go_build_latency", "", stats.UnitMilliseconds) 19 mGoRunLatency = stats.Float64("go-playground/frontend/go_run_latency", "", stats.UnitMilliseconds) 20 mGoVetLatency = stats.Float64("go-playground/frontend/go_vet_latency", "", stats.UnitMilliseconds) 21 22 goBuildCount = &view.View{ 23 Name: "go-playground/frontend/go_build_count", 24 Description: "Number of snippets built", 25 Measure: mGoBuildLatency, 26 TagKeys: []tag.Key{kGoBuildSuccess}, 27 Aggregation: view.Count(), 28 } 29 goBuildLatency = &view.View{ 30 Name: "go-playground/frontend/go_build_latency", 31 Description: "Latency distribution of building snippets", 32 Measure: mGoBuildLatency, 33 Aggregation: BuildLatencyDistribution, 34 } 35 goRunCount = &view.View{ 36 Name: "go-playground/frontend/go_run_count", 37 Description: "Number of snippets run", 38 Measure: mGoRunLatency, 39 TagKeys: []tag.Key{kGoRunSuccess}, 40 Aggregation: view.Count(), 41 } 42 goRunLatency = &view.View{ 43 Name: "go-playground/frontend/go_run_latency", 44 Description: "Latency distribution of running snippets", 45 Measure: mGoRunLatency, 46 Aggregation: BuildLatencyDistribution, 47 } 48 goVetCount = &view.View{ 49 Name: "go-playground/frontend/go_vet_count", 50 Description: "Number of vet runs", 51 Measure: mGoVetLatency, 52 TagKeys: []tag.Key{kGoVetSuccess}, 53 Aggregation: view.Count(), 54 } 55 goVetLatency = &view.View{ 56 Name: "go-playground/sandbox/go_vet_latency", 57 Description: "Latency distribution of vet runs", 58 Measure: mGoVetLatency, 59 Aggregation: BuildLatencyDistribution, 60 } 61 ) 62 63 // views should contain all measurements. All *view.View added to this 64 // slice will be registered and exported to the metric service. 65 var views = []*view.View{ 66 goBuildCount, 67 goBuildLatency, 68 goRunCount, 69 goRunLatency, 70 goVetCount, 71 goVetLatency, 72 }