vmware-go-kcl-v2/clientlibrary/metrics/cloudwatch/cloudwatch.go

380 lines
11 KiB
Go
Raw Normal View History

/*
* Copyright (c) 2018 VMware, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
2021-11-08 14:00:48 +00:00
// Package cloudwatch
// The implementation is derived from https://github.com/patrobinson/gokini
//
// Copyright 2018 Patrick robinson.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
package cloudwatch
import (
2021-11-08 15:27:29 +00:00
"context"
"sync"
"time"
2021-11-08 15:27:29 +00:00
"github.com/aws/aws-sdk-go-v2/aws"
cwatch "github.com/aws/aws-sdk-go-v2/service/cloudwatch"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/vmware/vmware-go-kcl-v2/logger"
)
2021-11-08 15:27:29 +00:00
// DefaultCloudwatchMetricsBufferDuration Buffer metrics for at most this long before publishing to CloudWatch.
const DefaultCloudwatchMetricsBufferDuration = 10 * time.Second
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
type MonitoringService struct {
appName string
streamName string
workerID string
region string
credentials aws.CredentialsProvider
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
logger logger.Logger
// control how often to publish to CloudWatch
bufferDuration time.Duration
stop *chan struct{}
waitGroup *sync.WaitGroup
2021-11-08 15:27:29 +00:00
svc *cwatch.Client
shardMetrics *sync.Map
}
type cloudWatchMetrics struct {
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
sync.Mutex
processedRecords int64
processedBytes int64
behindLatestMillis []float64
leasesHeld int64
leaseRenewals int64
getRecordsTime []float64
processRecordsTime []float64
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
// NewMonitoringService returns a Monitoring service publishing metrics to CloudWatch.
func NewMonitoringService(region string, creds aws.CredentialsProvider) *MonitoringService {
2021-11-08 15:27:29 +00:00
return NewMonitoringServiceWithOptions(region, creds, logger.GetDefaultLogger(), DefaultCloudwatchMetricsBufferDuration)
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
}
// NewMonitoringServiceWithOptions returns a Monitoring service publishing metrics to
// CloudWatch with the provided credentials, buffering duration and logger.
func NewMonitoringServiceWithOptions(region string, creds aws.CredentialsProvider, logger logger.Logger, bufferDur time.Duration) *MonitoringService {
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
return &MonitoringService{
region: region,
credentials: creds,
logger: logger,
bufferDuration: bufferDur,
}
}
func (cw *MonitoringService) Init(appName, streamName, workerID string) error {
cw.appName = appName
cw.streamName = streamName
cw.workerID = workerID
2021-11-08 15:27:29 +00:00
cfg := &aws.Config{Region: cw.region}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
cfg.Credentials = cw.credentials
2021-11-08 15:27:29 +00:00
cw.svc = cwatch.NewFromConfig(*cfg)
cw.shardMetrics = &sync.Map{}
stopChan := make(chan struct{})
cw.stop = &stopChan
wg := sync.WaitGroup{}
cw.waitGroup = &wg
return nil
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) Start() error {
cw.waitGroup.Add(1)
// entering eventloop for sending metrics to CloudWatch
go cw.eventloop()
return nil
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) Shutdown() {
cw.logger.Infof("Shutting down cloudwatch metrics system...")
close(*cw.stop)
cw.waitGroup.Wait()
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
cw.logger.Infof("Cloudwatch metrics system has been shutdown.")
}
2021-11-08 14:00:48 +00:00
// eventloop start daemon to flush metrics periodically
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) eventloop() {
defer cw.waitGroup.Done()
for {
if err := cw.flush(); err != nil {
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
cw.logger.Errorf("Error sending metrics to CloudWatch. %+v", err)
}
select {
case <-*cw.stop:
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
cw.logger.Infof("Shutting down monitoring system")
if err := cw.flush(); err != nil {
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
cw.logger.Errorf("Error sending metrics to CloudWatch. %+v", err)
}
return
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
case <-time.After(cw.bufferDuration):
}
}
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) flushShard(shard string, metric *cloudWatchMetrics) bool {
metric.Lock()
2021-11-08 15:27:29 +00:00
defaultDimensions := []types.Dimension{
{
Name: aws.String("Shard"),
Value: &shard,
},
{
Name: aws.String("KinesisStreamName"),
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
Value: &cw.streamName,
},
}
2021-11-08 15:27:29 +00:00
leaseDimensions := []types.Dimension{
{
Name: aws.String("Shard"),
Value: &shard,
},
{
Name: aws.String("KinesisStreamName"),
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
Value: &cw.streamName,
},
{
Name: aws.String("WorkerID"),
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
Value: &cw.workerID,
},
}
metricTimestamp := time.Now()
2021-11-08 15:27:29 +00:00
data := []types.MetricDatum{
{
Dimensions: defaultDimensions,
MetricName: aws.String("RecordsProcessed"),
2021-11-08 15:27:29 +00:00
Unit: types.StandardUnitCount,
Timestamp: &metricTimestamp,
Value: aws.Float64(float64(metric.processedRecords)),
},
{
Dimensions: defaultDimensions,
MetricName: aws.String("DataBytesProcessed"),
2021-11-08 15:27:29 +00:00
Unit: types.StandardUnitBytes,
Timestamp: &metricTimestamp,
Value: aws.Float64(float64(metric.processedBytes)),
},
{
Dimensions: leaseDimensions,
MetricName: aws.String("RenewLease.Success"),
2021-11-08 15:27:29 +00:00
Unit: types.StandardUnitCount,
Timestamp: &metricTimestamp,
Value: aws.Float64(float64(metric.leaseRenewals)),
},
{
Dimensions: leaseDimensions,
MetricName: aws.String("CurrentLeases"),
2021-11-08 15:27:29 +00:00
Unit: types.StandardUnitCount,
Timestamp: &metricTimestamp,
Value: aws.Float64(float64(metric.leasesHeld)),
},
}
if len(metric.behindLatestMillis) > 0 {
2021-11-08 15:27:29 +00:00
data = append(data, types.MetricDatum{
Dimensions: defaultDimensions,
MetricName: aws.String("MillisBehindLatest"),
2021-11-08 15:27:29 +00:00
Unit: types.StandardUnitMilliseconds,
Timestamp: &metricTimestamp,
2021-11-08 15:27:29 +00:00
StatisticValues: &types.StatisticSet{
SampleCount: aws.Float64(float64(len(metric.behindLatestMillis))),
Sum: sumFloat64(metric.behindLatestMillis),
Maximum: maxFloat64(metric.behindLatestMillis),
Minimum: minFloat64(metric.behindLatestMillis),
}})
}
if len(metric.getRecordsTime) > 0 {
2021-11-08 15:27:29 +00:00
data = append(data, types.MetricDatum{
Dimensions: defaultDimensions,
MetricName: aws.String("KinesisDataFetcher.getRecords.Time"),
2021-11-08 15:27:29 +00:00
Unit: types.StandardUnitMilliseconds,
Timestamp: &metricTimestamp,
2021-11-08 15:27:29 +00:00
StatisticValues: &types.StatisticSet{
SampleCount: aws.Float64(float64(len(metric.getRecordsTime))),
Sum: sumFloat64(metric.getRecordsTime),
Maximum: maxFloat64(metric.getRecordsTime),
Minimum: minFloat64(metric.getRecordsTime),
}})
}
if len(metric.processRecordsTime) > 0 {
2021-11-08 15:27:29 +00:00
data = append(data, types.MetricDatum{
Dimensions: defaultDimensions,
MetricName: aws.String("RecordProcessor.processRecords.Time"),
2021-11-08 15:27:29 +00:00
Unit: types.StandardUnitMilliseconds,
Timestamp: &metricTimestamp,
2021-11-08 15:27:29 +00:00
StatisticValues: &types.StatisticSet{
SampleCount: aws.Float64(float64(len(metric.processRecordsTime))),
Sum: sumFloat64(metric.processRecordsTime),
Maximum: maxFloat64(metric.processRecordsTime),
Minimum: minFloat64(metric.processRecordsTime),
}})
}
// Publish metrics data to cloud watch
2021-11-08 15:27:29 +00:00
_, err := cw.svc.PutMetricData(context.TODO(), &cwatch.PutMetricDataInput{
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
Namespace: aws.String(cw.appName),
MetricData: data,
})
if err == nil {
metric.processedRecords = 0
metric.processedBytes = 0
metric.behindLatestMillis = []float64{}
metric.leaseRenewals = 0
metric.getRecordsTime = []float64{}
metric.processRecordsTime = []float64{}
} else {
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
cw.logger.Errorf("Error in publishing cloudwatch metrics. Error: %+v", err)
}
metric.Unlock()
return true
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) flush() error {
cw.logger.Debugf("Flushing metrics data. Stream: %s, Worker: %s", cw.streamName, cw.workerID)
// publish per shard metrics
cw.shardMetrics.Range(func(k, v interface{}) bool {
shard, metric := k.(string), v.(*cloudWatchMetrics)
return cw.flushShard(shard, metric)
})
return nil
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) IncrRecordsProcessed(shard string, count int) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.processedRecords += int64(count)
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) IncrBytesProcessed(shard string, count int64) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.processedBytes += count
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) MillisBehindLatest(shard string, millSeconds float64) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.behindLatestMillis = append(m.behindLatestMillis, millSeconds)
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) LeaseGained(shard string) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.leasesHeld++
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) LeaseLost(shard string) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.leasesHeld--
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) LeaseRenewed(shard string) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.leaseRenewals++
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) RecordGetRecordsTime(shard string, time float64) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.getRecordsTime = append(m.getRecordsTime, time)
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) RecordProcessRecordsTime(shard string, time float64) {
m := cw.getOrCreatePerShardMetrics(shard)
m.Lock()
defer m.Unlock()
m.processRecordsTime = append(m.processRecordsTime, time)
}
Expose monitoring service (#49) * Remove MonitoringConfiguration and export no-op service MonitoringConfiguration is not needed anymore as the user directly implements its monitoring service or use one the default constructors. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor for CloudWatchMonitoringService Unexport all fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Provide a constructor to PrometheusMonitoringService Unexport fields Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove all CloudWatch specific-stuff from config package Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * NewWorker accepts a metrics.MonitoringService Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Add WithMonitoringService to config Instead of having an additional parameter to NewWorker so that the user can provide its own MonitoringService, WithMonitoringService is added to the configuration. This is much cleaner and remains in-line with the rest of the current API. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Fix tests after introduction of WithMonitoringService Also, fix tests that should have been fixed in earlier commits. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move Prometheus into its own package Also rename it to prometheus.MonitoringService to not have to repeat Prometheus twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Move CloudWatch metrics into its own package Also rename it to cloudwatch.MonitoringService to not have to repeat Cloudwatch twice when using. Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com> * Remove references to Cloudwatch in comments Signed-off-by: Aurélien Rainone <aurelien.rainone@gmail.com>
2019-11-06 13:53:21 +00:00
func (cw *MonitoringService) getOrCreatePerShardMetrics(shard string) *cloudWatchMetrics {
var i interface{}
var ok bool
if i, ok = cw.shardMetrics.Load(shard); !ok {
m := &cloudWatchMetrics{}
cw.shardMetrics.Store(shard, m)
return m
}
return i.(*cloudWatchMetrics)
}
func sumFloat64(slice []float64) *float64 {
sum := float64(0)
for _, num := range slice {
sum += num
}
return &sum
}
func maxFloat64(slice []float64) *float64 {
if len(slice) < 1 {
return aws.Float64(0)
}
max := slice[0]
for _, num := range slice {
if num > max {
max = num
}
}
return &max
}
func minFloat64(slice []float64) *float64 {
if len(slice) < 1 {
return aws.Float64(0)
}
min := slice[0]
for _, num := range slice {
if num < min {
min = num
}
}
return &min
}