Skip to content

Commit

Permalink
add trace to sync (#2601)
Browse files Browse the repository at this point in the history
* trace more

* cleanup

* allow use of mustache templates

---------

Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com>
  • Loading branch information
trajan0x and trajan0x authored May 9, 2024
1 parent db9440a commit 1d3ed83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/screener/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.4
version: 0.2.5

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
2 changes: 1 addition & 1 deletion charts/screener/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
{{ toYaml .Values.files | indent 2 }}
{{ tpl (toYaml .Values.files) . | indent 2 }}
{{- end }}
20 changes: 18 additions & 2 deletions contrib/screener-api/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func NewScreener(ctx context.Context, cfg config.Config, metricHandler metrics.H
}

screener.router = ginhelper.New(logger)
screener.router.Use(screener.metrics.Gin())
screener.router.Handle(http.MethodGet, "/:ruleset/address/:address", screener.screenAddress)

screener.router.Handle(http.MethodPost, "/api/data/sync", screener.authMiddleware(cfg), screener.blacklistAddress)
Expand Down Expand Up @@ -144,6 +145,12 @@ func (s *screenerImpl) fetchBlacklist(ctx context.Context) {
// @Produce json
// @Router /api/data/sync [post].
func (s *screenerImpl) blacklistAddress(c *gin.Context) {
var err error
ctx, span := s.metrics.Tracer().Start(c.Request.Context(), "blacklistAddress")
defer func() {
metrics.EndSpanWithErr(span, err)
}()

var blacklistBody client.BlackListBody

// Grab the body of the JSON request and unmarshal it into the blacklistBody struct.
Expand All @@ -152,6 +159,14 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {
return
}

span.SetAttributes(attribute.String("type", blacklistBody.TypeReq))
span.SetAttributes(attribute.String("id", blacklistBody.ID))
span.SetAttributes(attribute.String("data", blacklistBody.Data))
span.SetAttributes(attribute.String("network", blacklistBody.Network))
span.SetAttributes(attribute.String("tag", blacklistBody.Tag))
span.SetAttributes(attribute.String("remark", blacklistBody.Remark))
span.SetAttributes(attribute.String("address", blacklistBody.Address))

blacklistedAddress := db.BlacklistedAddress{
TypeReq: blacklistBody.TypeReq,
ID: blacklistBody.ID,
Expand All @@ -164,7 +179,8 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {

switch blacklistBody.TypeReq {
case "create":
if err := s.db.PutBlacklistedAddress(c, blacklistedAddress); err != nil {
if err := s.db.PutBlacklistedAddress(ctx, blacklistedAddress); err != nil {
span.AddEvent("error", trace.WithAttributes(attribute.String("error", err.Error())))
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
Expand Down Expand Up @@ -262,7 +278,7 @@ func (s *screenerImpl) Start(ctx context.Context) error {
// @Success 200 {object} map[string]bool "Returns the risk assessment result"
// @Failure 400 {object} map[string]string "Returns error if the required parameters are missing or invalid"
// @Failure 500 {object} map[string]string "Returns error if there are problems processing the indicators"
// @Router /screen/{ruleset}/{address} [get]
// @Router /screen/{ruleset}/{address} [get].
func (s *screenerImpl) screenAddress(c *gin.Context) {
var err error

Expand Down

0 comments on commit 1d3ed83

Please sign in to comment.