Skip to content

Commit

Permalink
Merge pull request #125 from grafana/124-improve-the-generated-metrics
Browse files Browse the repository at this point in the history
Improve the generated metrics
  • Loading branch information
szkiba authored Dec 11, 2024
2 parents 5747764 + 54a7efb commit a745adb
Show file tree
Hide file tree
Showing 68 changed files with 1,457 additions and 741 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ After modifying registry schema ([registry.schema.json]), the [registry_gen.go]
```bash
curl -s -o docs/registry.schema.json https://raw.githubusercontent.com/grafana/k6-extension-registry/main/registry.schema.json
go-jsonschema --capitalization URL --capitalization JavaScript --capitalization OSS -p k6registry --only-models -o registry_gen.go docs/registry.schema.json
bash metrics_gen.sh
```

[registry.schema.json]: docs/registry.schema.json
Expand Down
80 changes: 56 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ Registry generated from the source above.
"observability"
],
"compliance": {
"grade": "C",
"level": 80
"grade": "A",
"level": 100
},
"description": "Web-based metrics dashboard for k6",
"module": "github.com/grafana/xk6-dashboard",
Expand All @@ -89,8 +89,8 @@ Registry generated from the source above.
"name": "xk6-dashboard",
"owner": "grafana",
"public": true,
"stars": 343,
"timestamp": 1719907965,
"stars": 367,
"timestamp": 1731922735,
"topics": [
"xk6",
"xk6-official",
Expand Down Expand Up @@ -141,8 +141,11 @@ Registry generated from the source above.
"data"
],
"compliance": {
"grade": "A",
"level": 100
"grade": "B",
"issues": [
"smoke"
],
"level": 93
},
"description": "Load test SQL Servers",
"imports": [
Expand All @@ -155,14 +158,14 @@ Registry generated from the source above.
],
"repo": {
"clone_url": "https://github.com/grafana/xk6-sql.git",
"description": "k6 extension to load test RDBMSs (PostgreSQL, MySQL, MS SQL and SQLite3)",
"homepage": "https://github.com/grafana/xk6-sql",
"description": "Use SQL databases from k6 tests.",
"homepage": "http://sql.x.k6.io",
"license": "Apache-2.0",
"name": "xk6-sql",
"owner": "grafana",
"public": true,
"stars": 110,
"timestamp": 1725979901,
"stars": 120,
"timestamp": 1733736611,
"topics": [
"k6",
"sql",
Expand All @@ -172,6 +175,7 @@ Registry generated from the source above.
},
"tier": "official",
"versions": [
"v1.0.0",
"v0.4.1",
"v0.4.0",
"v0.3.0",
Expand All @@ -188,7 +192,12 @@ Registry generated from the source above.
],
"compliance": {
"grade": "C",
"level": 80
"issues": [
"smoke",
"examples",
"types"
],
"level": 81
},
"description": "Inject faults to test",
"imports": [
Expand All @@ -206,8 +215,8 @@ Registry generated from the source above.
"name": "xk6-disruptor",
"owner": "grafana",
"public": true,
"stars": 93,
"timestamp": 1727763654,
"stars": 97,
"timestamp": 1733824028,
"topics": [
"chaos-engineering",
"fault-injection",
Expand All @@ -219,6 +228,8 @@ Registry generated from the source above.
},
"tier": "official",
"versions": [
"v0.3.13",
"v0.3.12",
"v0.3.11",
"v0.3.10",
"v0.3.9",
Expand Down Expand Up @@ -246,8 +257,11 @@ Registry generated from the source above.
"data"
],
"compliance": {
"grade": "A",
"level": 100
"grade": "B",
"issues": [
"smoke"
],
"level": 93
},
"description": "Generate random fake data",
"imports": [
Expand All @@ -265,8 +279,8 @@ Registry generated from the source above.
"name": "xk6-faker",
"owner": "grafana",
"public": true,
"stars": 55,
"timestamp": 1725533453,
"stars": 63,
"timestamp": 1733730893,
"topics": [
"xk6"
],
Expand All @@ -289,8 +303,12 @@ Registry generated from the source above.
"misc"
],
"compliance": {
"grade": "A",
"level": 100
"grade": "C",
"issues": [
"smoke",
"types"
],
"level": 87
},
"description": "Print ASCII art banner from k6 test",
"imports": [
Expand Down Expand Up @@ -354,6 +372,7 @@ Registry generated from the source above.
},
"tier": "official",
"versions": [
"v0.55.0",
"v0.54.0",
"v0.53.0",
"v0.52.0",
Expand Down Expand Up @@ -533,6 +552,8 @@ By using the `--api` flag, files are created with relative paths in a base direc
```ascii file=docs/example-api.txt
docs/example-api
├── catalog.json
├── metrics.json
├── metrics.txt
├── registry.json
├── category
│   ├── authentication.json
Expand Down Expand Up @@ -563,21 +584,26 @@ docs/example-api
│   │   └── grafana
│   │   ├── xk6-dashboard
│   │   │   ├── badge.svg
│   │   │   └── extension.json
│   │   │   ├── extension.json
│   │   │   └── grade.svg
│   │   ├── xk6-disruptor
│   │   │   ├── badge.svg
│   │   │   └── extension.json
│   │   │   ├── extension.json
│   │   │   └── grade.svg
│   │   ├── xk6-faker
│   │   │   ├── badge.svg
│   │   │   └── extension.json
│   │   │   ├── extension.json
│   │   │   └── grade.svg
│   │   └── xk6-sql
│   │   ├── badge.svg
│   │   └── extension.json
│   │   ├── extension.json
│   │   └── grade.svg
│   ├── gitlab.com
│   │   └── szkiba
│   │   └── xk6-banner
│   │   ├── badge.svg
│   │   └── extension.json
│   │   ├── extension.json
│   │   └── grade.svg
│   └── go.k6.io
│   └── k6
│   └── extension.json
Expand All @@ -591,10 +617,16 @@ docs/example-api
└── tier
├── community-catalog.json
├── community.json
├── community-metrics.json
├── community-metrics.txt
├── official-catalog.json
├── official.json
├── official-metrics.json
├── official-metrics.txt
├── partner-catalog.json
├── partner.json
├── partner-metrics.json
├── partner-metrics.txt
└── at-least
├── community-catalog.json
├── community.json
Expand Down
45 changes: 44 additions & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,50 @@ func writeAPIGroupGlobal(registry k6registry.Registry, target string) error {
return err
}

return writeJSON(filepath.Join(target, "metrics.json"), k6registry.CalculateMetrics(registry))
if err := writeMetrics(registry, target, "", func(_ k6registry.Extension) bool { return true }); err != nil {
return err
}

for _, tier := range k6registry.Tiers {
err := writeMetrics(registry, filepath.Join(target, "tier"), string(tier)+"-",
func(ext k6registry.Extension) bool {
return ext.Tier == tier
})
if err != nil {
return err
}
}

return nil
}

func writeMetrics(
registry k6registry.Registry,
target string,
prefix string,
cond func(k6registry.Extension) bool,
) error {
metrics := k6registry.CalculateMetricsCond(registry, cond)

basename := "metrics"

if len(prefix) > 0 {
basename = prefix + basename
}

basename = filepath.Join(target, basename)

err := writeJSON(basename+".json", metrics)
if err != nil {
return err
}

data, err := metrics.MarshalPrometheus()
if err != nil {
return err
}

return os.WriteFile(basename+".txt", data, permFile) //nolint:forbidigo
}

const gradesvg = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="20"><clipPath id="B"><rect width="17" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#B)"><path fill="%s" d="M0 0h17v20H0z"/><path fill="url(#A)" d="M0 0h17v20H0z"/></g><g text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text x="85" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="70">%s</text><text x="85" y="140" transform="scale(.1)" fill="#fff" textLength="70">%s</text></g></svg>` //nolint:lll
Expand Down
23 changes: 18 additions & 5 deletions docs/example-api.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
docs/example-api
├── catalog.json
├── metrics.json
├── metrics.txt
├── registry.json
├── category
│   ├── authentication.json
Expand Down Expand Up @@ -30,21 +32,26 @@ docs/example-api
│   │   └── grafana
│   │   ├── xk6-dashboard
│   │   │   ├── badge.svg
│   │   │   └── extension.json
│   │   │   ├── extension.json
│   │   │   └── grade.svg
│   │   ├── xk6-disruptor
│   │   │   ├── badge.svg
│   │   │   └── extension.json
│   │   │   ├── extension.json
│   │   │   └── grade.svg
│   │   ├── xk6-faker
│   │   │   ├── badge.svg
│   │   │   └── extension.json
│   │   │   ├── extension.json
│   │   │   └── grade.svg
│   │   └── xk6-sql
│   │   ├── badge.svg
│   │   └── extension.json
│   │   ├── extension.json
│   │   └── grade.svg
│   ├── gitlab.com
│   │   └── szkiba
│   │   └── xk6-banner
│   │   ├── badge.svg
│   │   └── extension.json
│   │   ├── extension.json
│   │   └── grade.svg
│   └── go.k6.io
│   └── k6
│   └── extension.json
Expand All @@ -58,10 +65,16 @@ docs/example-api
└── tier
├── community-catalog.json
├── community.json
├── community-metrics.json
├── community-metrics.txt
├── official-catalog.json
├── official.json
├── official-metrics.json
├── official-metrics.txt
├── partner-catalog.json
├── partner.json
├── partner-metrics.json
├── partner-metrics.txt
└── at-least
├── community-catalog.json
├── community.json
Expand Down
Loading

0 comments on commit a745adb

Please sign in to comment.