Skip to content

Commit

Permalink
feat: Add metric for Store And Foward queue size
Browse files Browse the repository at this point in the history
closes edgexfoundry#1138

Signed-off-by: Leonard Goodell <leonard.goodell@intel.com>
  • Loading branch information
Leonard Goodell committed Jan 17, 2024
1 parent 15d59e2 commit 90ce391
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
26 changes: 12 additions & 14 deletions internal/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@

package internal

import (
"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
)

const (
ApiTriggerRoute = common.ApiBase + "/trigger"
ApiAddSecretRoute = common.ApiBase + "/secret"
)
import "github.com/edgexfoundry/go-mod-core-contracts/v3/common"

// SDKVersion indicates the version of the SDK - will be overwritten by build
var SDKVersion = "0.0.0"

// ApplicationVersion indicates the version of the application itself, not the SDK - will be overwritten by build
var ApplicationVersion = "0.0.0"

// Names for the Common Application Service Metrics
// Misc Constants
const (
ApiTriggerRoute = common.ApiBase + "/trigger"
MessageBusSubscribeTopics = "SubscribeTopics"
)

// Common Application Service Metrics constants
const (
MessagesReceivedName = "MessagesReceived"
InvalidMessagesReceivedName = "InvalidMessagesReceived"
Expand All @@ -43,9 +42,8 @@ const (
HttpExportErrorsName = "HttpExportErrors"
MqttExportSizeName = "MqttExportSize"
MqttExportErrorsName = "MqttExportErrors"
MessageBusSubscribeTopics = "SubscribeTopics"
MessageBusPublishTopic = "PublishTopic"
)
StoreForwardQueueSizeName = "StoreForwardQueueSize"

// MetricsReservoirSize is the default Metrics Sample Reservoir size
const MetricsReservoirSize = 1028
// MetricsReservoirSize is the default Metrics Sample Reservoir size
MetricsReservoirSize = 1028
)
19 changes: 18 additions & 1 deletion internal/runtime/storeforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sync/atomic"
"time"

"github.com/edgexfoundry/app-functions-sdk-go/v3/internal"
"github.com/edgexfoundry/app-functions-sdk-go/v3/internal/appfunction"
"github.com/edgexfoundry/app-functions-sdk-go/v3/internal/bootstrap/container"
"github.com/edgexfoundry/app-functions-sdk-go/v3/pkg/interfaces"
Expand All @@ -48,7 +49,7 @@ type storeForwardInfo struct {
}

func newStoreAndForward(runtime *FunctionsPipelineRuntime, dic *di.Container, serviceKey string) *storeForwardInfo {
return &storeForwardInfo{
sf := &storeForwardInfo{
runtime: runtime,
dic: dic,
lc: bootstrapContainer.LoggingClientFrom(dic.Get),
Expand All @@ -58,6 +59,22 @@ func newStoreAndForward(runtime *FunctionsPipelineRuntime, dic *di.Container, se
// TODO: Register counter metric when using it for the metrics capability
dataCount: gometrics.NewCounter(),
}

metricsManager := bootstrapContainer.MetricsManagerFrom(dic.Get)
if metricsManager == nil {
sf.lc.Errorf("Unable to register %s metric: MetricsManager is not available.", internal.StoreForwardQueueSizeName)
return sf
}

err := metricsManager.Register(internal.StoreForwardQueueSizeName, sf.dataCount, nil)
if err != nil {
sf.lc.Errorf("Unable to register metric %s. Collection will continue, but metric will not be reported: %v",
internal.StoreForwardQueueSizeName, err)
}

sf.lc.Infof("%s metric has been registered and will be reported (if enabled)", internal.StoreForwardQueueSizeName)

return sf
}

func (sf *storeForwardInfo) startStoreAndForwardRetryLoop(
Expand Down

0 comments on commit 90ce391

Please sign in to comment.