costs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package costs gets billing information from an ElasticSearch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetElasticSearchParams

func GetElasticSearchParams(accountList []string, durationBegin time.Time,
	durationEnd time.Time, params []string, client *elastic.Client, index string) *elastic.SearchService

GetElasticSearchParams is used to construct an ElasticSearch *elastic.SearchService used to perform a request on ES It takes as paramters :

  • accountList []string : A slice of strings representing aws account number, in the format of the field 'awsdetailedlineitem.linked_account_id'
  • durationBeing time.Time : A time.Time struct representing the begining of the time range in the query
  • durationEnd time.Time : A time.Time struct representing the end of the time range in the query
  • param []string : A slice of strings representing the different parameters, in the nesting order, that will create aggregations. Those can be :
  • "product" : It will create a TermsAggregation on the field 'product_name'
  • "availabilityzone" : It will create a TermsAggregation on the field 'availability_zone'
  • "region" : It will create a TermsAggregation on the field 'region'
  • "account" : It will create a TermsAggregation on the field 'linked_account_id'
  • "tag:<TAG_KEY>" : It will create a FilterAggregation on the field 'tag.key', filtering on the value 'user:<TAG_KEY>'. It will then create a TermsAggregation on the field 'tag.value'
  • "[day|week|month|year]": It will create a DateHistogramAggregation on the specified duration on the field 'usage_start_date'
  • client *elastic.Client : an instance of *elastic.Client that represent an Elastic Search client. It needs to be fully configured and ready to execute a client.Search()
  • index string : The Elastic Search index on wich to execute the query. In this context the default value should be "awsdetailedlineitems"

This function excepts arguments passed to it to be sanitize. If they are not, the following cases will make it crash :

  • For the 'tag:<TAG_KEY>' param, if the separator is not present, or if there is no key that is passed to it, the program will crash
  • If a param in the slice is not present in the detailedLineItemsFieldsName, the program will crash.
  • If the client is nil or malconfigured, it will crash
  • If the index is not an index present in the ES, it will crash

func MakeElasticSearchRequestAndParseIt

func MakeElasticSearchRequestAndParseIt(ctx context.Context, parsedParams EsQueryParams) (es.SimplifiedCostsDocument, int, error)

MakeElasticSearchRequestAndParseIt will make the actual request to the ElasticSearch parse the results and return them It will return the data, an http status code (as int) and an error. Because an error can be generated, but is not critical and is not needed to be known by the user (e.g if the index does not exists because it was not yet indexed ) the error will be returned, but instead of having a 500 status code, it will return the provided status code with empy data

Types

type EsQueryParams

type EsQueryParams struct {
	DateBegin         time.Time
	DateEnd           time.Time
	AccountList       []string
	IndexList         []string
	AggregationParams []string
}

EsQueryParams will store the parsed query params

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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