Skip to content

Commit

Permalink
Merge pull request #33 from grafana/schema-improvements
Browse files Browse the repository at this point in the history
Schema improvements
  • Loading branch information
szkiba authored Aug 21, 2024
2 parents d6671fc + 929ad1a commit 17d3113
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 75 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,5 @@ Requires
## legacy - Convert legacy registry

```bash
go run ./cmd/k6registry . --legacy | yq '.[]|= pick(["module","description","tier","product","imports","outputs","repo"])|sort_by(.module)' > ./docs/legacy.yaml
go run ./cmd/k6registry . --legacy | yq '.[]|= pick(["module","description","tier","products","imports","outputs","repo","categories"])|sort_by(.module)' > ./docs/legacy.yaml
```
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,33 @@ Check [k6 Extension Registry Concept](docs/registry.md) for information on desig
outputs:
- dashboard
tier: official
categories:
- reporting
- observability

- module: github.com/grafana/xk6-sql
description: Load test SQL Servers
imports:
- k6/x/sql
tier: official
product: ["cloud", "oss"]
products: ["cloud", "oss"]
categories:
- data

- module: github.com/grafana/xk6-disruptor
description: Inject faults to test
imports:
- k6/x/disruptor
tier: official
categories:
- kubernetes

- module: github.com/szkiba/xk6-faker
description: Generate random fake data
imports:
- k6/x/faker
categories:
- data
```
<details>
Expand All @@ -42,12 +51,16 @@ Registry generated from the source above.
```json file=docs/example.json
[
{
"categories": [
"reporting",
"observability"
],
"description": "Web-based metrics dashboard for k6",
"module": "github.com/grafana/xk6-dashboard",
"outputs": [
"dashboard"
],
"product": [
"products": [
"oss"
],
"repo": {
Expand All @@ -57,7 +70,7 @@ Registry generated from the source above.
"name": "xk6-dashboard",
"owner": "grafana",
"public": true,
"stars": 320,
"stars": 323,
"topics": [
"xk6",
"xk6-official",
Expand Down Expand Up @@ -104,12 +117,15 @@ Registry generated from the source above.
"tier": "official"
},
{
"categories": [
"data"
],
"description": "Load test SQL Servers",
"imports": [
"k6/x/sql"
],
"module": "github.com/grafana/xk6-sql",
"product": [
"products": [
"cloud",
"oss"
],
Expand All @@ -120,7 +136,7 @@ Registry generated from the source above.
"name": "xk6-sql",
"owner": "grafana",
"public": true,
"stars": 102,
"stars": 104,
"topics": [
"k6",
"sql",
Expand All @@ -140,12 +156,15 @@ Registry generated from the source above.
"tier": "official"
},
{
"categories": [
"kubernetes"
],
"description": "Inject faults to test",
"imports": [
"k6/x/disruptor"
],
"module": "github.com/grafana/xk6-disruptor",
"product": [
"products": [
"oss"
],
"repo": {
Expand Down Expand Up @@ -190,12 +209,15 @@ Registry generated from the source above.
"tier": "official"
},
{
"categories": [
"data"
],
"description": "Generate random fake data",
"imports": [
"k6/x/faker"
],
"module": "github.com/szkiba/xk6-faker",
"product": [
"products": [
"oss"
],
"repo": {
Expand Down Expand Up @@ -223,9 +245,12 @@ Registry generated from the source above.
"tier": "community"
},
{
"categories": [
"misc"
],
"description": "A modern load testing tool, using Go and JavaScript",
"module": "go.k6.io/k6",
"product": [
"products": [
"cloud",
"oss"
],
Expand All @@ -236,7 +261,7 @@ Registry generated from the source above.
"name": "k6",
"owner": "grafana",
"public": true,
"stars": 24184,
"stars": 24285,
"topics": [
"es6",
"go",
Expand Down
111 changes: 67 additions & 44 deletions cmd/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type legacyExtension struct {
Description string `json:"description"`
Tiers []string `json:"tiers"`
Type []string `json:"type"`
Categories []string `json:"categories"`
}

func legacyConvert(ctx context.Context) error {
Expand Down Expand Up @@ -58,6 +59,7 @@ func legacyConvert(ctx context.Context) error {
ext.Module = strings.TrimPrefix(legacyExt.URL, "https://")
ext.Description = legacyExt.Description
ext.Tier = legacyTierToTier(legacyExt.Tiers)
ext.Categories = legacyCategoriesToCategories(legacyExt.Categories)

for _, legacyType := range legacyExt.Type {
typ := strings.ToLower(legacyType)
Expand Down Expand Up @@ -115,6 +117,20 @@ func legacyTierToTier(tiers []string) k6registry.Tier {
return ""
}

func legacyCategoriesToCategories(legacyCats []string) []k6registry.Category {
if len(legacyCats) == 0 {
return nil
}

cats := make([]k6registry.Category, 0, len(legacyCats))

for _, cat := range legacyCats {
cats = append(cats, k6registry.Category(strings.ToLower(cat)))
}

return cats
}

func legacyPatch(ext *k6registry.Extension) {
override, found := extOverrides[ext.Module]
if !found {
Expand All @@ -137,59 +153,66 @@ func legacyPatch(ext *k6registry.Extension) {
ext.Module = override.module
}

if len(override.categories) != 0 {
ext.Categories = override.categories
}

for from, to := range phrases {
ext.Description = strings.ReplaceAll(ext.Description, from, to)
}
}

type extOverride struct {
imports string
outputs string
module string
imports string
outputs string
module string
categories []k6registry.Category
}

var extOverrides = map[string]extOverride{ //nolint:gochecknoglobals
"github.com/AckeeCZ/xk6-google-iap": {imports: "k6/x/googleIap"},
"github.com/BarthV/xk6-es": {outputs: "xk6-es"},
"github.com/GhMartingit/xk6-mongo": {},
"github.com/JorTurFer/xk6-input-prometheus": {imports: "k6/x/prometheusread"},
"github.com/Juandavi1/xk6-prompt": {},
"github.com/LeonAdato/xk6-output-statsd": {outputs: "output-statsd"},
"github.com/Maksimall89/xk6-output-clickhouse": {},
"github.com/NAlexandrov/xk6-tcp": {},
"github.com/SYM01/xk6-proxy": {},
"github.com/acuenca-facephi/xk6-read": {},
"github.com/akiomik/xk6-nostr": {},
"github.com/anycable/xk6-cable": {},
"github.com/avitalique/xk6-file": {},
"github.com/deejiw/xk6-gcp": {},
"github.com/deejiw/xk6-interpret": {},
"github.com/distribworks/xk6-ethereum": {},
"github.com/domsolutions/xk6-fasthttp": {},
"github.com/dynatrace/xk6-output-dynatrace": {outputs: "output-dynatrace"},
"github.com/elastic/xk6-output-elasticsearch": {outputs: "output-elasticsearch"},
"github.com/fornfrey/xk6-celery": {},
"github.com/frankhefeng/xk6-oauth-pkce": {},
"github.com/gjergjsheldija/xk6-mllp": {},
"github.com/golioth/xk6-coap": {},
"github.com/gpiechnik2/xk6-httpagg": {},
"github.com/gpiechnik2/xk6-smtp": {},
"github.com/grafana/xk6-client-prometheus-remote": {imports: "k6/x/remotewrite"},
"github.com/grafana/xk6-client-tracing": {imports: "k6/x/tracing"},
"github.com/grafana/xk6-dashboard": {},
"github.com/grafana/xk6-disruptor": {},
"github.com/grafana/xk6-exec": {},
"github.com/grafana/xk6-kubernetes": {},
"github.com/grafana/xk6-loki": {},
"github.com/grafana/xk6-notification": {},
"github.com/grafana/xk6-output-influxdb": {outputs: "xk6-influxdb"},
"github.com/grafana/xk6-output-kafka": {outputs: "xk6-kafka"},
"github.com/grafana/xk6-output-timescaledb": {},
"github.com/grafana/xk6-sql": {},
"github.com/grafana/xk6-ssh": {},
"github.com/goharbor/xk6-harbor": {},
"github.com/heww/xk6-harbor": {module: "github.com/goharbor/xk6-harbor"},
"github.com/kelseyaubrecht/xk6-webtransport": {},
"github.com/AckeeCZ/xk6-google-iap": {imports: "k6/x/googleIap"},
"github.com/BarthV/xk6-es": {outputs: "xk6-es"},
"github.com/GhMartingit/xk6-mongo": {},
"github.com/JorTurFer/xk6-input-prometheus": {imports: "k6/x/prometheusread"},
"github.com/Juandavi1/xk6-prompt": {categories: []k6registry.Category{k6registry.CategoryMisc}},
"github.com/LeonAdato/xk6-output-statsd": {outputs: "output-statsd"},
"github.com/Maksimall89/xk6-output-clickhouse": {},
"github.com/NAlexandrov/xk6-tcp": {},
"github.com/SYM01/xk6-proxy": {categories: []k6registry.Category{k6registry.CategoryProtocol}},
"github.com/acuenca-facephi/xk6-read": {},
"github.com/akiomik/xk6-nostr": {},
"github.com/anycable/xk6-cable": {},
"github.com/avitalique/xk6-file": {},
"github.com/deejiw/xk6-gcp": {},
"github.com/deejiw/xk6-interpret": {},
"github.com/distribworks/xk6-ethereum": {categories: []k6registry.Category{k6registry.CategoryProtocol}},
"github.com/domsolutions/xk6-fasthttp": {categories: []k6registry.Category{k6registry.CategoryProtocol}},
"github.com/dynatrace/xk6-output-dynatrace": {outputs: "output-dynatrace"},
"github.com/elastic/xk6-output-elasticsearch": {outputs: "output-elasticsearch"},
"github.com/fornfrey/xk6-celery": {},
"github.com/frankhefeng/xk6-oauth-pkce": {},
"github.com/gjergjsheldija/xk6-mllp": {},
"github.com/golioth/xk6-coap": {},
"github.com/gpiechnik2/xk6-httpagg": {},
"github.com/gpiechnik2/xk6-smtp": {},
"github.com/grafana/xk6-client-prometheus-remote": {imports: "k6/x/remotewrite"},
"github.com/grafana/xk6-client-tracing": {imports: "k6/x/tracing"},
"github.com/grafana/xk6-dashboard": {},
"github.com/grafana/xk6-disruptor": {categories: []k6registry.Category{k6registry.CategoryKubernetes}},
"github.com/grafana/xk6-exec": {},
"github.com/grafana/xk6-kubernetes": {categories: []k6registry.Category{k6registry.CategoryKubernetes}},
"github.com/grafana/xk6-loki": {},
"github.com/grafana/xk6-notification": {},
"github.com/grafana/xk6-output-influxdb": {outputs: "xk6-influxdb"},
"github.com/grafana/xk6-output-kafka": {outputs: "xk6-kafka"},
"github.com/grafana/xk6-output-timescaledb": {},
"github.com/grafana/xk6-sql": {},
"github.com/grafana/xk6-ssh": {},
"github.com/goharbor/xk6-harbor": {},
"github.com/heww/xk6-harbor": {module: "github.com/goharbor/xk6-harbor"},
"github.com/kelseyaubrecht/xk6-webtransport": {
categories: []k6registry.Category{k6registry.CategoryMessaging, k6registry.CategoryProtocol},
},
"github.com/kubeshop/xk6-tracetest": {},
"github.com/leonyork/xk6-output-timestream": {},
"github.com/maksimall89/xk6-telegram": {},
Expand Down
10 changes: 7 additions & 3 deletions cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func load(ctx context.Context, in io.Reader, loose bool, lint bool) (interface{}
Module: k6Module,
Description: k6Description,
Tier: k6registry.TierOfficial,
Product: []k6registry.Product{
Products: []k6registry.Product{
k6registry.ProductCloud,
k6registry.ProductOss,
},
Expand All @@ -52,8 +52,12 @@ func load(ctx context.Context, in io.Reader, loose bool, lint bool) (interface{}
registry[idx].Tier = k6registry.TierCommunity
}

if len(ext.Product) == 0 {
registry[idx].Product = append(registry[idx].Product, k6registry.ProductOss)
if len(ext.Products) == 0 {
registry[idx].Products = append(registry[idx].Products, k6registry.ProductOss)
}

if len(ext.Categories) == 0 {
registry[idx].Categories = append(registry[idx].Categories, k6registry.CategoryMisc)
}

if ext.Repo != nil {
Expand Down
Loading

0 comments on commit 17d3113

Please sign in to comment.