本文整理匯總了Golang中github.com/mozilla-services/reaper/reaperlog.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getVolumes
func getVolumes() chan *reaperaws.Volume {
ch := make(chan *reaperaws.Volume)
go func() {
volumeCh := reaperaws.AllVolumes()
regionSums := make(map[reapable.Region]int)
volumeSizeSums := make(map[reapable.Region]map[int64]int)
filteredCount := make(map[reapable.Region]int)
whitelistedCount := make(map[reapable.Region]int)
for volume := range volumeCh {
// make the map if it is not initialized
if volumeSizeSums[volume.Region()] == nil {
volumeSizeSums[volume.Region()] = make(map[int64]int)
}
regionSums[volume.Region()]++
if isWhitelisted(volume) {
whitelistedCount[volume.Region()]++
}
volumeSizeSums[volume.Region()][*volume.Size]++
if matchesFilters(volume) {
filteredCount[volume.Region()]++
}
ch <- volume
}
for region, sum := range regionSums {
log.Info("Found %d total volumes in %s", sum, region)
}
go func() {
for region, regionMap := range volumeSizeSums {
for volumeType, volumeSizeSum := range regionMap {
err := reaperevents.NewStatistic("reaper.volumes.total",
float64(volumeSizeSum),
[]string{fmt.Sprintf("region:%s,volumesize:%d", region, volumeType)})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.volumes.filtered",
float64(filteredCount[region]),
[]string{fmt.Sprintf("region:%s,volumesize:%d", region, volumeType)})
if err != nil {
log.Error(err.Error())
}
}
err := reaperevents.NewStatistic("reaper.volumes.whitelistedCount",
float64(whitelistedCount[region]),
[]string{fmt.Sprintf("region:%s", region)})
if err != nil {
log.Error(err.Error())
}
}
}()
close(ch)
}()
return ch
}
示例2: getSecurityGroups
func getSecurityGroups() chan *reaperaws.SecurityGroup {
ch := make(chan *reaperaws.SecurityGroup)
go func() {
securityGroupCh := reaperaws.AllSecurityGroups()
regionSums := make(map[reapable.Region]int)
filteredCount := make(map[reapable.Region]int)
whitelistedCount := make(map[reapable.Region]int)
for sg := range securityGroupCh {
regionSums[sg.Region()]++
if isWhitelisted(sg) {
whitelistedCount[sg.Region()]++
}
if matchesFilters(sg) {
filteredCount[sg.Region()]++
}
ch <- sg
}
for region, sum := range regionSums {
log.Info("Found %d total SecurityGroups in %s", sum, region)
}
go func() {
for region, regionSum := range regionSums {
err := reaperevents.NewStatistic("reaper.securitygroups.total",
float64(regionSum),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.securitygroups.whitelistedCount",
float64(whitelistedCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.securitygroups.filtered",
float64(filteredCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
}
}()
close(ch)
}()
return ch
}
示例3: AllSecurityGroups
// AllSecurityGroups describes every instance in the requested regions
// *SecurityGroups are created for each *ec2.SecurityGroup
// and are passed to a channel
func AllSecurityGroups() chan *SecurityGroup {
ch := make(chan *SecurityGroup, len(config.Regions))
// waitgroup for all regions
wg := sync.WaitGroup{}
for _, region := range config.Regions {
wg.Add(1)
go func(region string) {
defer wg.Done()
// add region to waitgroup
api := ec2.New(sess, aws.NewConfig().WithRegion(region))
resp, err := api.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{})
for _, sg := range resp.SecurityGroups {
ch <- NewSecurityGroup(region, sg)
}
if err != nil {
// probably should do something here...
log.Error(err.Error())
}
}(region)
}
go func() {
// in a separate goroutine, wait for all regions to finish
// when they finish, close the chan
wg.Wait()
close(ch)
}()
return ch
}
示例4: getCloudformations
func getCloudformations() chan *reaperaws.Cloudformation {
ch := make(chan *reaperaws.Cloudformation)
go func() {
cfs := reaperaws.AllCloudformations()
regionSums := make(map[reapable.Region]int)
filteredCount := make(map[reapable.Region]int)
whitelistedCount := make(map[reapable.Region]int)
for cf := range cfs {
if isWhitelisted(cf) {
whitelistedCount[cf.Region()]++
}
regionSums[cf.Region()]++
if matchesFilters(cf) {
filteredCount[cf.Region()]++
}
ch <- cf
}
for region, sum := range regionSums {
log.Info("Found %d total Cloudformation Stacks in %s", sum, region)
}
go func() {
for region, regionSum := range regionSums {
err := reaperevents.NewStatistic("reaper.cloudformations.total",
float64(regionSum),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.cloudformations.filtered",
float64(filteredCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.cloudformations.whitelistedCount",
float64(whitelistedCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
}
}()
close(ch)
}()
return ch
}
示例5: matchesFilters
// matchesFilters applies the relevant filter groups to a filterable
func matchesFilters(filterable filters.Filterable) bool {
// recover from potential panics caused by malformed filters
defer func() {
if r := recover(); r != nil {
log.Error("Recovered in matchesFilters with panic: ", r)
}
}()
var groups map[string]filters.FilterGroup
switch filterable.(type) {
case *reaperaws.Instance:
groups = config.Instances.FilterGroups
case *reaperaws.AutoScalingGroup:
groups = config.AutoScalingGroups.FilterGroups
case *reaperaws.Cloudformation:
groups = config.Cloudformations.FilterGroups
case *reaperaws.SecurityGroup:
groups = config.SecurityGroups.FilterGroups
case *reaperaws.Volume:
groups = config.Volumes.FilterGroups
default:
log.Warning("You probably screwed up and need to make sure matchesFilters works!")
return false
}
matched := false
// if there are no filters groups defined default to not match
if len(groups) == 0 {
return false
}
shouldFilter := false
for _, group := range groups {
if len(group) > 0 {
// there is a filter
shouldFilter = true
}
}
// no filters, default to not match
if !shouldFilter {
return false
}
for name, group := range groups {
didMatch := filters.ApplyFilters(filterable, group)
if didMatch {
matched = true
filterable.AddFilterGroup(name, group)
}
}
// convenient
if isWhitelisted(filterable) {
matched = false
}
return matched
}
示例6: AWSConsoleURL
// AWSConsoleURL returns the url that can be used to access the resource on the AWS Console
func (a *AutoScalingGroup) AWSConsoleURL() *url.URL {
url, err := url.Parse(fmt.Sprintf("https://%s.console.aws.amazon.com/ec2/autoscaling/home?region=%s#AutoScalingGroups:id=%s;view=details",
a.Region().String(), a.Region().String(), url.QueryEscape(a.ID().String())))
if err != nil {
log.Error("Error generating AWSConsoleURL. ", err)
}
return url
}
示例7: AWSConsoleURL
// AWSConsoleURL returns the url that can be used to access the resource on the AWS Console
func (a *Instance) AWSConsoleURL() *url.URL {
url, err := url.Parse(fmt.Sprintf("https://%s.console.aws.amazon.com/ec2/v2/home?region=%s#Instances:instanceId=%s",
a.Region().String(), a.Region().String(), url.QueryEscape(a.ID().String())))
if err != nil {
log.Error("Error generating AWSConsoleURL. ", err)
}
return url
}
示例8: BoolValue
func (filter *Filter) BoolValue(v int) (bool, error) {
b, err := strconv.ParseBool(filter.Arguments[v])
if err != nil {
log.Error(fmt.Sprintf("could not parse %s as bool", filter.Arguments[v]))
return false, err
}
return b, nil
}
示例9: Int64Value
func (filter *Filter) Int64Value(v int) (int64, error) {
// parseint -> base 10, 64 bit int
i, err := strconv.ParseInt(filter.Arguments[v], 10, 64)
if err != nil {
log.Error(fmt.Sprintf("could not parse %s as int64", filter.Arguments[v]))
return 0, err
}
return i, nil
}
示例10: AWSConsoleURL
// AWSConsoleURL returns the url that can be used to access the resource on the AWS Console
func (a *Cloudformation) AWSConsoleURL() *url.URL {
url, err := url.Parse("https://console.aws.amazon.com/cloudformation/home")
// setting RawQuery because QueryEscape messes with the "/"s in the url
url.RawQuery = fmt.Sprintf("region=%s#/stacks?filter=active&tab=overview&stackId=%s", a.Region().String(), a.ID().String())
if err != nil {
log.Error("Error generating AWSConsoleURL. ", err)
}
return url
}
示例11: getGodspeed
func (e *Datadog) getGodspeed() {
var gs *godspeed.Godspeed
var err error
// if config options not set, use defaults
if e.Config.Host == "" || e.Config.Port == "" {
gs, err = godspeed.NewDefault()
} else {
port, err := strconv.Atoi(e.Config.Port)
if err != nil {
log.Error(err.Error())
}
gs, err = godspeed.New(e.Config.Host, port, false)
}
if err != nil {
log.Error(err.Error())
}
e._godspeed = gs
}
示例12: Ready
// Ready NEEDS to be called for EventReporters and Reapables to be properly initialized
// which means events AND config need to be set BEFORE Ready
func Ready() {
reaperevents.SetDryRun(config.DryRun)
if r := reapable.NewReapables(config.AWS.Regions); r != nil {
reapables = *r
} else {
log.Error("reapables improperly initialized")
}
}
示例13: makeWhitelistLink
// MakeWhitelistLink creates a tokenized link for whitelisting
func makeWhitelistLink(region reapable.Region, id reapable.ID, tokenSecret, apiURL string) (string, error) {
whitelist, err := token.Tokenize(tokenSecret,
token.NewWhitelistJob(region.String(), id.String()))
if err != nil {
log.Error("Error creating whitelist link: ", err)
return "", err
}
return makeURL(apiURL, "whitelist", whitelist), nil
}
示例14: Cleanup
func Cleanup() {
for _, er := range *eventReporters {
c, ok := er.(Cleaner)
if ok {
if err := c.Cleanup(); err != nil {
log.Error(err.Error())
}
}
}
}
示例15: makeStopLink
// MakeStopLink creates a tokenized link for stopping
func makeStopLink(region reapable.Region, id reapable.ID, tokenSecret, apiURL string) (string, error) {
stop, err := token.Tokenize(tokenSecret,
token.NewStopJob(region.String(), id.String()))
if err != nil {
log.Error("Error creating ScaleToZero link: ", err)
return "", err
}
return makeURL(apiURL, "stop", stop), nil
}