Skip to content

Commit

Permalink
Merge branch 'main' into PC-13028-support-for-azure-prometheus-direct
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidwisn authored Jun 19, 2024
2 parents aba3dce + cd7b62d commit 988294e
Show file tree
Hide file tree
Showing 59 changed files with 163 additions and 56 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ jobs:
NOBL9_SDK_CLIENT_SECRET: ${{ secrets.clientSecret }}
NOBL9_SDK_OKTA_ORG_URL: ${{ inputs.oktaOrgUrl }}
NOBL9_SDK_OKTA_AUTH_SERVER: ${{ inputs.oktaAuthServer }}
NOBL9_SDK_NO_CONFIG_FILE: true
run: make test/e2e
2 changes: 2 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ words:
- noprefix
- nriq
- nrql
- objectimpl
- opentsdb
- opsgenie
- pagerduty
Expand Down Expand Up @@ -133,6 +134,7 @@ words:
- timeseries
- timeslice
- timeslices
- tmpl
- tpng
- tsdb
- twindow
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/MicahParks/jwkset v0.5.18
github.com/MicahParks/keyfunc/v3 v3.3.3
github.com/aws/aws-sdk-go v1.53.20
github.com/aws/aws-sdk-go v1.54.3
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/goccy/go-yaml v1.11.3
github.com/golang-jwt/jwt/v5 v5.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/MicahParks/jwkset v0.5.18 h1:WLdyMngF7rCrnstQxA7mpRoxeaWqGzPM/0z40PJU
github.com/MicahParks/jwkset v0.5.18/go.mod h1:q8ptTGn/Z9c4MwbcfeCDssADeVQb3Pk7PnVxrvi+2QY=
github.com/MicahParks/keyfunc/v3 v3.3.3 h1:c6j9oSu1YUo0k//KwF1miIQlEMtqNlj7XBFLB8jtEmY=
github.com/MicahParks/keyfunc/v3 v3.3.3/go.mod h1:f/UMyXdKfkZzmBeBFUeYk+zu066J1Fcl48f7Wnl5Z48=
github.com/aws/aws-sdk-go v1.53.20 h1:cYWPvZLP1gPj5CfUdnfjaaA7WFK3FGoJ/R9+Ks1inU4=
github.com/aws/aws-sdk-go v1.53.20/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.54.3 h1:Bk+EXoq6v5I1xmHR9GQGpsMWZZFXs+FD+5uPyEmfgX0=
github.com/aws/aws-sdk-go v1.54.3/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
16 changes: 16 additions & 0 deletions internal/cmd/objectimpl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# docgen

`objectimpl` is a tool that generates boilerplate functions for manifest objects
in order to implement `manifest.Object` interface.

It utilizes `text/template` to generate the code.

## Usage

Add the following `generate` directive to the file that contains
the `manifest.Object` object definition.
Replace the `<OBJECT_KIND>` with the struct name of your object, e.g. `Project`.

```go
//go:generate go run ../../../internal/cmd/objectimpl <OBJECT_KIND>
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"unicode"
)

//go:embed generate-object-impl.tpl
//go:embed object.tmpl
var templateStr string

type generator struct {
Expand Down Expand Up @@ -80,7 +80,7 @@ func main() {
errFatal(err.Error())
}
outputName := filepath.Join(cwd, fmt.Sprintf("%s_object.go", strings.TrimSuffix(filename, ".go")))
if err = os.WriteFile(outputName, formatted, 0600); err != nil {
if err = os.WriteFile(outputName, formatted, 0o600); err != nil {
errFatal(err.Error())
}
}
Expand Down Expand Up @@ -168,11 +168,7 @@ func (g *generator) hasOrganizationAndManifestSource(fields *ast.FieldList) bool
return hasOrganization && hasManifestSource
}

func errFatal(f string, a ...interface{}) {
if len(a) == 0 {
fmt.Fprintln(os.Stderr, f)
} else {
fmt.Fprintf(os.Stderr, f+"\n", a...)
}
func errFatal(f string) {
fmt.Fprintln(os.Stderr, f)
os.Exit(1)
}
File renamed without changes.
2 changes: 1 addition & 1 deletion manifest/v1alpha/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Agent
//go:generate go run ../../../internal/cmd/objectimpl Agent

// New creates new Agent instance.
func New(metadata Metadata, spec Spec) Agent {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/agent/agent_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Alert
//go:generate go run ../../../internal/cmd/objectimpl Alert

// New creates a new Alert based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Alert {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alert/alert_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alertmethod/alert_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go AlertMethod
//go:generate go run ../../../internal/cmd/objectimpl AlertMethod

// New creates a new AlertMethod based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) AlertMethod {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alertmethod/alert_method_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alertpolicy/alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go AlertPolicy
//go:generate go run ../../../internal/cmd/objectimpl AlertPolicy

func New(metadata Metadata, spec Spec) AlertPolicy {
return AlertPolicy{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alertpolicy/alert_policy_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alertsilence/alert_silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go AlertSilence
//go:generate go run ../../../internal/cmd/objectimpl AlertSilence

// New creates a new AlertSilence based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) AlertSilence {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alertsilence/alert_silence_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/annotation/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go Annotation
//go:generate go run ../../../internal/cmd/objectimpl Annotation

// New creates a new Annotation based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Annotation {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/annotation/annotation_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/budgetadjustment/budget_adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go BudgetAdjustment
//go:generate go run ../../../internal/cmd/objectimpl BudgetAdjustment

func New(metadata Metadata, spec Spec) BudgetAdjustment {
return BudgetAdjustment{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/dataexport/data_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go DataExport
//go:generate go run ../../../internal/cmd/objectimpl DataExport

// New creates a new DataExport based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) DataExport {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/dataexport/data_export_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/direct/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Direct
//go:generate go run ../../../internal/cmd/objectimpl Direct

func New(metadata Metadata, spec Spec) Direct {
return Direct{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/direct/direct_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Project
//go:generate go run ../../../internal/cmd/objectimpl Project

// New creates a new Project based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Project {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/project/project_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/rolebinding/role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go RoleBinding
//go:generate go run ../../../internal/cmd/objectimpl RoleBinding

func New(metadata Metadata, spec Spec) RoleBinding {
return RoleBinding{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/rolebinding/role_binding_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Service
//go:generate go run ../../../internal/cmd/objectimpl Service

// New creates a new Service based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Service {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/service/service_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/slo/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go SLO
//go:generate go run ../../../internal/cmd/objectimpl SLO

// New creates a new SLO based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) SLO {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/slo/slo_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/usergroup/user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go UserGroup
//go:generate go run ../../../internal/cmd/objectimpl UserGroup

func New(metadata Metadata, spec Spec) UserGroup {
return UserGroup{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/usergroup/user_group_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"devDependencies": {
"cspell": "8.8.4",
"cspell": "8.9.0",
"markdownlint-cli": "0.41.0",
"yaml": "2.4.5"
},
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions sdk/parser_test.go → sdk/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
v1alphaService "github.com/nobl9/nobl9-go/manifest/v1alpha/service"
)

//go:embed test_data/parser
var parserTestData embed.FS
//go:embed test_data/decode
var decodeTestData embed.FS

func TestDecode(t *testing.T) {
for _, test := range []struct {
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestDecodeSingle(t *testing.T) {

func readInputFile(t *testing.T, name string) []byte {
t.Helper()
data, err := parserTestData.ReadFile(filepath.Join("test_data", "parser", name))
data, err := decodeTestData.ReadFile(filepath.Join("test_data", "decode", name))
require.NoError(t, err)
return data
}
22 changes: 17 additions & 5 deletions sdk/printer.go → sdk/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

// PrintObjects prints objects to the given [io.Writer] in specified [manifest.ObjectFormat].
// EncodeObjects writes objects to the given [io.Writer] in the specified [manifest.ObjectFormat].
func EncodeObjects(objects []manifest.Object, out io.Writer, format manifest.ObjectFormat) error {
return encodeObjects(objects, out, format)
}

// EncodeObject writes a single object to the given [io.Writer] in the specified [manifest.ObjectFormat].
func EncodeObject(object manifest.Object, out io.Writer, format manifest.ObjectFormat) error {
return encodeObjects(object, out, format)
}

// PrintObjects prints objects to the given [io.Writer] in the specified [manifest.ObjectFormat].
// Deprecated: Use EncodeObjects instead.
func PrintObjects(objects []manifest.Object, out io.Writer, format manifest.ObjectFormat) error {
return printObjects(objects, out, format)
return encodeObjects(objects, out, format)
}

// PrintObject prints a single object to the given [io.Writer] in specified [manifest.ObjectFormat].
// PrintObject prints a single object to the given [io.Writer] in the specified [manifest.ObjectFormat].
// Deprecated: Use EncodeObject instead.
func PrintObject(object manifest.Object, out io.Writer, format manifest.ObjectFormat) error {
return printObjects(object, out, format)
return encodeObjects(object, out, format)
}

func printObjects(objects any, out io.Writer, format manifest.ObjectFormat) error {
func encodeObjects(objects any, out io.Writer, format manifest.ObjectFormat) error {
switch format {
case manifest.ObjectFormatJSON:
enc := json.NewEncoder(out)
Expand Down
Loading

0 comments on commit 988294e

Please sign in to comment.