-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
158 lines (137 loc) · 3 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package k6registry
import "strings"
// CalculateMetrics calculates registry metrics.
func CalculateMetrics(reg Registry) *Metrics {
const k6Module = "go.k6.io/k6"
m := new(Metrics)
for _, ext := range reg {
if ext.Module == k6Module {
continue
}
m.RegistryExtensionCount++
m.tier(ext.Tier)
if ext.Compliance != nil {
m.grade(ext.Compliance.Grade)
}
for _, prod := range ext.Products {
m.product(prod)
}
if len(ext.Products) == 0 {
m.RegistryProductOSSCount++
}
if len(ext.Imports) > 0 {
m.RegistryTypeJavaScriptCount++
}
if len(ext.Outputs) > 0 {
m.RegistryTypeOutputCount++
}
if strings.HasPrefix(ext.Module, "github.com/grafana/") && ext.Tier != TierOfficial {
m.RegistryTierUnofficialCount++
}
for _, cat := range ext.Categories {
m.category(cat)
}
if len(ext.Categories) == 0 {
m.RegistryCategoryMiscCount++
}
for _, issue := range ext.Compliance.Issues {
m.issue(issue)
}
if ext.Cgo {
m.RegistryCgoCount++
}
}
return m
}
func (m *Metrics) tier(tier Tier) {
switch tier {
case TierOfficial:
m.RegistryTierOfficialCount++
case TierPartner:
m.RegistryTierPartnerCount++
case TierCommunity:
fallthrough
default:
m.RegistryTierCommunityCount++
}
}
func (m *Metrics) grade(grade Grade) {
switch grade {
case GradeA:
m.RegistryGradeACount++
case GradeB:
m.RegistryGradeBCount++
case GradeC:
m.RegistryGradeCCount++
case GradeD:
m.RegistryGradeDCount++
case GradeE:
m.RegistryGradeECount++
case GradeF:
m.RegistryGradeFCount++
default:
}
}
func (m *Metrics) product(product Product) {
switch product {
case ProductCloud:
m.RegistryProductCloudCount++
case ProductSynthetic:
m.RegistryProductSyntheticCount++
case ProductOSS:
fallthrough
default:
m.RegistryProductOSSCount++
}
}
func (m *Metrics) category(category Category) {
switch category {
case CategoryAuthentication:
m.RegistryCategoryAuthenticationCount++
case CategoryBrowser:
m.RegistryCategoryBrowserCount++
case CategoryData:
m.RegistryCategoryDataCount++
case CategoryKubernetes:
m.RegistryCategoryKubernetesCount++
case CategoryMessaging:
m.RegistryCategoryMessagingCount++
case CategoryObservability:
m.RegistryCategoryObservabilityCount++
case CategoryProtocol:
m.RegistryCategoryProtocolCount++
case CategoryReporting:
m.RegistryCategoryReportingCount++
case CategoryMisc:
fallthrough
default:
m.RegistryCategoryMiscCount++
}
}
func (m *Metrics) issue(issue string) {
switch issue {
case "module":
m.RegistryIssueModuleCount++
case "replace":
m.RegistryIssueReplaceCount++
case "readme":
m.RegistryIssueReadmeCount++
case "examples":
m.RegistryIssueExamplesCount++
case "license":
m.RegistryIssueLicenseCount++
case "git":
m.RegistryIssueGitCount++
case "versions":
m.RegistryIssueVersionsCount++
case "build":
m.RegistryIssueBuildCount++
case "smoke":
m.RegistryIssueSmokeCount++
case "types":
m.RegistryIssueTypesCount++
case "codeowners":
m.RegistryIssueCodeownersCount++
default:
}
}