Documentation
¶
Index ¶
- Constants
- Variables
- func FormatCost2DP(currency string, d *decimal.Decimal) string
- func FormatOutput(format string, r Report, opts Options) ([]byte, error)
- func LoadCommentData(path string) (string, error)
- func ToDiff(out Report, opts Options) ([]byte, error)
- func ToHTML(out Report, opts Options) ([]byte, error)
- func ToJSON(out Report, opts Options) ([]byte, error)
- func ToSlackMessage(out Report, opts Options) ([]byte, error)
- func ToTable(out Report, opts Options) ([]byte, error)
- type ActualCosts
- type Breakdown
- type CostComponent
- type GovernanceFailures
- type MarkdownCtx
- type MarkdownOptions
- type MarkdownOutput
- type Metadata
- type Options
- type PolicyCheck
- type PolicyCheckFailures
- type PolicyCheckOutput
- type PolicyCheckResourceDetails
- type PolicyCheckViolations
- type PolicyOutput
- type Project
- type Projects
- type Report
- type ReportInput
- type Resource
- type Summary
- type SummaryOptions
- type TagPropagation
Constants ¶
const ( UPDATED = iota ADDED REMOVED )
Variables ¶
var ( // Technically Github allows 66536 characters, which we interpreted as 262144 bytes, but // we were still seeing 422 "Body is too long (maximum is 65536 characters)" errors so limit // more. GitHubMaxMessageSize = 200000 // bytes // Azure supports 150000 characters, which for ASCII is 150000 bytes, lets err on the side of caution and // limit to 140000 bytes. AzureReposMaxMessageSize = 140000 // bytes )
Functions ¶
func FormatOutput ¶
FormatOutput returns Root r as the format specified. The default format is a table output.
func LoadCommentData ¶
LoadCommentData reads the file at the path into a string.
Types ¶
type ActualCosts ¶
type Breakdown ¶
type Breakdown struct {
Resources []Resource `json:"resources"`
FreeResources []Resource `json:"freeResources,omitempty"`
TotalHourlyCost *decimal.Decimal `json:"totalHourlyCost"`
TotalMonthlyCost *decimal.Decimal `json:"totalMonthlyCost"`
TotalMonthlyUsageCost *decimal.Decimal `json:"totalMonthlyUsageCost"`
}
func (*Breakdown) HasResources ¶
HasResources returns true if the breakdown has any resources or free resources. This is used to determine if the breakdown should be shown in the output.
func (*Breakdown) TotalMonthlyBaselineCost ¶
type CostComponent ¶
type CostComponent struct {
Name string `json:"name"`
Unit string `json:"unit"`
HourlyQuantity *decimal.Decimal `json:"hourlyQuantity"`
MonthlyQuantity *decimal.Decimal `json:"monthlyQuantity"`
Price decimal.Decimal `json:"price"`
HourlyCost *decimal.Decimal `json:"hourlyCost"`
MonthlyCost *decimal.Decimal `json:"monthlyCost"`
UsageBased bool `json:"usageBased,omitempty"`
PriceNotFound bool `json:"priceNotFound"`
}
type GovernanceFailures ¶
type GovernanceFailures []string
GovernanceFailures defines a list of governance failures that were returned from c3x cloud.
func (GovernanceFailures) Error ¶
func (g GovernanceFailures) Error() string
Error implements the Error interface returning the failures as a single message that can be used in stderr.
type MarkdownCtx ¶
type MarkdownCtx struct {
Root Report
SkippedProjectCount int
ErroredProjectCount int
SkippedUnchangedProjectCount int
DiffOutput string
Options Options
MarkdownOptions MarkdownOptions
RunQuotaMsg string
UsageCostsMsg string
CostDetailsMsg string
}
MarkdownCtx holds information that can be used and executed with a go template.
type MarkdownOptions ¶
type MarkdownOutput ¶
MarkdownOutput holds the message converted to markdown with additional information about its length.
func ToMarkdown ¶
func ToMarkdown(out Report, opts Options, markdownOpts MarkdownOptions) (MarkdownOutput, error)
type Metadata ¶
type Metadata struct {
C3XCommand string `json:"c3xCommand"`
Branch string `json:"vcsBranch"`
BaseCommitSHA string `json:"vcsBaseCommitSha,omitempty"`
CommitSHA string `json:"vcsCommitSha"`
CommitAuthorName string `json:"vcsCommitAuthorName"`
CommitAuthorEmail string `json:"vcsCommitAuthorEmail"`
CommitTimestamp time.Time `json:"vcsCommitTimestamp"`
CommitMessage string `json:"vcsCommitMessage"`
VCSRepositoryURL string `json:"vcsRepositoryUrl,omitempty"`
VCSProvider string `json:"vcsProvider,omitempty"`
VCSBaseBranch string `json:"vcsBaseBranch,omitempty"`
VCSPullRequestTitle string `json:"vcsPullRequestTitle,omitempty"`
VCSPullRequestURL string `json:"vcsPullRequestUrl,omitempty"`
VCSPullRequestAuthor string `json:"vcsPullRequestAuthor,omitempty"`
VCSPullRequestLabels []string `json:"vcsPullRequestLabels,omitempty"`
VCSPipelineRunID string `json:"vcsPipelineRunId,omitempty"`
VCSPullRequestID string `json:"vcsPullRequestId,omitempty"`
UsageApiEnabled bool `json:"usageApiEnabled,omitempty"`
UsageFilePath string `json:"usageFilePath,omitempty"`
ConfigFilePath string `json:"configFilePath,omitempty"`
ConfigFileHasUsageFile bool `json:"configFileHasUsageFile,omitempty"`
}
Metadata holds common information used to identify the system that C3X is run within.
func NewMetadata ¶
NewMetadata returns a Metadata struct filled with information built from the RunContext.
type PolicyCheck ¶
type PolicyCheck struct {
Enabled bool
Failures PolicyCheckFailures
Passed []string
}
PolicyCheck holds information if a given run has any policy checks enabled. This struct is used in templates to create useful cost policy outputs.
func (PolicyCheck) HasFailed ¶
func (p PolicyCheck) HasFailed() bool
HasFailed returns if the PolicyCheck has any cost policy failures
type PolicyCheckFailures ¶
type PolicyCheckFailures []string
PolicyCheckFailures defines a list of policy check failures that can be collected from a policy evaluation.
func (PolicyCheckFailures) Error ¶
func (p PolicyCheckFailures) Error() string
Error implements the Error interface returning the failures as a single message that can be used in stderr.
type PolicyCheckOutput ¶
type PolicyCheckResourceDetails ¶
type PolicyCheckResourceDetails struct {
Address string
ResourceType string
Path string
Line int
Violations []PolicyCheckViolations
}
type PolicyCheckViolations ¶
type PolicyOutput ¶
type PolicyOutput struct {
HasFailures bool
HasWarnings bool
Checks []PolicyCheckOutput
}
PolicyOutput holds normalized PolicyCheck and TagPolicyCheck data so it can be output in a uniform "Policies" section of the c3x comment.
func NewPolicyOutput ¶
func NewPolicyOutput(pc PolicyCheck) PolicyOutput
NewPolicyOutput normalizes a PolicyCheck suitable for use in the output markdown template.
type Project ¶
type Project struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Metadata *engine.WorkspaceMeta `json:"metadata"`
PastBreakdown *Breakdown `json:"pastBreakdown"`
Breakdown *Breakdown `json:"breakdown"`
Diff *Breakdown `json:"diff"`
Summary *Summary `json:"summary"`
// contains filtered or unexported fields
}
func (*Project) LabelWithMetadata ¶
LabelWithMetadata returns the display name of the project appended with any distinguishing metadata (Module path or Workspace)
func (*Project) ToSchemaProject ¶
ToSchemaProject generates a engine.Workspace from a Project. The created engine.Workspace is not suitable to be used outside simple engine.Workspace to engine.Workspace comparisons. It contains missing information that cannot be inferred from a Project.
type Projects ¶
type Projects []Project
func (Projects) IsRunQuotaExceeded ¶
IsRunQuotaExceeded checks if any of the project metadata have errored with a "run quota exceeded" error. If found it returns the associated message with this diag. This should be used when in any output that notifies the user.
type Report ¶
type Report struct {
Version string `json:"version"`
Metadata Metadata `json:"metadata"`
RunID string `json:"runId,omitempty"`
CloudURL string `json:"cloudUrl,omitempty"`
Currency string `json:"currency"`
Projects Projects `json:"projects"`
TotalHourlyCost *decimal.Decimal `json:"totalHourlyCost"`
TotalMonthlyCost *decimal.Decimal `json:"totalMonthlyCost"`
TotalMonthlyUsageCost *decimal.Decimal `json:"totalMonthlyUsageCost,omitempty"`
PastTotalHourlyCost *decimal.Decimal `json:"pastTotalHourlyCost"`
PastTotalMonthlyCost *decimal.Decimal `json:"pastTotalMonthlyCost"`
PastTotalMonthlyUsageCost *decimal.Decimal `json:"pastTotalMonthlyUsageCost,omitempty"`
DiffTotalHourlyCost *decimal.Decimal `json:"diffTotalHourlyCost"`
DiffTotalMonthlyCost *decimal.Decimal `json:"diffTotalMonthlyCost"`
DiffTotalMonthlyUsageCost *decimal.Decimal `json:"diffTotalMonthlyUsageCost,omitempty"`
TimeGenerated time.Time `json:"timeGenerated"`
Summary *Summary `json:"summary"`
FullSummary *Summary `json:"-"`
IsCIRun bool `json:"-"`
}
func Combine ¶
func Combine(inputs []ReportInput) (Report, error)
func CompareTo ¶
CompareTo generates an output Root using another Root as the base snapshot. Each project in current Root will have all past resources overwritten with the matching projects in the prior Root. If we can't find a matching project then we assume that the project has been newly created and will show a 100% increase in the output Root.
func Load ¶
Load reads the file at the location p and the file body into a Root struct. Load naively validates that the C3X JSON body is valid by checking the that the version attribute is within a supported range.
func ToOutputFormat ¶
func (*Report) ExampleProjectName ¶
func (*Report) HasDiff ¶
HasDiff returns true if any project has a difference in monthly cost or resources
func (*Report) HasUnsupportedResources ¶
HasUnsupportedResources returns if the summary has any unsupported resources. This is used to determine if the summary should be shown in different output formats.
type ReportInput ¶
func LoadPaths ¶
func LoadPaths(paths []string) ([]ReportInput, error)
type Resource ¶
type Resource struct {
Name string `json:"name"`
ResourceType string `json:"resourceType,omitempty"`
Tags *map[string]string `json:"tags,omitempty"`
DefaultTags *map[string]string `json:"defaultTags,omitempty"`
TagPropagation *TagPropagation `json:"tagPropagation,omitempty"`
ProviderSupportsDefaultTags bool `json:"providerSupportsDefaultTags,omitempty"`
ProviderLink string `json:"providerLink,omitempty"`
Metadata map[string]interface{} `json:"metadata"`
HourlyCost *decimal.Decimal `json:"hourlyCost,omitempty"`
MonthlyCost *decimal.Decimal `json:"monthlyCost,omitempty"`
MonthlyUsageCost *decimal.Decimal `json:"monthlyUsageCost,omitempty"`
CostComponents []CostComponent `json:"costComponents,omitempty"`
ActualCosts []ActualCosts `json:"actualCosts,omitempty"`
SubResources []Resource `json:"subresources,omitempty"`
MissingVarsCausingUnknownTagKeys []string `json:"missingVarsCausingUnknownTagKeys,omitempty"`
MissingVarsCausingUnknownDefaultTagKeys []string `json:"missingVarsCausingUnknownDefaultTagKeys,omitempty"`
}
type Summary ¶
type Summary struct {
TotalResources *int `json:"totalResources,omitempty"`
TotalDetectedResources *int `json:"totalDetectedResources,omitempty"`
TotalSupportedResources *int `json:"totalSupportedResources,omitempty"`
TotalUnsupportedResources *int `json:"totalUnsupportedResources,omitempty"`
TotalUsageBasedResources *int `json:"totalUsageBasedResources,omitempty"`
TotalNoPriceResources *int `json:"totalNoPriceResources,omitempty"`
SupportedResourceCounts *map[string]int `json:"supportedResourceCounts,omitempty"`
UnsupportedResourceCounts *map[string]int `json:"unsupportedResourceCounts,omitempty"`
NoPriceResourceCounts *map[string]int `json:"noPriceResourceCounts,omitempty"`
EstimatedUsageCounts *map[string]int `json:"-"`
UnestimatedUsageCounts *map[string]int `json:"-"`
TotalEstimatedUsages *int `json:"-"`
TotalUnestimatedUsages *int `json:"-"`
}
func BuildSummary ¶
func BuildSummary(resources []*engine.Estimate, opts SummaryOptions) (*Summary, error)