Skip to content

Commit f8285ff

Browse files
authored
🌱 GitLab: Add RepoHost tag to OpenCensus view (#3320)
* Add RepoHost tag to OpenCensus view Signed-off-by: Raghav Kaul <[email protected]> * placate godot Signed-off-by: Raghav Kaul <[email protected]> * don't panic Signed-off-by: Raghav Kaul <[email protected]> * init new logger and emit warning Signed-off-by: Raghav Kaul <[email protected]> --------- Signed-off-by: Raghav Kaul <[email protected]>
1 parent e9495bb commit f8285ff

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

checker/check_runner.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,21 @@ func (r *Runner) Run(ctx context.Context, c Check) CheckResult {
9696
fmt.Sprintf("requiredType: %s not supported by check %s", fmt.Sprint(unsupported), r.CheckName)))
9797
}
9898

99+
l := NewLogger()
99100
ctx, err := tag.New(ctx, tag.Upsert(stats.CheckName, r.CheckName))
100101
if err != nil {
101-
panic(err)
102+
l.Warn(&LogMessage{Text: fmt.Sprintf("tag.New: %v", err)})
102103
}
104+
105+
ctx, err = tag.New(ctx, tag.Upsert(stats.RepoHost, r.CheckRequest.Repo.Host()))
106+
if err != nil {
107+
l.Warn(&LogMessage{Text: fmt.Sprintf("tag.New: %v", err)})
108+
}
109+
103110
startTime := time.Now()
104111

105112
var res CheckResult
106-
l := NewLogger()
113+
l = NewLogger()
107114
for retriesRemaining := checkRetries; retriesRemaining > 0; retriesRemaining-- {
108115
checkRequest := r.CheckRequest
109116
checkRequest.Ctx = ctx

stats/tags.go

+2
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ var (
2323
ErrorName = tag.MustNewKey("errorName")
2424
// RequestTag is the tag key for the request type.
2525
RequestTag = tag.MustNewKey("requestTag")
26+
// RepoHost is the tag key for the host of the repository being scanned.
27+
RepoHost = tag.MustNewKey("repoHost")
2628
)

stats/views.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
Name: "CheckRuntime",
2727
Description: "CPU runtime stats per check",
2828
Measure: CheckRuntimeInSec,
29-
TagKeys: []tag.Key{CheckName},
29+
TagKeys: []tag.Key{CheckName, RepoHost},
3030
//nolint:gomnd
3131
Aggregation: view.Distribution(
3232
0,
@@ -51,7 +51,7 @@ var (
5151
Name: "CheckErrorCount",
5252
Description: "Error count by type per check",
5353
Measure: CheckErrors,
54-
TagKeys: []tag.Key{CheckName, ErrorName},
54+
TagKeys: []tag.Key{CheckName, RepoHost, ErrorName},
5555
Aggregation: view.Count(),
5656
}
5757

@@ -60,7 +60,7 @@ var (
6060
Name: "OutgoingHTTPRequests",
6161
Description: "HTTPRequests made per check",
6262
Measure: HTTPRequests,
63-
TagKeys: []tag.Key{CheckName, RequestTag},
63+
TagKeys: []tag.Key{CheckName, RepoHost, RequestTag},
6464
Aggregation: view.Count(),
6565
}
6666
)

0 commit comments

Comments
 (0)