-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BRIDGE-206): added observability service suport & metrics
- Loading branch information
1 parent
d23b4be
commit b6afba8
Showing
15 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package observability | ||
|
||
import "context" | ||
|
||
type observabilitySenderKeyType struct{} | ||
|
||
var observabilitySenderKeyVal observabilitySenderKeyType | ||
|
||
func NewContextWithObservabilitySender(ctx context.Context, sender Sender) context.Context { | ||
return context.WithValue(ctx, observabilitySenderKeyVal, sender) | ||
} | ||
|
||
func getObservabilitySenderFromContext(ctx context.Context) (Sender, bool) { | ||
v := ctx.Value(observabilitySenderKeyVal) | ||
if v == nil { | ||
return nil, false | ||
} | ||
|
||
sender, ok := v.(Sender) | ||
return sender, ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package metrics | ||
|
||
import "time" | ||
|
||
const schemaName = "bridge_gluon_errors_total" | ||
const schemaVersion = 1 | ||
|
||
func generateGluonFailureMetric(errorType string) map[string]interface{} { | ||
return map[string]interface{}{ | ||
"Name": schemaName, | ||
"Version": schemaVersion, | ||
"Timestamp": time.Now().Unix(), | ||
"Data": map[string]interface{}{ | ||
"Value": 1, | ||
"Labels": map[string]string{ | ||
"errorType": errorType, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func GenerateFailedParseIMAPCommandMetric() map[string]interface{} { | ||
return generateGluonFailureMetric("failedParseIMAPCommand") | ||
} | ||
|
||
func GenerateFailedToCreateMailbox() map[string]interface{} { | ||
return generateGluonFailureMetric("failedCreateMailbox") | ||
} | ||
|
||
func GenerateFailedToDeleteMailboxMetric() map[string]interface{} { | ||
return generateGluonFailureMetric("failedDeleteMailbox") | ||
} | ||
|
||
func GenerateFailedToCopyMessagesMetric() map[string]interface{} { | ||
return generateGluonFailureMetric("failedCopyMessages") | ||
} | ||
|
||
func GenerateFailedToMoveMessagesFromMailboxMetric() map[string]interface{} { | ||
return generateGluonFailureMetric("failedMoveMessagesFromMailbox") | ||
} | ||
|
||
func GenerateFailedToRemoveDeletedMessagesMetric() map[string]interface{} { | ||
return generateGluonFailureMetric("failedRemoveDeletedMessages") | ||
} | ||
|
||
func GenerateFailedToCommitDatabaseTransactionMetric() map[string]interface{} { | ||
return generateGluonFailureMetric("failedCommitDatabaseTransaction") | ||
} | ||
|
||
func GenerateFailedToInsertMessageIntoRecoveryMailbox() map[string]interface{} { | ||
return generateGluonFailureMetric("failedToInsertMessageIntoRecoveryMailbox") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package observability | ||
|
||
var imapErrorMetricType int | ||
var messageErrorMetricType int | ||
var otherErrorMetricType int | ||
|
||
type Sender interface { | ||
AddMetrics(metrics ...map[string]interface{}) | ||
AddDistinctMetrics(errType interface{}, metrics ...map[string]interface{}) | ||
} | ||
|
||
func SetupMetricTypes(imapErrorType, messageErrorType, otherErrorType int) { | ||
imapErrorMetricType = imapErrorType | ||
messageErrorMetricType = messageErrorType | ||
otherErrorMetricType = otherErrorType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package observability | ||
|
||
import "context" | ||
|
||
func AddImapMetric(ctx context.Context, metric ...map[string]interface{}) { | ||
sender, ok := getObservabilitySenderFromContext(ctx) | ||
if !ok { | ||
return | ||
} | ||
sender.AddDistinctMetrics(imapErrorMetricType, metric...) | ||
} | ||
|
||
func AddMessageRelatedMetric(ctx context.Context, metric ...map[string]interface{}) { | ||
sender, ok := getObservabilitySenderFromContext(ctx) | ||
if !ok { | ||
return | ||
} | ||
sender.AddDistinctMetrics(messageErrorMetricType, metric...) | ||
} | ||
|
||
func AddOtherMetric(ctx context.Context, metric ...map[string]interface{}) { | ||
sender, ok := getObservabilitySenderFromContext(ctx) | ||
if !ok { | ||
return | ||
} | ||
sender.AddDistinctMetrics(otherErrorMetricType, metric...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters