sloth icon indicating copy to clipboard operation
sloth copied to clipboard

validate/generate command fails when spec file is created with CRLF on windows

Open ishantanu opened this issue 2 years ago • 1 comments

Hello,

I was testing adding new plugins to sloth and I saw that sloth validate command fails when the Sloth spec is created with CRLF.

The error message doesn't mention any of this. However, when I copied an existing spec and edited the plugin id, it worked. Similarly, when I created a test.yml file with LF, the validate as well as generate command worked.

Example:

File created using default CRLF:

$ sloth validate -p plugins/ -i test/integration/ --debug
DEBU[0000] Debug level is enabled                        version=v0.10.0
DEBU[0000] SLI plugin loaded                             plugin-id=sloth-common/kubernetes/kooper/availability plugin-path="plugins\\kubernetes\\kooper\\availability\\plugin.go" svc=storage.FileSLIPlugin version=v0.10.0 window=30d
DEBU[0000] SLI plugin loaded                             plugin-id=sloth-common/kubernetes/kooper/latency plugin-path="plugins\\kubernetes\\kooper\\latency\\plugin.go" svc=storage.FileSLIPlugin version=v0.10.0 window=30d
DEBU[0000] SLI plugin loaded                             plugin-id=sloth-common/test1 plugin-path="plugins\\test1\\plugin.go" svc=storage.FileSLIPlugin version=v0.10.0 window=30d
...
INFO[0000] SLI plugins loaded                            plugins=20 svc=storage.FileSLIPlugin version=v0.10.0 window=30d
INFO[0000] SLO period windows loaded                     svc=alert.WindowsRepo version=v0.10.0 window=30d windows=2
DEBU[0000] File validated                                file="test\\integration\\coredns-availability.yml" version=v0.10.0 window=30d
...
DEBU[0000] File validated                                file="test\\integration\\slok-go-http-metrics-availability.yml" version=v0.10.0 window=30d
DEBU[0000] File validated                                file="test\\integration\\slok-go-http-metrics-latency.yml" version=v0.10.0 window=30d
DEBU[0000] File validated                                file="test\\integration\\test.yml" version=v0.10.0 window=30d
ERRO[0000] Unknown spec type                             file="test\\integration\\test.yml" version=v0.10.0 window=30d
...
DEBU[0000] File validated                                file="test\\integration\\traefik-v2-availability.yml" version=v0.10.0 window=30d
DEBU[0000] File validated                                file="test\\integration\\traefik-v2-latency.yml" version=v0.10.0 window=30d

File created using LF:

$ sloth validate -p plugins/ -i test/integration/ --debug
DEBU[0000] Debug level is enabled                        version=v0.10.0
DEBU[0000] SLI plugin loaded                             plugin-id=sloth-common/slok-go-http-metrics/latency plugin-path="plugins\\slok-go-http-metrics\\latency\\plugin.go" svc=storage.FileSLIPlugin version=v0.10.0 window=30d
...
DEBU[0000] SLI plugin loaded                             plugin-id=sloth-common/test1 plugin-path="plugins\\test1\\plugin.go" svc=storage.FileSLIPlugin version=v0.10.0 window=30d
...
DEBU[0000] SLI plugin loaded                             plugin-id=sloth-common/prometheus/rules/eval-availability plugin-path="plugins\\prometheus\\rules\\evalavailability\\plugin.go" svc=storage.FileSLIPlugin version=v0.10.0 window=30d
INFO[0000] SLI plugins loaded                            plugins=20 svc=storage.FileSLIPlugin version=v0.10.0 window=30d
INFO[0000] SLO period windows loaded                     svc=alert.WindowsRepo version=v0.10.0 window=30d windows=2
DEBU[0000] File validated                                file="test\\integration\\coredns-availability.yml" version=v0.10.0 window=30d
...
DEBU[0000] File validated                                file="test\\integration\\slok-go-http-metrics-latency.yml" version=v0.10.0 window=30d
DEBU[0000] File validated                                file="test\\integration\\test.yml" version=v0.10.0 window=30d
DEBU[0000] File validated                                file="test\\integration\\test1.yml" version=v0.10.0 window=30d
...
DEBU[0000] File validated                                file="test\\integration\\traefik-v2-latency.yml" version=v0.10.0 window=30d
INFO[0000] Validation succeeded                          slo-specs=21 version=v0.10.0 window=30d

ishantanu avatar Oct 17 '22 12:10 ishantanu

I confirm having the same issue when building on Windows with a Docker container running Sloth. Converting the .yml file to LF instead of the default CRLF fixed the error but it was definitely not obvious to find the right fix.

corentinaltepe avatar Oct 22 '22 11:10 corentinaltepe