Skip to content

Commit

Permalink
refactor to remove multi-report since unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca committed Nov 5, 2023
1 parent c400eb4 commit f1b94bd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 59 deletions.
4 changes: 2 additions & 2 deletions grafana_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func generateDashboard(title string, metrics []string) {

// Update Dashboard based on metrics
dashboard := generateDashboardJson(title, strings.Join(panels, ","))
err := os.WriteFile(fmt.Sprintf("grafana/dashboards/instrumentation-benchmarks-%v.json", title), []byte(dashboard), 0644)
err := os.WriteFile("grafana/dashboards/instrumentation-benchmarks.json", []byte(dashboard), 0644)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func generateDashboardJson(title, panels string) string {
},
"timepicker": {},
"timezone": "",
"title": "Benchmarks (%v)",
"title": "%v",
"uid": "",
"version": 2,
"weekStart": ""
Expand Down
10 changes: 2 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ func main() {
}()
otel.SetMeterProvider(meterProvider)

reports := []string{
"release",
"snapshot-regression",
"snapshot",
}

// Cache API calls to github to prevent repeated calls when testing
commitCache := NewSingleFileCache("cache/commit-cache.json")
reportCache := NewSingleFileCache("cache/report-cache.json")
Expand All @@ -40,6 +34,6 @@ func main() {

timeframe, _ := generateTimeframeToToday("2022-02-14", 7)

data := FetchReports(timeframe, *commitCache, *reportCache, client, repo, reports)
ConvertReports(reports, timeframe, data, exp, ctx)
data := FetchReports(timeframe, *commitCache, *reportCache, client, repo)
ConvertReport(timeframe, data, exp, ctx)
}
49 changes: 23 additions & 26 deletions report_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,35 @@ import (
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

func ConvertReports(reports, timeframe []string, data map[string]string, exp metric.Exporter, ctx context.Context) {
for _, report := range reports {
dataPoints := map[string][]metricdata.DataPoint[float64]{}
for _, timestamp := range timeframe {

report := ParseReport(data[fmt.Sprintf("%v-%v", timestamp, report)])
for entity, metrics := range report.Metrics {
for metricName, metricValue := range metrics {
if _, ok := dataPoints[metricName]; !ok {
dataPoints[metricName] = []metricdata.DataPoint[float64]{}
}
dataPoints[metricName] = append(dataPoints[metricName], *generateDataPoint(entity, report.Date, metricValue))
func ConvertReport(timeframe []string, data map[string]string, exp metric.Exporter, ctx context.Context) {
dataPoints := map[string][]metricdata.DataPoint[float64]{}
for _, timestamp := range timeframe {
report := ParseReport(data[timestamp])
for entity, metrics := range report.Metrics {
for metricName, metricValue := range metrics {
if _, ok := dataPoints[metricName]; !ok {
dataPoints[metricName] = []metricdata.DataPoint[float64]{}
}
dataPoints[metricName] = append(dataPoints[metricName], *generateDataPoint(entity, report.Date, metricValue))
}
}
}

var metricNames []string
var metricNames []string

var metrics []metricdata.Metrics
for metric, metricData := range dataPoints {
metrics = append(metrics, *generateMetrics(metric, metricData))
metricNames = append(metricNames, metric)
}
var metrics []metricdata.Metrics
for metric, metricData := range dataPoints {
metrics = append(metrics, *generateMetrics(metric, metricData))
metricNames = append(metricNames, metric)
}

resourceMetrics := generateResourceMetrics(metrics)
resourceMetrics := generateResourceMetrics(metrics)

// export to collector
fmt.Printf("Exporting metrics for %v\n", report)
_ = exp.Export(ctx, resourceMetrics)
// export to collector
fmt.Print("Exporting metrics")
_ = exp.Export(ctx, resourceMetrics)

// Update Dashboard based on metrics
generateDashboard(report, metricNames)
fmt.Printf("Generated dashboard for %v", report)
}
// Update Dashboard based on metrics
generateDashboard("Benchmark Metrics", metricNames)
fmt.Print("Generated dashboard")
}
25 changes: 10 additions & 15 deletions report_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import "fmt"

func FetchReports(timeframe []string, commitCache, reportCache SingleFileCache, client ReportSource, repo string, reports []string) map[string]string {
func FetchReports(timeframe []string, commitCache, reportCache SingleFileCache, client ReportSource, repo string) map[string]string {
results := make(map[string]string)

for _, timestamp := range timeframe {
Expand All @@ -19,22 +19,17 @@ func FetchReports(timeframe []string, commitCache, reportCache SingleFileCache,
}

var contents string

for _, report := range reports {
mapKey := fmt.Sprintf("%v-%v", timestamp, report)
filePath := fmt.Sprintf("benchmark-overhead/results/%v/summary.txt", report)
cached, _ = reportCache.RetrieveValue(mapKey)
if cached == "" {
contents, _ = client.GetFileAtCommit(repo, filePath, commit)
err := reportCache.AddToCache(mapKey, contents)
if err != nil {
fmt.Println("Error adding to cache")
}
} else {
contents = cached
cached, _ = reportCache.RetrieveValue(timestamp)
if cached == "" {
contents, _ = client.GetFileAtCommit(repo, "benchmark-overhead/results/release/summary.txt", commit)
err := reportCache.AddToCache(timestamp, contents)
if err != nil {
fmt.Println("Error adding to cache")
}
results[mapKey] = contents
} else {
contents = cached
}
results[timestamp] = contents

}
return results
Expand Down
18 changes: 10 additions & 8 deletions report_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ func TestReportReturnsMappedData(t *testing.T) {

timeframe, _ := generateTimeframeSlice("2022-02-14", "2022-02-15", 1)

reports := []string{
"release",
}

result := FetchReports(timeframe, *commitCache, *reportCache, githubClient, "test-repo", reports)
assert.Contains(t, result["2022-02-14-release"], "Mon Feb 14 05:17:37 UTC 2022")
result := FetchReports(timeframe, *commitCache, *reportCache, githubClient, "test-repo")
assert.Contains(t, result["2022-02-14"], "Mon Feb 14 05:17:37 UTC 2022")

commitCache.DeleteCache()
reportCache.DeleteCache()
err := commitCache.DeleteCache()
if err != nil {
return
}
err = reportCache.DeleteCache()
if err != nil {
return
}
}

0 comments on commit f1b94bd

Please sign in to comment.