asset

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const BaseVersion = "0.1"

Variables

View Source
var (
	ErrEmptyID     = errors.New("asset does not have ID")
	ErrProbeExists = errors.New("asset probe already exists")
	ErrEmptyURN    = errors.New("asset does not have URN")
	ErrUnknownType = errors.New("unknown type")
	ErrNilAsset    = errors.New("nil asset")
)

AllSupportedTypes holds a list of all supported types struct

Functions

func IncreaseMinorVersion

func IncreaseMinorVersion(v string) (string, error)

IncreaseMinorVersion bumps up the minor version +0.1

func NewFilterBuilder

func NewFilterBuilder() *filterBuilder

func ParseVersion

func ParseVersion(v string) (*semver.Version, error)

ParseVersion returns error if version string is not in MAJOR.MINOR format

Types

type Asset

type Asset struct {
	ID          string                 `json:"id" diff:"-"`
	URN         string                 `json:"urn" diff:"-"`
	Type        Type                   `json:"type" diff:"-"`
	Service     string                 `json:"service" diff:"-"`
	Name        string                 `json:"name" diff:"name"`
	Description string                 `json:"description" diff:"description"`
	Data        map[string]interface{} `json:"data" diff:"data"`
	URL         string                 `json:"url" diff:"url"`
	Labels      map[string]string      `json:"labels" diff:"labels"`
	Owners      []user.User            `json:"owners,omitempty" diff:"owners"`
	CreatedAt   time.Time              `json:"created_at" diff:"-"`
	UpdatedAt   time.Time              `json:"updated_at" diff:"-"`
	Version     string                 `json:"version" diff:"-"`
	UpdatedBy   user.User              `json:"updated_by" diff:"-"`
	Changelog   diff.Changelog         `json:"changelog,omitempty" diff:"-"`
	Probes      []Probe                `json:"probes,omitempty"`
}

Asset is a model that wraps arbitrary data with Compass' context

func (*Asset) Diff

func (a *Asset) Diff(otherAsset *Asset) (diff.Changelog, error)

Diff returns nil changelog with nil error if equal returns wrapped r3labs/diff Changelog struct with nil error if not equal

func (*Asset) Patch

func (a *Asset) Patch(patchData map[string]interface{})

Patch appends asset with data from map. It mutates the asset itself. It is using json annotation of the struct to patch the correct keys

type DiscoveryError

type DiscoveryError struct {
	Op     string
	ID     string
	Index  string
	ESCode string
	Err    error
}

func (DiscoveryError) Error

func (err DiscoveryError) Error() string

type DiscoveryRepository

type DiscoveryRepository interface {
	Upsert(context.Context, Asset) error
	DeleteByID(ctx context.Context, assetID string) error
	DeleteByURN(ctx context.Context, assetURN string) error
	Search(ctx context.Context, cfg SearchConfig) (results []SearchResult, err error)
	Suggest(ctx context.Context, cfg SearchConfig) (suggestions []string, err error)
	GroupAssets(ctx context.Context, cfg GroupConfig) (results []GroupResult, err error)
	SyncAssets(ctx context.Context, indexName string) (cleanup func() error, err error)
}

type Filter

type Filter struct {
	Types         []Type
	Services      []string
	Size          int
	Offset        int
	SortBy        string `validate:"omitempty,oneof=name type service created_at updated_at"`
	SortDirection string `validate:"omitempty,oneof=asc desc"`
	QueryFields   []string
	Query         string
	Data          map[string][]string
}

func (*Filter) Validate

func (f *Filter) Validate() error

type GroupConfig added in v0.5.4

type GroupConfig struct {
	// IncludedFields specifies the fields to return in response
	IncludedFields []string

	// GroupBy fields to group on
	GroupBy []string

	// Filters specifies document level values to look for.
	// Multiple values can be specified for a single key
	Filters SearchFilter

	// Number of documents you want in response
	Size int
}

GroupConfig represents a group query along with any corresponding filter(s)

type GroupField added in v0.5.4

type GroupField struct {
	Name  string
	Value string
}

type GroupResult added in v0.5.4

type GroupResult struct {
	Fields []GroupField
	Assets []Asset
}

type InvalidError

type InvalidError struct {
	AssetID string
}

func (InvalidError) Error

func (err InvalidError) Error() string

type Lineage

type Lineage struct {
	Edges     []LineageEdge             `json:"edges"`
	NodeAttrs map[string]NodeAttributes `json:"node_attrs"`
}

type LineageDirection

type LineageDirection string
const (
	LineageDirectionUpstream   LineageDirection = "upstream"
	LineageDirectionDownstream LineageDirection = "downstream"
)

func (LineageDirection) IsValid

func (dir LineageDirection) IsValid() bool

type LineageEdge

type LineageEdge struct {
	// Source represents source's node ID
	Source string `json:"source"`

	// Target represents target's node ID
	Target string `json:"target"`

	// Prop is a map containing extra information about the edge
	Prop map[string]interface{} `json:"prop"`
}

type LineageGraph

type LineageGraph []LineageEdge

type LineageQuery

type LineageQuery struct {
	Level     int
	Direction LineageDirection
}

type LineageRepository

type LineageRepository interface {
	GetGraph(ctx context.Context, urn string, query LineageQuery) (LineageGraph, error)
	Upsert(ctx context.Context, urn string, upstreams, downstreams []string) error
	DeleteByURN(ctx context.Context, urn string) error
}

type NodeAttributes

type NodeAttributes struct {
	Probes ProbesInfo `json:"probes"`
}

type NotFoundError

type NotFoundError struct {
	AssetID string
	URN     string
}

func (NotFoundError) Error

func (err NotFoundError) Error() string

type Probe

type Probe struct {
	ID           string                 `json:"id"`
	AssetURN     string                 `json:"asset_urn"`
	Status       string                 `json:"status"`
	StatusReason string                 `json:"status_reason"`
	Metadata     map[string]interface{} `json:"metadata"`
	Timestamp    time.Time              `json:"timestamp"`
	CreatedAt    time.Time              `json:"created_at"`
}

Probe represents a single asset's probe

type ProbesFilter

type ProbesFilter struct {
	AssetURNs []string
	MaxRows   int
	NewerThan time.Time
	OlderThan time.Time
}

type ProbesInfo

type ProbesInfo struct {
	Latest Probe `json:"latest"`
}

type Repository

type Repository interface {
	GetAll(context.Context, Filter) ([]Asset, error)
	GetCount(context.Context, Filter) (int, error)
	GetByID(ctx context.Context, id string) (Asset, error)
	GetByURN(ctx context.Context, urn string) (Asset, error)
	GetVersionHistory(ctx context.Context, flt Filter, id string) ([]Asset, error)
	GetByVersionWithID(ctx context.Context, id, version string) (Asset, error)
	GetByVersionWithURN(ctx context.Context, urn, version string) (Asset, error)
	GetTypes(ctx context.Context, flt Filter) (map[Type]int, error)
	Upsert(ctx context.Context, ast *Asset) (string, error)
	DeleteByID(ctx context.Context, id string) error
	DeleteByURN(ctx context.Context, urn string) error
	AddProbe(ctx context.Context, assetURN string, probe *Probe) error
	GetProbes(ctx context.Context, assetURN string) ([]Probe, error)
	GetProbesWithFilter(ctx context.Context, flt ProbesFilter) (map[string][]Probe, error)
}

type SearchConfig

type SearchConfig struct {
	// Text to search for
	Text string

	// Filters specifies document level values to look for.
	// Multiple values can be specified for a single key
	Filters SearchFilter

	// Number of relevant results to return
	MaxResults int

	// RankBy is a param to rank based on a specific parameter
	RankBy string

	// Queries is a param to search a resource based on asset's fields
	Queries map[string]string

	// Flags flags to control the search behavior (e.g. column level search, disable fuzzy, etc)
	Flags SearchFlags

	// Offset parameter defines the offset from the first result you want to fetch
	// Note that MaxResults + Offset can not be more than the `index.max_result_window` index setting in ES cluster, which defaults to 10,000
	Offset int

	// IncludeFields specifies the fields to return in response
	IncludeFields []string
}

SearchConfig represents a search query along with any corresponding filter(s)

type SearchFilter

type SearchFilter = map[string][]string

SearchFilter is a filter intended to be used as a search criteria for operations involving asset search

type SearchFlags added in v0.5.5

type SearchFlags struct {
	EnableHighlight bool

	// DisableFuzzy disables fuzziness on search
	DisableFuzzy bool

	IsColumnSearch bool
}

SearchFlags is intended to be used as flags to control the search behavior (e.g. column level search, disable fuzzy, enable highlight etc) for operations involving asset search

type SearchResult

type SearchResult struct {
	ID          string                 `json:"id"`
	URN         string                 `json:"urn"`
	Title       string                 `json:"title"`
	Type        string                 `json:"type"`
	Service     string                 `json:"service"`
	Description string                 `json:"description"`
	Labels      map[string]string      `json:"labels"`
	Data        map[string]interface{} `json:"data"`
}

SearchResult represents an item/result in a list of search results

func (SearchResult) ToAsset

func (sr SearchResult) ToAsset() Asset

ToAsset returns search result as asset

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(deps ServiceDeps) *Service

func (*Service) AddProbe

func (s *Service) AddProbe(ctx context.Context, assetURN string, probe *Probe) error

func (*Service) DeleteAsset

func (s *Service) DeleteAsset(ctx context.Context, id string) (err error)

func (*Service) GetAllAssets

func (s *Service) GetAllAssets(ctx context.Context, flt Filter, withTotal bool) ([]Asset, uint32, error)

func (*Service) GetAssetByID

func (s *Service) GetAssetByID(ctx context.Context, id string) (Asset, error)

func (*Service) GetAssetByIDWithoutProbes added in v0.6.1

func (s *Service) GetAssetByIDWithoutProbes(ctx context.Context, id string) (Asset, error)

func (*Service) GetAssetByVersion

func (s *Service) GetAssetByVersion(ctx context.Context, id, version string) (ast Asset, err error)

func (*Service) GetAssetVersionHistory

func (s *Service) GetAssetVersionHistory(ctx context.Context, flt Filter, id string) ([]Asset, error)

func (*Service) GetLineage

func (s *Service) GetLineage(ctx context.Context, urn string, query LineageQuery) (Lineage, error)

func (*Service) GetTypes

func (s *Service) GetTypes(ctx context.Context, flt Filter) (map[Type]int, error)

func (*Service) GroupAssets added in v0.5.4

func (s *Service) GroupAssets(ctx context.Context, cfg GroupConfig) (results []GroupResult, err error)

func (*Service) SearchAssets

func (s *Service) SearchAssets(ctx context.Context, cfg SearchConfig) (results []SearchResult, err error)

func (*Service) SuggestAssets

func (s *Service) SuggestAssets(ctx context.Context, cfg SearchConfig) (suggestions []string, err error)

func (*Service) SyncAssets added in v0.7.0

func (s *Service) SyncAssets(ctx context.Context, services []string) error

func (*Service) UpsertAsset

func (s *Service) UpsertAsset(ctx context.Context, ast *Asset, upstreams, downstreams []string) (string, error)

func (*Service) UpsertAssetWithoutLineage

func (s *Service) UpsertAssetWithoutLineage(ctx context.Context, ast *Asset) (string, error)

type ServiceDeps added in v0.6.0

type ServiceDeps struct {
	AssetRepo     Repository
	DiscoveryRepo DiscoveryRepository
	LineageRepo   LineageRepository
	Worker        Worker
}

type Type

type Type string

Type specifies a supported type name

const (
	TypeTable        Type = "table"
	TypeJob          Type = "job"
	TypeDashboard    Type = "dashboard"
	TypeTopic        Type = "topic"
	TypeFeatureTable Type = "feature_table"
	TypeApplication  Type = "application"
	TypeModel        Type = "model"
	TypeQuery        Type = "query"
)

func (Type) IsValid

func (t Type) IsValid() bool

IsValid will validate whether the typename is valid or not

func (Type) String

func (t Type) String() string

String cast Type to string

type Worker added in v0.6.0

type Worker interface {
	EnqueueIndexAssetJob(ctx context.Context, ast Asset) error
	EnqueueDeleteAssetJob(ctx context.Context, urn string) error
	EnqueueSyncAssetJob(ctx context.Context, service string) error
	Close() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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