Skip to content

Commit

Permalink
add tracing (#152)
Browse files Browse the repository at this point in the history
Co-authored-by: James Kwon <[email protected]>
  • Loading branch information
james03160927 and james03160927 authored Jan 23, 2025
1 parent 6828234 commit 2a4b225
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 190 deletions.
13 changes: 13 additions & 0 deletions gateways/algolia/algolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"registry-backend/ent"
"registry-backend/entity"
"registry-backend/mapper"
"registry-backend/tracing"

"github.com/algolia/algoliasearch-client-go/v3/algolia/search"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -49,6 +50,8 @@ func NewAlgoliaService(cfg *config.Config) (AlgoliaService, error) {

// IndexNodes indexes the provided nodes in Algolia.
func (a *algolia) IndexNodes(ctx context.Context, nodes ...*ent.Node) error {
defer tracing.TraceDefaultSegment(ctx, "AlgoliaService.IndexNodes")()

index := a.client.InitIndex("nodes_index")
objects := make([]entity.AlgoliaNode, len(nodes))

Expand All @@ -66,6 +69,8 @@ func (a *algolia) IndexNodes(ctx context.Context, nodes ...*ent.Node) error {

// SearchNodes searches for nodes in Algolia matching the query.
func (a *algolia) SearchNodes(ctx context.Context, query string, opts ...interface{}) (nodes []*ent.Node, err error) {
defer tracing.TraceDefaultSegment(ctx, "AlgoliaService.SearchNodes")()

index := a.client.InitIndex("nodes_index")
res, err := index.Search(query, opts...)
if err != nil {
Expand All @@ -84,6 +89,8 @@ func (a *algolia) SearchNodes(ctx context.Context, query string, opts ...interfa

// DeleteNode deletes the specified node from Algolia.
func (a *algolia) DeleteNode(ctx context.Context, node *ent.Node) error {
defer tracing.TraceDefaultSegment(ctx, "AlgoliaService.DeleteNode")()

index := a.client.InitIndex("nodes_index")
res, err := index.DeleteObject(node.ID)
if err != nil {
Expand All @@ -94,6 +101,8 @@ func (a *algolia) DeleteNode(ctx context.Context, node *ent.Node) error {

// IndexNodeVersions implements AlgoliaService.
func (a *algolia) IndexNodeVersions(ctx context.Context, nodes ...*ent.NodeVersion) error {
defer tracing.TraceDefaultSegment(ctx, "AlgoliaService.IndexNodeVersions")()

index := a.client.InitIndex("node_versions_index")
objects := make([]struct {
ObjectID string `json:"objectID"`
Expand Down Expand Up @@ -122,6 +131,8 @@ func (a *algolia) IndexNodeVersions(ctx context.Context, nodes ...*ent.NodeVersi

// DeleteNodeVersions implements AlgoliaService.
func (a *algolia) DeleteNodeVersions(ctx context.Context, nodes ...*ent.NodeVersion) error {
defer tracing.TraceDefaultSegment(ctx, "AlgoliaService.DeleteNodeVersions")()

index := a.client.InitIndex("node_versions_index")
ids := []string{}
for _, node := range nodes {
Expand All @@ -136,6 +147,8 @@ func (a *algolia) DeleteNodeVersions(ctx context.Context, nodes ...*ent.NodeVers

// SearchNodeVersions implements AlgoliaService.
func (a *algolia) SearchNodeVersions(ctx context.Context, query string, opts ...interface{}) ([]*ent.NodeVersion, error) {
defer tracing.TraceDefaultSegment(ctx, "AlgoliaService.SearchNodeVersions")()

index := a.client.InitIndex("node_versions_index")
res, err := index.Search(query, opts...)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions gateways/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"registry-backend/config"
"registry-backend/tracing"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -47,6 +48,8 @@ func NewPubSubService(c *config.Config) (PubSubService, error) {

// PublishNodePack implements PubSubService.
func (p *pubsubimpl) PublishNodePack(ctx context.Context, storageURL string) (err error) {
defer tracing.TraceDefaultSegment(ctx, "PubSubService.PublishNodePack")()

u, err := url.Parse(storageURL)
if err != nil {
return fmt.Errorf("invalid storage URL: %w", err)
Expand Down
8 changes: 7 additions & 1 deletion gateways/storage/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"os"
"time"

"registry-backend/config"
"registry-backend/tracing"

"cloud.google.com/go/storage"
"github.com/rs/zerolog/log"
"registry-backend/config"
)

// StorageService defines the interface for interacting with cloud storage.
Expand Down Expand Up @@ -52,6 +54,8 @@ func NewStorageService(cfg *config.Config) (StorageService, error) {

// UploadFile uploads an object to GCP storage.
func (s *storageService) UploadFile(ctx context.Context, bucket, object, filePath string) (string, error) {
defer tracing.TraceDefaultSegment(ctx, "StorageService.UploadFile")()

log.Ctx(ctx).Info().Msgf("Uploading %v to %v/%v.\n", filePath, bucket, object)

// Open local file
Expand Down Expand Up @@ -120,6 +124,8 @@ func (s *storageService) StreamFileUpload(w io.Writer, objectName, blob string)

// GetFileUrl gets the public URL of a file from GCP storage.
func (s *storageService) GetFileUrl(ctx context.Context, bucketName, objectPath string) (string, error) {
defer tracing.TraceDefaultSegment(ctx, "StorageService.GetFileUrl")()

// Get the public URL of a file in a bucket
attrs, err := s.client.Bucket(bucketName).Object(objectPath).Attrs(ctx)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions server/implementation/cicd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"registry-backend/ent/gitcommit"
"registry-backend/ent/schema"
"registry-backend/mapper"
"registry-backend/tracing"
"sort"
"strings"

Expand All @@ -17,6 +18,8 @@ import (
)

func (impl *DripStrictServerImplementation) GetGitcommit(ctx context.Context, request drip.GetGitcommitRequestObject) (drip.GetGitcommitResponseObject, error) {
defer tracing.TraceDefaultSegment(ctx, "DripStrictServerImplementation.GetGitcommit")()

var commitId uuid.UUID = uuid.Nil
if request.Params.CommitId != nil {
log.Ctx(ctx).Info().Msgf("getting commit data for %s", *request.Params.CommitId)
Expand Down Expand Up @@ -124,6 +127,7 @@ func (impl *DripStrictServerImplementation) GetGitcommit(ctx context.Context, re
}

func (impl *DripStrictServerImplementation) GetGitcommitsummary(ctx context.Context, request drip.GetGitcommitsummaryRequestObject) (drip.GetGitcommitsummaryResponseObject, error) {
defer tracing.TraceDefaultSegment(ctx, "DripStrictServerImplementation.GetGitcommitsummary")()
log.Ctx(ctx).Info().Msg("Getting git commit summary")

// Prep relevant vars
Expand Down Expand Up @@ -254,6 +258,8 @@ func (impl *DripStrictServerImplementation) GetGitcommitsummary(ctx context.Cont
}

func (impl *DripStrictServerImplementation) GetWorkflowResult(ctx context.Context, request drip.GetWorkflowResultRequestObject) (drip.GetWorkflowResultResponseObject, error) {
defer tracing.TraceDefaultSegment(ctx, "DripStrictServerImplementation.GetWorkflowResult")()

log.Ctx(ctx).Info().Msgf("Getting workflow result with ID %s", request.WorkflowResultId)
workflowId := uuid.MustParse(request.WorkflowResultId)
workflow, err := impl.Client.CIWorkflowResult.Query().WithGitcommit().WithStorageFile().Where(ciworkflowresult.IDEQ(workflowId)).First(ctx)
Expand All @@ -278,6 +284,8 @@ func (impl *DripStrictServerImplementation) GetWorkflowResult(ctx context.Contex
}

func (impl *DripStrictServerImplementation) GetBranch(ctx context.Context, request drip.GetBranchRequestObject) (drip.GetBranchResponseObject, error) {
defer tracing.TraceDefaultSegment(ctx, "DripStrictServerImplementation.GetBranch")()

repoNameFilter := strings.ToLower(request.Params.RepoName)

branches, err := impl.Client.GitCommit.
Expand All @@ -295,6 +303,8 @@ func (impl *DripStrictServerImplementation) GetBranch(ctx context.Context, reque
}

func (impl *DripStrictServerImplementation) PostUploadArtifact(ctx context.Context, request drip.PostUploadArtifactRequestObject) (drip.PostUploadArtifactResponseObject, error) {
defer tracing.TraceDefaultSegment(ctx, "DripStrictServerImplementation.PostUploadArtifact")()

err := impl.ComfyCIService.ProcessCIRequest(ctx, impl.Client, &request)
if err != nil {
log.Ctx(ctx).Error().Msgf("Error processing CI request w/ err: %v", err)
Expand Down
Loading

0 comments on commit 2a4b225

Please sign in to comment.