analyzer

package
v0.0.0-...-ed06964 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceName       = "Analyzer"
	ResourceNamePlural = "Analyzers"
)

Variables

View Source
var (
	// plugins
	StandardsID = "standards"
	CommonID    = "common"
	SecurityID  = "security"

	// rules
	EnsureSpanNamingRuleID      string = "span-naming"
	RequiredAttributesRuleID    string = "required-attributes"
	EnsureAttributeNamingRuleID string = "attribute-naming"
	NotEmptyAttributesRuleID    string = "no-empty-attributes"
	EnforceDnsRuleID            string = "prefer-dns"
	EnforceHttpsProtocolRuleID  string = "secure-https-protocol"
	EnsuresNoApiKeyLeakRuleID   string = "no-api-key-leak"

	ErrorLevelWarning  string = "warning"
	ErrorLevelError    string = "error"
	ErrorLevelDisabled string = "disabled"

	SortWeight = map[string]int{
		ErrorLevelError:    2,
		ErrorLevelWarning:  1,
		ErrorLevelDisabled: 0,
	}

	DefaultPlugins = []LinterPlugin{
		StandardsPlugin,
		CommonPlugin,
		SecurityPlugin,
	}

	AvailablePlugins = []string{StandardsPlugin.ID, CommonPlugin.ID, SecurityPlugin.ID}

	// standards
	StandardsPlugin = LinterPlugin{
		ID:          StandardsID,
		Name:        "OTel Semantic Conventions",
		Description: "Enforce trace standards following OTel Semantic Conventions",
		Enabled:     true,
		Rules: []LinterRule{
			EnsureSpanNamingRule,
			RequiredAttributesRule,
			EnsureAttributeNamingRule,
			NotEmptyAttributesRule,
		},
	}

	EnsureSpanNamingRule = LinterRule{
		ID:               EnsureSpanNamingRuleID,
		Name:             "Span Naming",
		Description:      "Enforce span names that identify a class of Spans",
		ErrorDescription: "",
		Tips:             []string{},
		Weight:           25,
		ErrorLevel:       "error",
	}

	RequiredAttributesRule = LinterRule{
		ID:               RequiredAttributesRuleID,
		Name:             "Required Attributes",
		Description:      "Enforce required attributes by span type",
		ErrorDescription: "This span is missing the following required attributes:",
		Tips:             []string{"This rule checks if all required attributes are present in spans of given type"},
		Weight:           25,
		ErrorLevel:       "error",
	}

	EnsureAttributeNamingRule = LinterRule{
		ID:               EnsureAttributeNamingRuleID,
		Name:             "Attribute Naming",
		Description:      "Enforce attribute keys to follow common specifications",
		ErrorDescription: "The following attributes do not follow the naming convention:",
		Tips: []string{
			"You should always add namespaces to your span names to ensure they will not be overwritten",
			"Use snake_case to separate multi-words. Ex: http.status_code instead of http.statusCode",
		},
		Weight:     25,
		ErrorLevel: "error",
	}

	NotEmptyAttributesRule = LinterRule{
		ID:               NotEmptyAttributesRuleID,
		Name:             "No Empty Attributes",
		Description:      "Disallow empty attribute values",
		ErrorDescription: "The following attributes are empty:",
		Tips:             []string{"Empty attributes don't provide any information about the operation and should be removed"},
		Weight:           25,
		ErrorLevel:       "error",
	}

	// common
	CommonPlugin = LinterPlugin{
		ID:          CommonID,
		Name:        "Common Problems",
		Description: "Help you find common mistakes with your application",
		Enabled:     true,
		Rules: []LinterRule{
			EnforceDnsRule,
		},
	}

	EnforceDnsRule = LinterRule{
		ID:               EnforceDnsRuleID,
		Name:             "Prefer DNS",
		Description:      "Enforce usage of DNS instead of IP addresses",
		ErrorDescription: "The following attributes are using IP addresses instead of DNS:",
		Tips:             []string{},
		Weight:           100,
		ErrorLevel:       "error",
	}

	// security
	SecurityPlugin = LinterPlugin{
		ID:          SecurityID,
		Name:        "Security",
		Description: "Help you find security problems with your application",
		Enabled:     true,
		Rules: []LinterRule{
			EnforceHttpsProtocolRule,
			EnsuresNoApiKeyLeakRule,
		},
	}

	EnforceHttpsProtocolRule = LinterRule{
		ID:               EnforceHttpsProtocolRuleID,
		Name:             "Secure HTTPS Protocol",
		Description:      "Enforce usage of secure protocol for HTTP server spans",
		ErrorDescription: "The following attributes are using insecure http protocol:",
		Tips:             []string{},
		Weight:           30,
		ErrorLevel:       "error",
	}

	EnsuresNoApiKeyLeakRule = LinterRule{
		ID:               EnsuresNoApiKeyLeakRuleID,
		Name:             "No API Key Leak",
		Description:      "Disallow leaked API keys for HTTP spans",
		ErrorDescription: "The following attributes are exposing API keys:",
		Tips:             []string{},
		Weight:           70,
		ErrorLevel:       "error",
	}
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Value       string   `json:"value"`
	Expected    string   `json:"expected"`
	Description string   `json:"description"`
	Suggestions []string `json:"suggestions"`
}

type EvalRuleResult

type EvalRuleResult struct {
	Passed  bool     `json:"passed"`
	Results []Result `json:"results"`
}

type Linter

type Linter struct {
	ID           id.ID          `json:"id"`
	Name         string         `json:"name"`
	Enabled      bool           `json:"enabled"`
	MinimumScore int            `json:"minimumScore"`
	Plugins      []LinterPlugin `json:"plugins"`
}

func GetDefaultLinter

func GetDefaultLinter() Linter

func (Linter) EnabledPlugins

func (l Linter) EnabledPlugins() []LinterPlugin

func (Linter) GetID

func (l Linter) GetID() id.ID

func (Linter) HasID

func (l Linter) HasID() bool

func (Linter) ShouldSkip

func (l Linter) ShouldSkip() bool

func (Linter) Validate

func (l Linter) Validate() error

func (Linter) WithMetadata

func (l Linter) WithMetadata() (Linter, error)

type LinterPlugin

type LinterPlugin struct {
	ID      string       `json:"id"`
	Enabled bool         `json:"enabled"`
	Rules   []LinterRule `json:"rules"`

	// internal fields
	Name        string `json:"name"`
	Description string `json:"description"`
}

type LinterResult

type LinterResult struct {
	Plugins      []PluginResult `json:"plugins"`
	Score        int            `json:"score"`
	MinimumScore int            `json:"minimumScore"`
	Passed       bool           `json:"passed"`
}

func NewLinterResult

func NewLinterResult(pluginResults []PluginResult, totalScore int, passed bool) LinterResult

type LinterRule

type LinterRule struct {
	ID         string `json:"id"`
	Weight     int    `json:"weight"`
	ErrorLevel string `json:"errorLevel"`

	// internal fields
	Name             string   `json:"name"`
	ErrorDescription string   `json:"errorDescription"`
	Description      string   `json:"description"`
	Tips             []string `json:"tips"`
}

type PluginResult

type PluginResult struct {
	// metadata
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`

	//results
	Passed bool         `json:"passed"`
	Score  int          `json:"score"`
	Rules  []RuleResult `json:"rules"`
}

func (PluginResult) CalculateResults

func (pr PluginResult) CalculateResults() PluginResult

type Repository

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

func NewRepository

func NewRepository(db *sql.DB) *Repository

func (*Repository) Count

func (r *Repository) Count(ctx context.Context, query string) (int, error)

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, linter Linter) (Linter, error)

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, id id.ID) error

func (*Repository) Get

func (r *Repository) Get(ctx context.Context, id id.ID) (Linter, error)

func (*Repository) GetDefault

func (r *Repository) GetDefault(ctx context.Context) Linter

func (*Repository) List

func (r *Repository) List(ctx context.Context, take, skip int, query, sortBy, sortDirection string) ([]Linter, error)

func (*Repository) Provision

func (r *Repository) Provision(ctx context.Context, linter Linter) error

func (*Repository) SetID

func (r *Repository) SetID(linters Linter, id id.ID) Linter

func (*Repository) SortingFields

func (*Repository) SortingFields() []string

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, linter Linter) (Linter, error)

type Result

type Result struct {
	SpanID string  `json:"span_id"`
	Passed bool    `json:"passed"`
	Errors []Error `json:"errors"`
}

type RuleResult

type RuleResult struct {
	// config
	ID               string   `json:"id"`
	Name             string   `json:"name"`
	Description      string   `json:"description"`
	ErrorDescription string   `json:"errorDescription"`
	Tips             []string `json:"tips"`
	Weight           int      `json:"weight"`
	Level            string   `json:"level"`

	// results
	Passed  bool     `json:"passed"`
	Results []Result `json:"results"`
}

func NewRuleResult

func NewRuleResult(config LinterRule, results EvalRuleResult) RuleResult

func SortRules

func SortRules(rules []RuleResult, sortWeight map[string]int) []RuleResult

Jump to

Keyboard shortcuts

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