Skip to content

Commit ec3abd5

Browse files
feat: add os/arch tag
1 parent cae471a commit ec3abd5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

internal/metrics/metrics.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ import (
44
"fmt"
55

66
"contrib.go.opencensus.io/exporter/stackdriver"
7-
87
"github.com/go-semantic-release/plugin-registry/internal/config"
98
"go.opencensus.io/stats"
109
"go.opencensus.io/stats/view"
10+
"go.opencensus.io/tag"
1111
)
1212

1313
var (
1414
CounterSemRelDownloads = stats.Int64("semrel_downloads", "Number of semantic-release downloads", "1")
1515
CounterCacheHit = stats.Int64("cache_hits", "Number of cache hits", "1")
1616
CounterCacheMiss = stats.Int64("cache_misses", "Number of cache misses", "1")
17+
18+
TagOSArch = tag.MustNewKey("os_arch")
1719
)
1820

1921
var views = []*view.View{
2022
{
2123
Name: "semrel_downloads",
2224
Measure: CounterSemRelDownloads,
2325
Description: "Number of semantic-release downloads",
26+
TagKeys: []tag.Key{TagOSArch},
2427
Aggregation: view.Count(),
2528
},
2629
{

internal/server/handler_download.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/go-semantic-release/plugin-registry/internal/metrics"
1212
"github.com/google/go-github/v50/github"
1313
"go.opencensus.io/stats"
14+
"go.opencensus.io/tag"
1415
)
1516

1617
func (s *Server) getLatestSemRelRelease(ctx context.Context) (*github.RepositoryRelease, error) {
@@ -51,7 +52,11 @@ func (s *Server) downloadLatestSemRelBinary(w http.ResponseWriter, r *http.Reque
5152
osArchIdentifier := strings.ToLower(fmt.Sprintf("%s_%s", os, arch))
5253
for _, asset := range latestRelease.Assets {
5354
if strings.Contains(asset.GetName(), osArchIdentifier) {
54-
stats.Record(r.Context(), metrics.CounterSemRelDownloads.M(1))
55+
ctx, err := tag.New(r.Context(), tag.Upsert(metrics.TagOSArch, osArchIdentifier))
56+
if err != nil {
57+
s.log.Errorf("could not create context with tag: %v", err)
58+
}
59+
stats.Record(ctx, metrics.CounterSemRelDownloads.M(1))
5560
http.Redirect(w, r, asset.GetBrowserDownloadURL(), http.StatusFound)
5661
return
5762
}

0 commit comments

Comments
 (0)