Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,71 @@
## Commands

```
go build -o opensloctl . # build binary
go run . load -f <file> # parse and print OpenSlo specs
go run . generate -f <file> -o <dir> # generate Prometheus recording rules
golangci-lint run # lint (via mise)
go test ./... # run tests (none exist yet)
make lint # golangci-lint run
make test # go test ./...
make load FILE=<file> # parse and print OpenSlo specs
make generate FILE=<f> OUTPUT=<d> # generate Prometheus recording rules
```

Semconv registry (Weaver):
```
make semconv-generate # registry YAML → pkg/semconv/semconv_gen.go
make semconv-check # validate registry schema
make semconv-stats # show registry statistics
make semconv-diff BASE=<ref> # detect breaking changes vs base ref
```

## Architecture

- `main.go` → `cmd.Execute()` — single entrypoint
- CLI: cobra-based, two subcommands: `load`, `generate`
- `pkg/specstore/` — loads and sorts OpenSlo YAML files into typed structs
- `internal/generator/prometheusgenerator/` — generates Prometheus recording rule YAML from SLO specs using Go templates (embedded via `//go:embed`)
- `pkg/semconv/` — OpenTelemetry semantic convention constants
- `internal/feature/` — feature flags (multi-dimensional SLI annotations)
- `pkg/util/file.go` — file discovery (recursive YAML/YML finder)
- Both accept `-f` (filename, repeatable) and `-r` (recursive directory scan)
- `generate` also requires `-o` (output directory)
- `pkg/specstore/loader.go` — loads YAML files via `openslosdk.Decode`, sorts into typed `OpenSloSpecs` struct
- `internal/generator/generator.go` — `Generator` interface
- `internal/generator/prometheusgenerator/` — generates Prometheus recording rule YAML from SLO specs using Go templates + sprig (embedded via `//go:embed`)
- `internal/feature/feature.go` — feature flags for multi-dimensional SLI annotations
- `pkg/semconv/semconv_gen.go` — **auto-generated** from semconv registry (do not edit manually)
- `pkg/util/file.go` — recursive YAML/YML file discovery

## Semconv Codegen Flow

`semconv/registry/` (YAML metrics/attributes) → `semconv/templates/go/` (MiniJinja) → `pkg/semconv/semconv_gen.go`

Run `make semconv-generate` after editing registry YAML or templates. `go generate ./...` runs this before goreleaser builds.

## Key Dependencies

- `github.com/thisisibrahimd/openslo` — OpenSlo SDK for decoding specs
- `github.com/OpenSLO/go-sdk` — official OpenSlo SDK for decoding specs (v0.9.2)
- `github.com/spf13/cobra` — CLI framework
- `github.com/charmbracelet/log` — logging
- `log/slog` — structured logging (stdlib)
- `github.com/Masterminds/sprig/v3` — template functions
- OpenTelemetry Weaver — semconv registry management

## CI / Release

- GoReleaser builds linux/darwin binaries, CGO_ENABLED=0
- PR triggers snapshot dry-run; published release triggers real release
- `go mod tidy` + `go generate ./...` run before build
- `before` hooks: `go mod tidy` + `go generate ./...`
- `prerelease: auto` — tags with prerelease markers get prerelease release

## Tooling

- `mise.toml` manages Go (1.26), golangci-lint, weaver
- `go.mod` declares `go 1.25.5` — auto-upgraded by SDK migration; trust mise for dev
- No `.golangci.yml` — uses defaults
- No Makefile, Taskfile, or pre-commit hooks
- No tests exist — adding tests requires setting up from scratch

## Gotchas

- `generate` requires `-o` (output directory) — cannot be empty
- `generate` requires `indicator` on SLOs; ratio metrics not supported
- Spec files must be YAML/YML; non-OpenSlo files are silently skipped with a log error
- No tests exist — adding tests requires setting up from scratch
- `generate` rejects: empty `-o`, SLOs without `indicator`, ratio metrics (not supported)
- Only `ThresholdMetric` supported — `RatioMetric` returns error
- Non-OpenSlo YAML files silently skipped (continue on decode error)
- `semconv_gen.go` is auto-generated — never hand-edit
- Feature flags use SLO annotations: `multi-dimensional-sli.openslo.com/dimensions` + `multi-dimensional-sli.openslo.com/label`

## SDK API Notes (github.com/OpenSLO/go-sdk)

- `SLIMetricSource.Spec` (not `MetricSourceSpec`) — `map[string]any` containing the query
- `SLOObjective.Target` is `*float64` (pointer), not `float64`
- `SLOTimeWindow.Duration` is `v1.DurationShorthand` (struct), not `string` — use `.String()` for string representation
- `BudgetAdjustment` kind not supported in this SDK version
12 changes: 8 additions & 4 deletions cmd/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"github.com/charmbracelet/log"
"log/slog"
"os"

"github.com/spf13/cobra"
"github.com/thisisibrahimd/opensloctl/internal/generator/prometheusgenerator"
"github.com/thisisibrahimd/opensloctl/pkg/specstore"
Expand Down Expand Up @@ -32,17 +34,19 @@ func newGenerateCommand() *cobra.Command {
}

func runGenerate(cmd *cobra.Command, args []string, flags generateFlags) {
log.Info("running generate command")
slog.Info("running generate command")

specStore := specstore.NewSpecStore(specstore.WithFilenames(flags.filenames), specstore.WithRecursive(flags.recursive))
specs, err := specStore.GetSpecs()
if err != nil {
log.Fatal(err)
slog.Error(err.Error())
os.Exit(1)
}

pg := prometheusgenerator.NewPrometheusGenerator(specs)
err = pg.Generate(flags.outputDirectory)
if err != nil {
log.Fatal("unable to generate files", "err", err)
slog.Error("unable to generate files", "err", err)
os.Exit(1)
}
}
12 changes: 7 additions & 5 deletions cmd/load.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"github.com/charmbracelet/log"
"log/slog"
"os"

"github.com/spf13/cobra"
"github.com/thisisibrahimd/opensloctl/pkg/specstore"
)
Expand Down Expand Up @@ -29,15 +31,15 @@ func newLoadCommand() *cobra.Command {
}

func runLoad(cmd *cobra.Command, args []string, flags loadFlags) {
log.Info("reading files/dirs", "number", len(flags.filenames))
slog.Info("reading files/dirs", "number", len(flags.filenames))

// Read and load specs
specStore := specstore.NewSpecStore(specstore.WithFilenames(flags.filenames), specstore.WithRecursive(flags.recursive))
specs, err := specStore.GetSpecs()
if err != nil {
log.Fatal(err)
slog.Error(err.Error())
os.Exit(1)
}

log.Info(specs)

slog.Info("specs loaded", "count", len(specs.V1.SLOs))
}
24 changes: 9 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
module github.com/thisisibrahimd/opensloctl

go 1.22.5
go 1.25.5

require (
github.com/Masterminds/sprig/v3 v3.3.0
github.com/charmbracelet/log v0.4.0
github.com/OpenSLO/go-sdk v0.9.2
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.8.1
github.com/thisisibrahimd/openslo v1.0.1-alpha5
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.13.0 // indirect
github.com/charmbracelet/x/ansi v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/nobl9/govy v0.26.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/tools v0.45.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)
44 changes: 16 additions & 28 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@ github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY=
github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/OpenSLO/go-sdk v0.9.2 h1:pc6b4sWImIJreEDGNPbfplMbOZL5LwOkoRq2IULShRc=
github.com/OpenSLO/go-sdk v0.9.2/go.mod h1:s4PEBTqO5O2u5SeVFQZyLHE9RzCZgGNxTt43FwuqvCo=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand All @@ -36,25 +28,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/nobl9/govy v0.26.0 h1:pjHXreO+3Rl+Uz6/rFX7L54zH4LW/SaTjb6YX3GQGs4=
github.com/nobl9/govy v0.26.0/go.mod h1:fExiIzXORe0ktwg2bWasOAmCZtEFMQkR4PpgzhHcZSA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand All @@ -68,17 +51,22 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/thisisibrahimd/openslo v1.0.1-alpha5 h1:A2swL0D41eGVNpGydwlyl1kUesCdOega+2Hb23Br7qs=
github.com/thisisibrahimd/openslo v1.0.1-alpha5/go.mod h1:SQ1CagQEbM454dDhJBAmJOzDhtJaN3h+LPwkFnUtYyY=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v3 v3.0.3 h1:bXOww4E/J3f66rav3pX3m8w6jDE4knZjGOw8b5Y6iNE=
go.yaml.in/yaml/v3 v3.0.3/go.mod h1:tBHosrYAkRZjRAOREWbDnBXUf08JOwYq++0QNwQiWzI=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
14 changes: 7 additions & 7 deletions internal/generator/prometheusgenerator/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package prometheusgenerator
import (
"bytes"
"fmt"
"log/slog"
"os"
"path"
"regexp"
"strconv"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/charmbracelet/log"
"github.com/pkg/errors"
"github.com/thisisibrahimd/opensloctl/internal/feature"
"github.com/thisisibrahimd/opensloctl/internal/generator"
Expand Down Expand Up @@ -44,15 +44,15 @@ func (g *PrometheusGenerator) Generate(outputDirectory string) error {
return errors.New("output directory can not be empty")
}

log.Info("generating files")
slog.Info("generating files")
generatedFiles, err := g.createGeneratedFiles()
if err != nil {
return errors.Wrap(err, "unable to create generated files")
}

for _, generatedFile := range generatedFiles {
fullPath := path.Join(outputDirectory, generatedFile.Path)
log.Info("writing generated files", "file", fullPath)
slog.Info("writing generated files", "file", fullPath)
err := os.WriteFile(fullPath, generatedFile.Bytes(), 0664)
if err != nil {
return errors.Wrap(err, "unable to write file")
Expand All @@ -66,7 +66,7 @@ func (g *PrometheusGenerator) createGeneratedFiles() ([]*generator.GeneratedFile
var generatedPrometheusRuleFiles []*generator.GeneratedFile
// loop through slos
for _, slo := range g.specs.V1.SLOs {
log.Info("generating prometheus recording rule", "slo", slo.Metadata.Name)
slog.Info("generating prometheus recording rule", "slo", slo.Metadata.Name)

// TODO: support indicator ref
// Ensure indicator is present
Expand All @@ -79,7 +79,7 @@ func (g *PrometheusGenerator) createGeneratedFiles() ([]*generator.GeneratedFile
if slo.Spec.Indicator.Spec.RatioMetric != nil {
return nil, fmt.Errorf("ratio metrics are not supported")
} else {
promQuery = slo.Spec.Indicator.Spec.ThresholdMetric.MetricSource.MetricSourceSpec["query"].(string)
promQuery = slo.Spec.Indicator.Spec.ThresholdMetric.MetricSource.Spec["query"].(string)
}

// check if features are enabled
Expand Down Expand Up @@ -108,15 +108,15 @@ func (g *PrometheusGenerator) createGeneratedFiles() ([]*generator.GeneratedFile
}

// extract days in time window
numberOfDays := numberRegex.FindString(slo.Spec.TimeWindow[0].Duration)
numberOfDays := numberRegex.FindString(slo.Spec.TimeWindow[0].Duration.String())

// template out prom rules
tpldData := templates.TemplateData{
SloName: slo.Metadata.Name,
OpensloVersion: string(slo.APIVersion),
PrometheusQuery: windowedPromQueries[0].Query,
WindowedPrometheusQueries: windowedPromQueries,
Objective: strconv.FormatFloat(slo.Spec.Objectives[0].Target, 'f', -1, 32),
Objective: strconv.FormatFloat(*slo.Spec.Objectives[0].Target, 'f', -1, 64),
IsMulti: multiFeatureEnabled,
MultiDimensionalLabel: multiDimSliLabel,
TimeWindowDays: numberOfDays,
Expand Down
Loading
Loading