Skip to content

Commit

Permalink
feat: add metrics to acl request
Browse files Browse the repository at this point in the history
  • Loading branch information
anvari1313 committed Jun 22, 2024
1 parent 54363fc commit 9483363
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/api/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (a API) ACLv1(c *fiber.Ctx) error {
zap.String("username", request.Username),
zap.String("password", request.Password),
)
authenticator.IncrementWithErrorAuthCounter("unknown_company_before_parse_body", err)

Check warning on line 45 in internal/api/acl.go

View check run for this annotation

Codecov / codecov/patch

internal/api/acl.go#L45

Added line #L45 was not covered by tests

return c.Status(http.StatusBadRequest).SendString("bad request")
}
Expand All @@ -66,6 +67,8 @@ func (a API) ACLv1(c *fiber.Ctx) error {
span.RecordError(err)
}

authenticator.IncrementWithErrorAuthCounter(vendor, err)

Check warning on line 70 in internal/api/acl.go

View check run for this annotation

Codecov / codecov/patch

internal/api/acl.go#L70

Added line #L70 was not covered by tests

var tnaErr authenticator.TopicNotAllowedError

if errors.As(err, &tnaErr) {
Expand Down Expand Up @@ -102,6 +105,7 @@ func (a API) ACLv1(c *fiber.Ctx) error {
zap.String("password", request.Password),
zap.String("authenticator", auth.GetCompany()),
)
authenticator.IncrementWithErrorAuthCounter(vendor, err)

Check warning on line 108 in internal/api/acl.go

View check run for this annotation

Codecov / codecov/patch

internal/api/acl.go#L108

Added line #L108 was not covered by tests

return c.Status(http.StatusOK).SendString("ok")
}
Expand Down Expand Up @@ -133,6 +137,7 @@ func (a API) ACLv2(c *fiber.Ctx) error {
zap.String("username", request.Username),
zap.String("password", request.Password),
)
authenticator.IncrementWithErrorAuthCounter("unknown_company_before_parse_body", err)

Check warning on line 140 in internal/api/acl.go

View check run for this annotation

Codecov / codecov/patch

internal/api/acl.go#L140

Added line #L140 was not covered by tests

return c.Status(http.StatusOK).JSON(ACLResponse{
Result: "deny",
Expand Down Expand Up @@ -168,6 +173,8 @@ func (a API) ACLv2(c *fiber.Ctx) error {
span.RecordError(err)
}

authenticator.IncrementWithErrorAuthCounter(vendor, err)

Check warning on line 176 in internal/api/acl.go

View check run for this annotation

Codecov / codecov/patch

internal/api/acl.go#L176

Added line #L176 was not covered by tests

var tnaErr authenticator.TopicNotAllowedError

if errors.As(err, &tnaErr) {
Expand Down Expand Up @@ -206,6 +213,7 @@ func (a API) ACLv2(c *fiber.Ctx) error {
zap.String("password", request.Password),
zap.String("authenticator", auth.GetCompany()),
)
authenticator.IncrementWithErrorAuthCounter(vendor, err)

Check warning on line 216 in internal/api/acl.go

View check run for this annotation

Codecov / codecov/patch

internal/api/acl.go#L216

Added line #L216 was not covered by tests

return c.Status(http.StatusOK).JSON(ACLResponse{
Result: "allow",
Expand Down
5 changes: 4 additions & 1 deletion internal/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

"github.com/gofiber/fiber/v2"
"github.com/golang-jwt/jwt/v5"
"github.com/snapp-incubator/soteria/internal/authenticator"
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"

"github.com/snapp-incubator/soteria/internal/authenticator"
)

// AuthRequest is the body payload structure of the auth endpoint.
Expand Down Expand Up @@ -56,6 +57,7 @@ func (a API) Authv1(c *fiber.Ctx) error {

err := auth.Auth(token)
if err != nil {
authenticator.IncrementWithErrorAuthCounter(vendor, err)

Check warning on line 60 in internal/api/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/api/auth.go#L58-L60

Added lines #L58 - L60 were not covered by tests
span.RecordError(err)

if !errors.Is(err, jwt.ErrTokenExpired) {
Expand Down Expand Up @@ -123,6 +125,7 @@ func (a API) Authv2(c *fiber.Ctx) error {
err := auth.Auth(token)
if err != nil {

Check warning on line 126 in internal/api/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/api/auth.go#L125-L126

Added lines #L125 - L126 were not covered by tests
span.RecordError(err)
authenticator.IncrementWithErrorAuthCounter(vendor, err)

Check warning on line 128 in internal/api/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/api/auth.go#L128

Added line #L128 was not covered by tests

if !errors.Is(err, jwt.ErrTokenExpired) {
a.Logger.
Expand Down

0 comments on commit 9483363

Please sign in to comment.