Skip to content

Commit

Permalink
Merge pull request #60 from containerish/logger
Browse files Browse the repository at this point in the history
Add: Zerolog with FluentBit  Integration
  • Loading branch information
guacamole authored Nov 17, 2021
2 parents b3e2572 + af9f4dd commit a4b540f
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 79 deletions.
2 changes: 2 additions & 0 deletions cache/register_for_beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"regexp"

"github.com/containerish/OpenRegistry/types"
"github.com/dgraph-io/badger/v3"
"github.com/labstack/echo/v4"
)
Expand Down Expand Up @@ -101,6 +102,7 @@ func (ds *dataStore) RegisterForBeta(ctx echo.Context) error {
func (ds *dataStore) GetAllEmail(ctx echo.Context) error {
bz, err := ds.Get([]byte("email"))
if err != nil && err != badger.ErrKeyNotFound {
ctx.Set(types.HttpEndpointErrorKey, err.Error())
return ctx.JSON(http.StatusInternalServerError, echo.Map{
"error": "couldn't get them all",
})
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ func main() {
return
}

router.Register(e, reg, authSvc, localCache)
router.Register(cfg, e, reg, authSvc, localCache)
log.Fatal().Msgf("error starting server: %s\n", e.Start(cfg.Address()))
}
14 changes: 8 additions & 6 deletions registry/v2/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"

"github.com/containerish/OpenRegistry/types"
"github.com/fatih/color"
"github.com/labstack/echo/v4"
)
Expand Down Expand Up @@ -37,14 +38,15 @@ func (b *blobs) HEAD(ctx echo.Context) error {
"skynet": "skynet link not found",
}
errMsg := b.errorResponse(RegistryErrorCodeManifestBlobUnknown, err.Error(), details)
b.fluentbit.Send(errMsg)

ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}

size, ok := b.registry.skynet.Metadata(layerRef.Skylink)
if !ok {
errMsg := b.errorResponse(RegistryErrorCodeManifestBlobUnknown, "Manifest does not exist", nil)
b.fluentbit.Send(errMsg)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}

Expand All @@ -65,7 +67,7 @@ func (b *blobs) UploadBlob(ctx echo.Context) error {
"stream upload after first write are not allowed",
nil,
)
b.fluentbit.Send(errMsg)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusBadRequest, errMsg)
}

Expand All @@ -88,13 +90,13 @@ func (b *blobs) UploadBlob(ctx echo.Context) error {
"contentRange": contentRange,
}
errMsg := b.errorResponse(RegistryErrorCodeBlobUploadUnknown, err.Error(), details)
b.fluentbit.Send(errMsg)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusRequestedRangeNotSatisfiable, errMsg)
}

if start != len(b.uploads[uuid]) {
errMsg := b.errorResponse(RegistryErrorCodeBlobUploadUnknown, "content range mismatch", nil)
b.fluentbit.Send(errMsg)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusRequestedRangeNotSatisfiable, errMsg)
}

Expand All @@ -106,7 +108,7 @@ func (b *blobs) UploadBlob(ctx echo.Context) error {
"error while creating new buffer from existing blobs",
nil,
)
b.fluentbit.Send(errMsg)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusInternalServerError, errMsg)
} // 10
ctx.Request().Body.Close()
Expand Down
Loading

0 comments on commit a4b540f

Please sign in to comment.