backend

package
v0.0.0-...-d983439 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClockFn

func ClockFn(fn func() error) error

ClockFn will call the provided func and clock the time it took to run

Example: ```

f := func() error {
  return aFuncToMeasure()
}

err := backend.ClockFn(f) ```

func ClockFnWithFields

func ClockFnWithFields(fn func() error, fields log.Fields) error

ClockFnWithFields will call the provided func and clock the time it took to run plus adding the provided Fields to the log message

Example: Clock the time to insert a elasticsearch document ```

f := func() error {
  // Add a document on a particular
  _, err := bkend.client.Index().
    Index(index).
    Type(mapping.Type).
    BodyJson(data).
    Do(ctx)
  return err
}
fields := log.Fields{
  "metric": "elasticsearch",
  "type":   "doc_insert",
  "index":  index,
}

err := backend.ClockFnWithFields(f, fields) ```

This example will log a message similar to: => time="" level=info msg=metric index=converge-history-2017.12.12 metric=elasticsearch ms=12 type=doc_insert

func CountNumberOfValuesMap

func CountNumberOfValuesMap(jsonMap map[string]interface{}) int

CountNumberOfValuesMap - counts the number of

func EmptyStringIfNil

func EmptyStringIfNil(attribute interface{}) string

EmptyStringIfNil asserts an interface as a string, and if that fails it returns empty string

func Flatten

func Flatten(m map[string]interface{}) map[string]interface{}

Types

type ChefClientResource

type ChefClientResource struct {
	Type            string              `json:"type"`
	Name            string              `json:"name"`
	ID              string              `json:"id"`
	Duration        string              `json:"duration"`
	Delta           string              `json:"delta"`
	Result          string              `json:"result"`
	Status          string              `json:"status"`
	IgnoreFailure   ignoreFailureOption `json:"ignore_failure,omitempty"`
	CookbookName    string              `json:"cookbook_name,omitempty"`
	CookbookVersion string              `json:"cookbook_version,omitempty"`
	CookbookType    string              `json:"cookbook_type,omitempty"`
	RecipeName      string              `json:"recipe_name,omitempty"`
	Conditional     string              `json:"conditional,omitempty"`
	Error           ChefError           `json:"error,omitempty"`
}

ChefClientResource represents a resource as reported from chef client

type ChefClientRun

type ChefClientRun struct {
	ChefServerFqdn       string               `json:"chef_server_fqdn"`
	EntityUUID           string               `json:"entity_uuid"`
	ExpandedRunList      ExpandedRunList      `json:"expanded_run_list"`
	ID                   string               `json:"id"`
	MessageVersion       string               `json:"message_version"`
	MessageType          string               `json:"message_type"`
	NodeName             string               `json:"node_name"`
	OrganizationName     string               `json:"organization_name"`
	Resources            []ChefClientResource `json:"resources"`
	RunID                string               `json:"run_id"`
	RunList              []string             `json:"run_list"`
	StartTime            time.Time            `json:"start_time"`
	EndTime              time.Time            `json:"end_time"`
	Source               string               `json:"source"`
	Status               string               `json:"status"`
	TotalResourceCount   int                  `json:"total_resource_count"`
	UpdatedResourceCount int                  `json:"updated_resource_count"`
	Error                ChefError            `json:"error,omitempty"`
	NodePayload          NodePayload          `json:"node"`
	PolicyName           string               `json:"policy_name"`
	PolicyGroup          string               `json:"policy_group"`
	Deprecations         []Deprecation        `json:"deprecations,omitempty"`
	Tags                 []string             `json:"tags,omitempty"`
}

ChefClientRun is the struct representing a chef client converge message

func (*ChefClientRun) ChefVersion

func (ccr *ChefClientRun) ChefVersion() string

ChefVersion Returns a chef version string retrieved from automatic attributes or an empty string if it is not present

func (*ChefClientRun) CloudProvider

func (ccr *ChefClientRun) CloudProvider() string

func (*ChefClientRun) Cookbooks

func (ccr *ChefClientRun) Cookbooks() []string

Cookbooks returns an array of strings containing the names of cookbooks

func (*ChefClientRun) DmiSystemManufacturer

func (ccr *ChefClientRun) DmiSystemManufacturer() string

func (*ChefClientRun) DmiSystemSerialNumber

func (ccr *ChefClientRun) DmiSystemSerialNumber() string

func (*ChefClientRun) KernelRelease

func (ccr *ChefClientRun) KernelRelease() string

func (*ChefClientRun) KernelVersion

func (ccr *ChefClientRun) KernelVersion() string

func (*ChefClientRun) MemoryTotal

func (ccr *ChefClientRun) MemoryTotal() string

func (*ChefClientRun) Platform

func (ccr *ChefClientRun) Platform() string

func (*ChefClientRun) PlatformWithVersion

func (ccr *ChefClientRun) PlatformWithVersion() string

func (*ChefClientRun) RecipeNames

func (ccr *ChefClientRun) RecipeNames() []string

RecipeNames Returns an array of strings containing only the recipe names of the CCR

func (*ChefClientRun) ResourceNames

func (ccr *ChefClientRun) ResourceNames() []string

ResourceNames Returns an array of strings containing only the resource names of the CCR

func (*ChefClientRun) RoleNames

func (ccr *ChefClientRun) RoleNames() []string

RoleNames Returns an array of strings containing only the tag names of the CCR

func (*ChefClientRun) TagNames

func (ccr *ChefClientRun) TagNames() []string

TagNames Returns an array of strings containing only the tag names of the CCR

func (*ChefClientRun) Timezone

func (ccr *ChefClientRun) Timezone() string

func (*ChefClientRun) ToNode

func (ccr *ChefClientRun) ToNode() (nodeState Node, err error)

ToNode Returns a Node after transforming a ChefClientRun into a Node object

func (*ChefClientRun) ToNodeAttribute

func (ccr *ChefClientRun) ToNodeAttribute() (NodeAttribute, error)

ToNodeAttribute Returns the node attribute from a ChefClientRun

func (*ChefClientRun) ToNodeRun

func (ccr *ChefClientRun) ToNodeRun() (run Run, err error)

ToNodeRun returns a run after transforming a ChefClientRun into a Run object

func (*ChefClientRun) VirtualizationRole

func (ccr *ChefClientRun) VirtualizationRole() string

func (*ChefClientRun) VirtualizationSystem

func (ccr *ChefClientRun) VirtualizationSystem() string

type ChefError

type ChefError struct {
	Class       string               `json:"class"`
	Message     string               `json:"message"`
	Backtrace   []string             `json:"backtrace"`
	Description ChefErrorDescription `json:"description"`
}

ChefError as reported by chef client converge message

type ChefErrorDescription

type ChefErrorDescription struct {
	Title    string                   `json:"title"`
	Sections []map[string]interface{} `json:"sections"`
}

type Client

type Client interface {
	project_update_lib.SerializedProjectUpdate
	// @param None
	Initializing() bool
	// @param (context)
	InitializeStore(context.Context) error
	// @param (context, node)
	InsertNode(context.Context, Node) error
	// @param (context, node)
	InsertUpsertNode(ctx context.Context, node UpsertNode) error
	// @param (context, UTC time, data)
	InsertRun(context.Context, Run) error
	// @param (context, UTC time, data)
	InsertNodeAttribute(context.Context, NodeAttribute) error
	// @param (context, UTC time)
	InsertNodeRunDateInfo(context.Context, Run) error
	// @param (context, threshold)
	MarkNodesMissing(context.Context, string) ([]string, error)
	// @param (context, threshold)
	DeleteMarkedNodes(context.Context, string) (int, error)
	// @param (context, threshold)
	MarkMissingNodesForDeletion(context.Context, string) ([]string, error)
	// @param (context, nodeIDs []string)
	MarkForDeleteMultipleNodesByID(ctx context.Context, nodeIDs []string) (int, error)
	// @param (context, nodeID string)
	DeleteNodeByID(ctx context.Context, nodeID string) (int, error)
	// @param (context, orgName string, remoteHostname string, nodeName string)
	DeleteNodeByFields(ctx context.Context, orgName string, remoteHostname string, nodeName string) (int, error)
	// @param (context, indexName)
	DeleteIndex(context.Context, string) error
	// @param (context, indexName)
	DoesIndexExists(context.Context, string) (bool, error)
	// @param (context, aliasName)
	DoesAliasExists(context.Context, string) bool
	// @param (context, templateName)
	DeleteTemplate(context.Context, string) error
	// @param (context, aliasName)
	RemoveAlias(context.Context, string, string) error
	// @param (context, aliasName)
	CreateAlias(context.Context, string, string) error
	// @param (context, cursorID)
	GetNodeBasics(context.Context, string) ([]NodeBasics, error)
	// @param (context, indexName)
	GetAllTimeseriesIndiceNames(context.Context, string) ([]string, error)
	// @param (context, nodeID)
	RecordLivenessPing(context.Context, Liveness) error
	// @param (context, instanceID)
	FindNodeIDByInstanceId(context.Context, string) ([]string, error)
	// @param (context, filter)
	FindNodeIDsByFields(context.Context, map[string]string) ([]string, error)
	// @param (data)
	CreateBulkNodeUpdateRequest(Node) elastic.BulkableRequest
	// @param (data)
	CreateBulkNodeAttributeUpdateRequest(NodeAttribute) elastic.BulkableRequest
	// @param (data)
	CreateBulkNodeRunInfoUpdateRequest(Run) elastic.BulkableRequest
	// @param (data)
	CreateBulkRunUpdateRequest(Run) elastic.BulkableRequest
	// @param (context, bulkableRequests)
	SendBulkRequest(context.Context, []elastic.BulkableRequest) error
	// @param (context, projectRules)
	UpdateNodeProjectTags(context.Context, map[string]*authz.ProjectRules) (string, error)
	// @param (context, jobID)
	JobStatus(context.Context, string) (project_update_lib.JobStatus, error)
	// @param (context, jobID)
	JobCancel(context.Context, string) error

	UpdateProjectTags(context.Context, map[string]*authz.ProjectRules) ([]string, error)

	// Migration contracts
	ReindexInsightstoConvergeHistory(context.Context, string, string) error
	GetInsightsRunData(context.Context, string, string) ([]InsightsRunNodePayLoadData, error)
	GetLatestA1NodeRun(context.Context, string, string) (InsightsRun, bool, error)
	ReindexNodeStateA1(context.Context, string) error
	UpdateNode(context.Context, string, InsightsRun, []VersionedCookbook) error
	EmptyNodeLatestRunID(context.Context, string) error
	ReindexInsightstoActions(context.Context, string, string) error
	RefreshIndex(context.Context, string) error
	GetNodeCount(context.Context, string) (int64, error)
	// @param (context, previousIndex)
	// @return (taskID, error)
	ReindexNodeStateToLatest(context.Context, string) (string, error)
	GetActions(string, int, time.Time, string, bool) ([]InternalChefAction, int64, error)
	DeleteAllIndexesWithPrefix(string, context.Context) error
}

type Deprecation

type Deprecation struct {
	Message  string `json:"message"`
	URL      string `json:"url"`
	Location string `json:"location"`
}

type Ec2

type Ec2 struct {
	InstanceId                string      `json:"instance_id"`
	InstanceType              string      `json:"instance_type"`
	PublicIpv4                interface{} `json:"public_ipv4"` // An interface bc ES type is `ip`
	PlacementAvailabilityZone string      `json:"placement_availability_zone"`
	Region                    string      `json:"region"`
	AccountID                 string      `json:"account_id"`
}

type ExpandedRunList

type ExpandedRunList struct {
	ID      string                   `json:"id"`
	RunList []ExpandedRunListRunList `json:"run_list"`
}

ExpandedRunList

type ExpandedRunListRunList

type ExpandedRunListRunList struct {
	Type     string                   `json:"type"`
	Name     string                   `json:"name"`
	Version  interface{}              `json:"version"`
	Skipped  bool                     `json:"skipped"`
	Children []ExpandedRunListRunList `json:"children,omitempty"`
}

type InsightsRun

type InsightsRun struct {
	RunID                string     `json:"run_id"`
	StartTime            time.Time  `json:"start_time"`
	EndTime              time.Time  `json:"end_time"`
	TotalResourceCount   int        `json:"total_resource_count"`
	UpdatedResourceCount int        `json:"updated_resource_count"`
	Node                 string     `json:"node"` // escaped json
	Resources            []Resource `json:"resources"`
}

InsightsRun - converge data pulled from an A1 insights index.

type InsightsRunNodePayLoadData

type InsightsRunNodePayLoadData struct {
	RunID string `json:"run_id"`
	Node  string `json:"node"` // escaped json
}

type InternalChefAction

type InternalChefAction struct {
	Id               string    `json:"id"`
	MessageType      string    `json:"message_type,omitempty"`
	MessageVersion   string    `json:"message_version,omitempty"`
	EntityName       string    `json:"entity_name,omitempty"`
	EntityType       string    `json:"entity_type,omitempty"`
	ParentName       string    `json:"parent_name,omitempty"`
	ParentType       string    `json:"parent_type,omitempty"`
	Task             string    `json:"task,omitempty"`
	OrganizationName string    `json:"organization_name,omitempty"`
	RemoteHostname   string    `json:"remote_hostname,omitempty"`
	RunId            string    `json:"run_id,omitempty"`
	NodeId           string    `json:"node_id,omitempty"`
	RecordedAt       time.Time `json:"recorded_at,omitempty"`
	RemoteRequestId  string    `json:"remote_request_id,omitempty"`
	RequestId        string    `json:"request_id,omitempty"`
	RequestorName    string    `json:"requestor_name,omitempty"`
	RequestorType    string    `json:"requestor_type,omitempty"`
	RevisionId       string    `json:"revision_id,omitempty"`
	ServiceHostname  string    `json:"service_hostname,omitempty"`
	UserAgent        string    `json:"user_agent,omitempty"`
	Data             string    `json:"data,omitempty"`
	Projects         []string  `json:"projects"`
}

type Liveness

type Liveness struct {
	NodeID          string    `json:"entity_uuid"`
	Checkin         time.Time `json:"checkin"`
	LivenessManaged bool      `json:"liveness_managed"`
	Organization    string    `json:"organization_name"`
	NodeName        string    `json:"node_name"`
	SourceFQDN      string    `json:"source_fqdn"`
}

Liveness node ping message

type Node

type Node struct {
	NodeInfo
	Checkin           time.Time `json:"checkin"`
	LatestRunID       string    `json:"latest_run_id"`
	Exists            bool      `json:"exists"`
	Attributes        []string  `json:"attributes"`
	Ec2               Ec2       `json:"ec2,omitempty"`
	LastCCRReceived   time.Time `json:"lastCCRReceived,omitempty"`
	LivenessManaged   bool      `json:"liveness_managed,omitempty"`
	CloudID           string    `json:"cloud_id,omitempty"`
	CloudAccountID    string    `json:"cloud_account_id,omitempty"`
	CloudRegion       string    `json:"cloud_region,omitempty"`
	HasDeprecations   bool      `json:"has_deprecations"`
	DeprecationsCount int       `json:"deprecations_count"`
	Projects          []string  `json:"projects"`
	ErrorMessage      string    `json:"error_message"`
	ErrorType         string    `json:"error_type"`
}

Node is the representation of a Node

type NodeAttribute

type NodeAttribute struct {
	EntityUUID          string    `json:"entity_uuid"`
	Name                string    `json:"name"`
	RunList             []string  `json:"run_list"`
	ChefEnvironment     string    `json:"chef_environment"`
	Normal              string    `json:"normal"`
	NormalValueCount    int       `json:"normal_value_count"`
	Default             string    `json:"default"`
	DefaultValueCount   int       `json:"default_value_count"`
	Override            string    `json:"override"`
	OverrideValueCount  int       `json:"override_value_count"`
	Automatic           string    `json:"automatic"`
	AutomaticValueCount int       `json:"automatic_value_count"`
	AllValueCount       int       `json:"all_value_count"`
	LastUpdate          time.Time `json:"last_update"`
}

NodeAttribute is the representation of the attributes of a Node

func CreateNodeAttribute

func CreateNodeAttribute(nodePayload NodePayload, entityUUID string) (attribute NodeAttribute, err error)

CreateNodeAttribute crate the NodeAttribute from the NodePayload

type NodeBasics

type NodeBasics struct {
	EntityUuid string    `json:"entity_uuid"`
	Checkin    time.Time `json:"checkin"`
}

type NodeInfo

type NodeInfo struct {
	EntityUuid       string   `json:"entity_uuid"`
	EventAction      string   `json:"event_action"`
	NodeName         string   `json:"node_name"`
	OrganizationName string   `json:"organization_name"`
	RunList          []string `json:"run_list"`
	Source           string   `json:"source"`
	// In the backend, status may be modified by other systems/processes and have
	// new values, for example to mark a node missing
	Status string `json:"status"`
	// ChefRunStatus should not be modified and should always contain the Chef
	// Run's success/failure outcome. This is used to with elasticsearch
	// aggregations to compute success/failure statistics across different node
	// cohorts
	ChefRunStatus         string              `json:"chef_run_status"`
	TotalResourceCount    int                 `json:"total_resource_count"`
	Deprecations          []Deprecation       `json:"deprecations,omitempty"`
	Error                 ChefError           `json:"error,omitempty"`
	Tags                  []string            `json:"tags,omitempty"`
	ResourceNames         []string            `json:"resource_names"`
	Recipes               []string            `json:"recipes"`
	ChefTags              []string            `json:"chef_tags"`
	Cookbooks             []string            `json:"cookbooks"`
	Platform              string              `json:"platform"`
	PlatformFamily        string              `json:"platform_family"`
	PlatformVersion       string              `json:"platform_version"`
	ChefVersion           string              `json:"chef_version"`
	UptimeSeconds         int64               `json:"uptime_seconds"`
	Environment           string              `json:"environment"`
	Roles                 []string            `json:"roles"`
	PolicyName            string              `json:"policy_name"`
	PolicyGroup           string              `json:"policy_group"`
	PolicyRevision        string              `json:"policy_revision"`
	Fqdn                  string              `json:"fqdn"`
	Ipaddress             interface{}         `json:"ipaddress"`
	SourceFqdn            string              `json:"source_fqdn"`
	ExpandedRunList       ExpandedRunList     `json:"expanded_run_list"`
	Timestamp             time.Time           `json:"timestamp"`
	VersionedCookbooks    []VersionedCookbook `json:"versioned_cookbooks"`
	CloudProvider         string              `json:"cloud_provider"`
	Timezone              string              `json:"timezone"`
	KernelRelease         string              `json:"kernel_release"`
	KernelVersion         string              `json:"kernel_version"`
	VirtualizationSystem  string              `json:"virtualization_system"`
	VirtualizationRole    string              `json:"virtualization_role"`
	DmiSystemManufacturer string              `json:"dmi_system_manufacturer"`
	DmiSystemSerialNumber string              `json:"dmi_system_serial_number"`
	Domain                string              `json:"domain"`
	Hostname              string              `json:"hostname"`
	Macaddress            string              `json:"macaddress"`
	MemoryTotal           string              `json:"memory_total"`
	Ip6address            interface{}         `json:"ip6address"`
}

NodeInfo defines common fields between Run and Node types

type NodePayload

type NodePayload struct {
	Name            string                 `json:"name"`
	ChefEnvironment string                 `json:"chef_environment"`
	PolicyName      string                 `json:"policy_name"`
	PolicyGroup     string                 `json:"policy_group"`
	RunList         []string               `json:"run_list"`
	Normal          map[string]interface{} `json:"normal"`
	Default         map[string]interface{} `json:"default"`
	Override        map[string]interface{} `json:"override"`
	Automatic       map[string]interface{} `json:"automatic"`
}

NodePayload is the ohai information reported in a chef client converge message

type NodeRunDateInfo

type NodeRunDateInfo struct {
	NodeID   string    `json:"node_uuid"`
	FirstRun time.Time `json:"first_run"`
	LastRun  time.Time `json:"last_run"`
}

NodeRunDateInfo The node data to store latest run datetime in elasticsearch

type Resource

type Resource struct {
	Type            string    `json:"type"`
	Name            string    `json:"name"`
	ID              string    `json:"id"`
	Duration        string    `json:"duration"`
	Delta           string    `json:"delta"`
	IgnoreFailure   bool      `json:"ignore_failure,omitempty"`
	Result          string    `json:"result"`
	Status          string    `json:"status"`
	CookbookName    string    `json:"cookbook_name,omitempty"`
	CookbookVersion string    `json:"cookbook_version,omitempty"`
	CookbookType    string    `json:"cookbook_type,omitempty"`
	RecipeName      string    `json:"recipe_name,omitempty"`
	Conditional     string    `json:"conditional,omitempty"`
	Error           ChefError `json:"error,omitempty"`
}

Resource is the representation of a Chef Resource

type Run

type Run struct {
	NodeInfo
	Resources            []Resource `json:"resources"`
	RunID                string     `json:"run_id"`
	StartTime            time.Time  `json:"start_time"`
	EndTime              time.Time  `json:"end_time"`
	UpdatedResourceCount int        `json:"updated_resource_count"`
}

Run is the representation of a Run

type UpsertNode

type UpsertNode struct {
	Node
	Created time.Time `json:"created,omitempty"`
}

UpsertNode The node data used when the node is first created in the node-state index.

type VersionedCookbook

type VersionedCookbook struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

VersionedCookbook links cookbook names and versions

func VersionedCookbooks

func VersionedCookbooks(nodePayload NodePayload) []VersionedCookbook

VersionedCookbooks returns an array of VersionedCookbooks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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