backend

package
v0.0.0-...-0490640 Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

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"`
}

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) Cookbooks

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

Cookbooks returns an array of strings containing the names of cookbooks

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) 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

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 {
	// @param None
	Initializing() bool
	// @param (context, UTC time)
	InitializeStore(context.Context)
	// @param (context, UTC time, data)
	InsertNode(context.Context, Node) error
	// @param (context, UTC time, data)
	InsertRun(context.Context, Run) error
	// @param (context, UTC time, data)
	InsertNodeAttribute(context.Context, NodeAttribute) error
	// @param (context, backend.InternalChefAction)
	InsertAction(context.Context, InternalChefAction) error
	// @param (context, threshold)
	MarkNodesMissing(context.Context, string) (int, error)
	// @param (context, threshold)
	DeleteMarkedNodes(context.Context, string) (int, error)
	// @param (context, threshold)
	MarkMissingNodesForDeletion(context.Context, string) (int, 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 (data)
	CreateBulkNodeUpdateRequest(Node) elastic.BulkableRequest
	// @param (data)
	CreateBulkNodeAttributeUpdateRequest(NodeAttribute) elastic.BulkableRequest
	// @param (data)
	CreateBulkRunUpdateRequest(Run) elastic.BulkableRequest
	// @param (data)
	CreateBulkActionRequest(InternalChefAction) elastic.BulkableRequest
	// @param (context, bulkableRequests)
	SendBulkRequest(context.Context, []elastic.BulkableRequest) error
	// @param (context, projectRules)
	UpdateNodeProjectTags(context.Context, map[string]*iam_v2.ProjectRules) (string, error)
	// @param (context, projectRules)
	UpdateActionProjectTags(context.Context, map[string]*iam_v2.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]*iam_v2.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)
	ReindexNodeStateToLatest(context.Context, string) 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"`
}

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"`
	HasDeprecations   bool      `json:"has_deprecations"`
	DeprecationsCount int       `json:"deprecations_count"`
	Projects          []string  `json:"projects"`
}

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"`
	Status             string              `json:"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"`
}

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 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"`
}

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 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