OpenSLO converter for Nobl9!
Convert OpenSLO schema to Nobl9 configuration with ease π
Tip
Starting with sloctl
version 0.12.0
OpenSLO converter is available as a CLI through sloctl convert openslo
command.
To add the latest version to your Go module, run:
go get github.com/nobl9/nobl9-go
package main
import (
"bytes"
"context"
"log"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
"github.com/nobl9/nobl9-go/sdk"
"github.com/nobl9/nobl9-openslo/pkg/openslotonobl9"
)
const opensloData = `
apiVersion: openslo/v1
kind: Service
metadata:
annotations:
nobl9.com/metadata.project: non-default
my.domain/custom: foo
name: example-service
spec:
description: Example service description
`
func main() {
// Read OpenSLO objects.
objects, err := openslosdk.Decode(bytes.NewBufferString(opensloData), openslosdk.FormatYAML)
if err != nil {
log.Fatalf("failed to read OpenSLO objects: %v", err)
}
// Convert OpenSLO to Nobl9.
nobl9Objects, err := openslotonobl9.Convert(objects)
if err != nil {
log.Fatalf("failed to convert OpenSLO to Nobl9: %v", err)
}
// Create Nobl9 SDK client.
client, err := sdk.DefaultClient()
if err != nil {
log.Fatalf("failed to create Nobl9 SDK client: %v", err)
}
// Apply the objects.
if err = client.Objects().V1().Apply(context.Background(), nobl9Objects); err != nil {
log.Fatalf("failed to apply Nobl9 objects: %v", err)
}
}
- Resolve object references by either inlining or exporting dependent objects.
- Validate decoded and resolved OpenSLO objects according to OpenSLO-defined rules.
- Validate decoded and resolved OpenSLO objects according to Nobl9-defined, custom rules.
- Convert OpenSLO objects to Nobl9 objects.
The following OpenSLO objects map to Nobl9 schema:
OpenSLO object | Nobl9 object | Supported | Extra rules |
---|---|---|---|
v1.Service | v1alpha.Service | β | |
v1.SLO | v1alpha.SLO | β | |
v1.SLI | - | βοΈ | Inlined when referenced by SLO. |
v1.DataSource | v1alpha.Agent | β | By default, an Agent connection is created. Use annotations to create a Direct connection. |
v1.AlertPolicy | v1alpha.AlertPolicy | β | |
v1.AlertCondition | - | βοΈ | Inlined when referenced by AlertPolicy. |
v1.AlertNotificationTarget | v1.AlertMethod | β |
Generic fields in the OpenSLO schema also have additional rules applied.
spec.metricSource.spec
field is directly converted to a matching Nobl9
metric spec based on the metricSource.type
field.
Example:
# OpenSLO input:
metricSource:
type: prometheus
spec:
promql: sum(http_request_duration_seconds_count{handler="/api/v1/slos"})
# Nobl9 output:
query:
prometheus:
promql: sum(http_request_duration_seconds_count{handler="/api/v1/slos"})
Each field within metricSource.spec
must correspond exactly to the
definitions in Nobl9's query.<metricSource.type>
.
Similar to v1.SLI, the spec.type
field is used to determine the type
of Nobl9 data source details, and spec.connectionDetails
content must match
Nobl9's definition for that data source type.
Example:
# OpenSLO input:
type: appDynamics
connectionDetails:
accountName: nobl9
clientID: dev-agent@nobl9
clientName: dev-agent
clientSecret: secret
url: https://example.com
# Nobl9 output:
appDynamics:
accountName: nobl9
clientID: dev-agent@nobl9
clientName: dev-agent
clientSecret: secret
url: https://example.com
The list of objects passed to the Convert
method must include all
objects referenced within that list.
For instance, if v1.SLO
named my-slo references v1.SLI
named my-sli,
then the list must contain v1.SLI
named my-sli.
spec.indicatorRef
inlinesv1.SLI
.spec.alertPolicies[*].alertPolicyRef
inlinesv1.AlertPolicy
. The inlining is done recursively, so that objects referenced byv1.AlertPolicy
are inlined in the inlinedv1.AlertPolicy
.spec.alertPolicies[*]
(inlined version) is exported.
spec.conditions[*].conditionRef
inlinesv1.AlertCondition
.spec.notificationTargets[*]
(inlined version) is exported.
Each field in the resulting Nobl9 object can be modified
using the metadata.annotations
field in the OpenSLO object.
To change a field in the resulting Nobl9 object, provide an
annotation in the following format:
nobl9.com/<field_path>: <value>
Example:
# Input:
apiVersion: openslo/v1
kind: Service
metadata:
annotations:
nobl9.com/metadata.project: non-default
my.domain/custom: foo
name: example-service
spec:
description: Example service description
# Output:
apiVersion: n9/v1alpha
kind: Service
metadata:
annotations:
my.domain/custom: foo
project: non-default
name: example-service
spec:
description: Example service description
Common use cases:
nobl9.com/metadata.project
sets the project for the object.nobl9.com/kind
sets the service kind for the object. This applies only toDataSource
, allowing users to specifyDataSource
conversion to eitherAgent
orDirect
.