report

package
v0.91.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: MPL-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package report defines Report object definitions. Report is under development and not yet available for use.

Index

Examples

Constants

View Source
const (
	// IsoDateOnlyLayout is date only (without time zone) of iso layout
	IsoDateOnlyLayout string = "2006-01-02"
)

Variables

View Source
var ErrInvalidRowGroupBy = fmt.Errorf("not a valid RowGroupBy, try [%s]", strings.Join(_RowGroupByNames, ", "))
View Source
var ErrInvalidSnapshotPoint = fmt.Errorf("not a valid SnapshotPoint, try [%s]", strings.Join(_SnapshotPointNames, ", "))

Functions

func GetMinDate added in v0.89.0

func GetMinDate() time.Time

func RowGroupByNames

func RowGroupByNames() []string

RowGroupByNames returns a list of possible string values of RowGroupBy.

func RowGroupByValidation

func RowGroupByValidation() govy.Rule[RowGroupBy]

func SnapshotPointNames

func SnapshotPointNames() []string

SnapshotPointNames returns a list of possible string values of SnapshotPoint.

func SnapshotPointValidation

func SnapshotPointValidation() govy.Rule[SnapshotPoint]

Types

type CalendarTimeFrame

type CalendarTimeFrame struct {
	From   *string `json:"from,omitempty"`
	To     *string `json:"to,omitempty"`
	Repeat `json:",inline"`
}

type ColumnSpec

type ColumnSpec struct {
	DisplayName string `json:"displayName" validate:"required"`
	Labels      Labels `json:"labels" validate:"required"`
}

type CustomPeriod

type CustomPeriod struct {
	StartDate string `json:"startDate,omitempty"`
	EndDate   string `json:"endDate,omitempty"`
}

type ErrorBudgetStatusConfig

type ErrorBudgetStatusConfig struct{}

type Filters

type Filters struct {
	Projects []string `json:"projects,omitempty"`
	Services Services `json:"services,omitempty"`
	SLOs     SLOs     `json:"slos,omitempty"`
	Labels   Labels   `json:"labels,omitempty"`
}

type LabelKey

type LabelKey = string

type LabelValue

type LabelValue = string

type Labels

type Labels map[LabelKey][]LabelValue

type Metadata

type Metadata struct {
	Name        string `json:"name" validate:"required,objectName"`
	DisplayName string `json:"displayName,omitempty"`
}

type Repeat

type Repeat struct {
	Unit  *string `json:"unit,omitempty" example:"Week"`
	Count *int    `json:"count,omitempty" example:"1"`
}

type Report

type Report struct {
	APIVersion manifest.Version `json:"apiVersion"`
	Kind       manifest.Kind    `json:"kind"`
	Metadata   Metadata         `json:"metadata"`
	Spec       Spec             `json:"spec"`

	Organization   string `json:"organization,omitempty"`
	ManifestSource string `json:"manifestSrc,omitempty"`
}
Example (ErrorBudgetStatus)
package main

import (
	"context"
	"log"

	"github.com/nobl9/nobl9-go/internal/examples"
	"github.com/nobl9/nobl9-go/manifest"
	"github.com/nobl9/nobl9-go/manifest/v1alpha/report"
)

func main() {
	// Create the object:
	myReport := report.New(
		report.Metadata{
			Name:        "report",
			DisplayName: "My report",
		},
		report.Spec{
			Shared: true,
			Filters: &report.Filters{
				Projects: []string{"project"},
				Services: []report.Service{
					{
						Name:    "service",
						Project: "project",
					},
				},
				SLOs: []report.SLO{
					{
						Name:    "slo1",
						Project: "project",
					},
				},
				Labels: map[string][]string{
					"key1": {
						"value1",
						"value2",
					},
					"key2": {
						"value1",
						"value2",
					},
				},
			},
			ErrorBudgetStatus: &report.ErrorBudgetStatusConfig{},
		},
	)

	// Verify the object:
	if err := myReport.Validate(); err != nil {
		log.Fatalf("report validation failed, err: %v", err)
	}
	// Apply the object:
	client := examples.GetOfflineEchoClient()
	if err := client.Objects().V1().Apply(context.Background(), []manifest.Object{myReport}); err != nil {
		log.Fatalf("failed to apply report, err: %v", err)
	}
}
Output:

apiVersion: n9/v1alpha
kind: Report
metadata:
  name: report
  displayName: My report
spec:
  shared: true
  filters:
    projects:
    - project
    services:
    - name: service
      project: project
    slos:
    - name: slo1
      project: project
    labels:
      key1:
      - value1
      - value2
      key2:
      - value1
      - value2
  errorBudgetStatus: {}
Example (SloHistory)
package main

import (
	"context"
	"log"

	"github.com/nobl9/nobl9-go/internal/examples"
	"github.com/nobl9/nobl9-go/manifest"
	"github.com/nobl9/nobl9-go/manifest/v1alpha/report"
)

func main() {
	// Create the object:
	myReport := report.New(
		report.Metadata{
			Name:        "report",
			DisplayName: "My report",
		},
		report.Spec{
			Shared: true,
			Filters: &report.Filters{
				Projects: []string{"project"},
				Services: []report.Service{
					{
						Name:    "service",
						Project: "project",
					},
				},
				SLOs: []report.SLO{
					{
						Name:    "slo1",
						Project: "project",
					},
				},
				Labels: map[string][]string{
					"key1": {
						"value1",
						"value2",
					},
					"key2": {
						"value1",
						"value2",
					},
				},
			},
			SLOHistory: &report.SLOHistoryConfig{
				TimeFrame: report.SLOHistoryTimeFrame{
					Rolling: &report.RollingTimeFrame{
						Repeat: report.Repeat{
							Unit:  ptr("Week"),
							Count: ptr(2),
						},
					},
					TimeZone: "America/New_York",
				},
			},
		},
	)

	// Verify the object:
	if err := myReport.Validate(); err != nil {
		log.Fatalf("report validation failed, err: %v", err)
	}
	// Apply the object:
	client := examples.GetOfflineEchoClient()
	if err := client.Objects().V1().Apply(context.Background(), []manifest.Object{myReport}); err != nil {
		log.Fatalf("failed to apply report, err: %v", err)
	}
}

func ptr[T any](v T) *T { return &v }
Output:

apiVersion: n9/v1alpha
kind: Report
metadata:
  name: report
  displayName: My report
spec:
  shared: true
  filters:
    projects:
    - project
    services:
    - name: service
      project: project
    slos:
    - name: slo1
      project: project
    labels:
      key1:
      - value1
      - value2
      key2:
      - value1
      - value2
  sloHistory:
    timeFrame:
      rolling:
        unit: Week
        count: 2
      timeZone: America/New_York
Example (SystemHealthReview)
package main

import (
	"context"
	"log"
	"time"

	"github.com/nobl9/nobl9-go/internal/examples"
	"github.com/nobl9/nobl9-go/manifest"
	"github.com/nobl9/nobl9-go/manifest/v1alpha/report"
)

func main() {
	// Create the object:
	myReport := report.New(
		report.Metadata{
			Name:        "report",
			DisplayName: "My report",
		},
		report.Spec{
			Shared: true,
			Filters: &report.Filters{
				Projects: []string{"project"},
				Services: []report.Service{
					{
						Name:    "service",
						Project: "project",
					},
				},
				SLOs: []report.SLO{
					{
						Name:    "slo1",
						Project: "project",
					},
				},
				Labels: map[string][]string{
					"key1": {
						"value1",
						"value2",
					},
					"key2": {
						"value1",
						"value2",
					},
				},
			},
			SystemHealthReview: &report.SystemHealthReviewConfig{
				TimeFrame: report.SystemHealthReviewTimeFrame{
					Snapshot: report.SnapshotTimeFrame{
						Point: report.SnapshotPointPast,
						DateTime: ptr(
							time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC),
						),
						Rrule: "FREQ=WEEKLY",
					},
					TimeZone: "America/New_York",
				},
				RowGroupBy: report.RowGroupByProject,
				Columns: []report.ColumnSpec{
					{
						DisplayName: "Column 1",
						Labels: map[string][]string{
							"key1": {
								"value1",
							},
							"key2": {
								"value1",
								"value2",
							},
						},
					},
					{
						DisplayName: "Column 2",
						Labels: map[string][]string{
							"key3": {
								"value1",
							},
						},
					},
				},
				Thresholds: report.Thresholds{
					RedLessThanOrEqual: ptr(0.8),
					GreenGreaterThan:   ptr(0.95),
					ShowNoData:         false,
				},
			},
		},
	)

	// Verify the object:
	if err := myReport.Validate(); err != nil {
		log.Fatalf("report validation failed, err: %v", err)
	}
	// Apply the object:
	client := examples.GetOfflineEchoClient()
	if err := client.Objects().V1().Apply(context.Background(), []manifest.Object{myReport}); err != nil {
		log.Fatalf("failed to apply report, err: %v", err)
	}
}

func ptr[T any](v T) *T { return &v }
Output:

apiVersion: n9/v1alpha
kind: Report
metadata:
  name: report
  displayName: My report
spec:
  shared: true
  filters:
    projects:
    - project
    services:
    - name: service
      project: project
    slos:
    - name: slo1
      project: project
    labels:
      key1:
      - value1
      - value2
      key2:
      - value1
      - value2
  systemHealthReview:
    timeFrame:
      snapshot:
        point: past
        dateTime: 2022-01-01T00:00:00Z
        rrule: FREQ=WEEKLY
      timeZone: America/New_York
    rowGroupBy: project
    columns:
    - displayName: Column 1
      labels:
        key1:
        - value1
        key2:
        - value1
        - value2
    - displayName: Column 2
      labels:
        key3:
        - value1
    thresholds:
      redLte: 0.8
      greenGt: 0.95
      showNoData: false

func New

func New(metadata Metadata, spec Spec) Report

func (Report) GetKind

func (r Report) GetKind() manifest.Kind

func (Report) GetManifestSource

func (r Report) GetManifestSource() string

func (Report) GetName

func (r Report) GetName() string

func (Report) GetOrganization

func (r Report) GetOrganization() string

func (Report) GetValidator

func (r Report) GetValidator() govy.Validator[Report]

func (Report) GetVersion

func (r Report) GetVersion() manifest.Version

func (Report) SetManifestSource

func (r Report) SetManifestSource(src string) manifest.Object

func (Report) SetOrganization

func (r Report) SetOrganization(org string) manifest.Object

func (Report) Validate

func (r Report) Validate() error

type RollingTimeFrame

type RollingTimeFrame struct {
	Repeat `json:",inline"`
}

type RowGroupBy

type RowGroupBy int

RowGroupBy /* ENUM(project = 1, service)*/

const (
	// RowGroupByProject is a RowGroupBy of type Project.
	RowGroupByProject RowGroupBy = iota + 1
	// RowGroupByService is a RowGroupBy of type Service.
	RowGroupByService
)

func ParseRowGroupBy

func ParseRowGroupBy(name string) (RowGroupBy, error)

ParseRowGroupBy attempts to convert a string to a RowGroupBy.

func RowGroupByValues

func RowGroupByValues() []RowGroupBy

RowGroupByValues returns a list of the values for RowGroupBy

func (RowGroupBy) IsValid

func (x RowGroupBy) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (RowGroupBy) MarshalText

func (r RowGroupBy) MarshalText() ([]byte, error)

func (RowGroupBy) String

func (x RowGroupBy) String() string

String implements the Stringer interface.

func (*RowGroupBy) UnmarshalText

func (x *RowGroupBy) UnmarshalText(text []byte) error

type SLO

type SLO struct {
	Name    string `json:"name" validate:"required"`
	Project string `json:"project" validate:"required"`
}

type SLOHistoryConfig

type SLOHistoryConfig struct {
	TimeFrame SLOHistoryTimeFrame `json:"timeFrame" validate:"required"`
}

type SLOHistoryTimeFrame

type SLOHistoryTimeFrame struct {
	Rolling  *RollingTimeFrame  `json:"rolling,omitempty"`
	Calendar *CalendarTimeFrame `json:"calendar,omitempty"`
	TimeZone string             `json:"timeZone" validate:"required,timeZone" example:"America/New_York"`
}

type SLOs

type SLOs []SLO

type Service

type Service struct {
	Name    string `json:"name" validate:"required"`
	Project string `json:"project" validate:"required"`
}

type Services

type Services []Service

type SnapshotPoint

type SnapshotPoint int

SnapshotPoint /* ENUM(past = 1, latest)*/

const (
	// SnapshotPointPast is a SnapshotPoint of type Past.
	SnapshotPointPast SnapshotPoint = iota + 1
	// SnapshotPointLatest is a SnapshotPoint of type Latest.
	SnapshotPointLatest
)

func ParseSnapshotPoint

func ParseSnapshotPoint(name string) (SnapshotPoint, error)

ParseSnapshotPoint attempts to convert a string to a SnapshotPoint.

func SnapshotPointValues

func SnapshotPointValues() []SnapshotPoint

SnapshotPointValues returns a list of the values for SnapshotPoint

func (SnapshotPoint) IsValid

func (x SnapshotPoint) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (SnapshotPoint) MarshalText

func (p SnapshotPoint) MarshalText() ([]byte, error)

func (SnapshotPoint) String

func (x SnapshotPoint) String() string

String implements the Stringer interface.

func (*SnapshotPoint) UnmarshalText

func (p *SnapshotPoint) UnmarshalText(text []byte) error

type SnapshotTimeFrame

type SnapshotTimeFrame struct {
	Point    SnapshotPoint `json:"point" validate:"required" example:"latest"`
	DateTime *time.Time    `json:"dateTime,omitempty"`
	Rrule    string        `json:"rrule,omitempty"`
}

type Spec

type Spec struct {
	CreatedAt          string                    `json:"createdAt,omitempty"`
	UpdatedAt          string                    `json:"updatedAt,omitempty"`
	Shared             bool                      `json:"shared" validate:"required"`
	CreatedBy          *string                   `json:"createdBy,omitempty"`
	Filters            *Filters                  `json:"filters,omitempty"`
	SystemHealthReview *SystemHealthReviewConfig `json:"systemHealthReview,omitempty"`
	SLOHistory         *SLOHistoryConfig         `json:"sloHistory,omitempty"`
	ErrorBudgetStatus  *ErrorBudgetStatusConfig  `json:"errorBudgetStatus,omitempty"`
}

type SystemHealthReviewConfig

type SystemHealthReviewConfig struct {
	TimeFrame  SystemHealthReviewTimeFrame `json:"timeFrame" validate:"required"`
	RowGroupBy RowGroupBy                  `json:"rowGroupBy" validate:"required" example:"project"`
	Columns    []ColumnSpec                `json:"columns" validate:"min=1,max=30"`
	Thresholds Thresholds                  `json:"thresholds" validate:"required"`
}

type SystemHealthReviewTimeFrame

type SystemHealthReviewTimeFrame struct {
	Snapshot SnapshotTimeFrame `json:"snapshot" validate:"required"`
	TimeZone string            `json:"timeZone" validate:"required,timeZone" example:"America/New_York"`
}

type Thresholds added in v0.85.0

type Thresholds struct {
	RedLessThanOrEqual *float64 `json:"redLte" validate:"required" example:"0.8"`
	// Yellow is calculated as the difference between Red and Green
	// thresholds. If Red and Green are the same, Yellow is not used on the report.
	GreenGreaterThan *float64 `json:"greenGt" validate:"required" example:"0.95"`
	// ShowNoData customizes the report to either show or hide rows with no data.
	ShowNoData bool `json:"showNoData"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL