Skip to content

Commit

Permalink
feat: move the db objects to the delta main (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvin Reyes authored Aug 6, 2023
2 parents 7094c36 + f47e5c9 commit fb642aa
Show file tree
Hide file tree
Showing 47 changed files with 1,272 additions and 139 deletions.
2 changes: 1 addition & 1 deletion api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/google/uuid"
Expand Down
2 changes: 1 addition & 1 deletion api/deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"delta/utils"
"encoding/json"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/google/uuid"
"github.com/ipfs/go-cid"
"github.com/multiformats/go-multiaddr"
Expand Down
2 changes: 1 addition & 1 deletion api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"delta/core"
"github.com/application-research/delta-db/db_models"
"delta/models"
"github.com/labstack/echo/v4"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down
2 changes: 1 addition & 1 deletion api/open_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"delta/core"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/labstack/echo/v4"
Expand Down
2 changes: 1 addition & 1 deletion api/open_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"delta/core"
"delta/jobs"
"delta/utils"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/labstack/echo/v4"
"strconv"
)
Expand Down
2 changes: 1 addition & 1 deletion api/repair_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"delta/jobs"
"delta/utils"
"encoding/json"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/labstack/echo/v4"
"strings"
"time"
Expand Down
45 changes: 1 addition & 44 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ package api
import (
"delta/config"
"delta/core"
"delta/utils"
_ "delta/docs/swagger"
"encoding/json"
"fmt"
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"time"

_ "delta/docs/swagger"
"github.com/application-research/delta-db/messaging"
logging "github.com/ipfs/go-log/v2"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
Expand Down Expand Up @@ -268,46 +265,6 @@ func ValidateRequestBody() echo.MiddlewareFunc {
// ErrorHandler It's a function that is called when an error occurs.
func ErrorHandler(err error, c echo.Context) {

ip := DeltaNodeConfig.Node.AnnounceAddrIP

// get the request body and log it

s := struct {
RemoteIP string `json:"remote_ip"`
PublicIP string `json:"public_ip"`
Host string `json:"host"`
Referer string `json:"referer"`
Request string `json:"request"`
Path string `json:"path"`
ErrorDetails string `json:"details"`
}{
RemoteIP: c.RealIP(),
PublicIP: ip,
Host: c.Request().Host,
Referer: c.Request().Referer(),
Request: c.Request().RequestURI,
Path: c.Path(),
ErrorDetails: err.Error(),
}

b, errM := json.Marshal(s)
if errM != nil {
log.Error(errM)
}

// It's sending the error to the log server.
utils.GlobalDeltaDataReporter.TraceLog(
messaging.LogEvent{
LogEventType: "Error: " + core.GetHostname() + " " + c.Request().Method + " " + c.Path(),
SourceHost: core.GetHostname(),
SourceIP: ip,
LogEventObject: b,
LogEvent: c.Path(),
DeltaUuid: DeltaNodeConfig.Node.InstanceUuid,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
})

var httpRespErr *HttpError
if xerrors.As(err, &httpRespErr) {
log.Errorf("handler error: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion api/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"delta/core"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"strings"

"github.com/labstack/echo/v4"
Expand Down
2 changes: 1 addition & 1 deletion api/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"delta/core"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"sync"
Expand Down
16 changes: 1 addition & 15 deletions cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import (
"delta/api"
c "delta/config"
"delta/core"
_ "delta/models"
"delta/utils"
"fmt"
"github.com/application-research/delta-db/db_models"
_ "github.com/application-research/delta-db/db_models"
"github.com/application-research/delta-db/messaging"
"github.com/filecoin-project/go-address"
"github.com/jasonlvhit/gocron"
"github.com/urfave/cli/v2"
"runtime"
"time"
)

// DaemonCmd Creating a new command called `daemon` that will run the API node.
Expand Down Expand Up @@ -186,17 +183,6 @@ By: Protocol Labs - Outercore Engineering
` + utils.Reset + utils.Red + "version: " + cfg.Common.Version + utils.Reset)

fmt.Println(utils.Blue + "Reporting Delta startup logs" + utils.Reset)
utils.GlobalDeltaDataReporter.Trace(messaging.DeltaMetricsBaseMessage{
ObjectType: "DeltaStartupLogs",
Object: db_models.DeltaStartupLogs{
NodeInfo: core.GetHostname(),
OSDetails: runtime.GOARCH + " " + runtime.GOOS,
IPAddress: ip,
DeltaNodeUuid: cfg.Node.InstanceUuid,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
},
})
fmt.Println(utils.Blue + "Reporting Delta startup logs... DONE" + utils.Reset)
fmt.Println("----------------------------------")
fmt.Println(utils.Green + "Welcome! Delta daemon is running..." + utils.Reset)
Expand Down
2 changes: 1 addition & 1 deletion core/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"delta/utils"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
fc "github.com/application-research/filclient"
datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/ipfs/go-cid"
Expand Down
18 changes: 2 additions & 16 deletions core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package core
import (
"context"
c "delta/config"
model "delta/models"
"delta/utils"
"encoding/base64"
"encoding/json"
"fmt"
model "github.com/application-research/delta-db/db_models"
"github.com/application-research/delta-db/messaging"
fc "github.com/application-research/filclient"
"github.com/application-research/filclient/keystore"
"github.com/application-research/whypfs-core"
Expand All @@ -30,7 +29,6 @@ import (
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
trace2 "go.opencensus.io/trace"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/trace"
"gorm.io/gorm"
Expand Down Expand Up @@ -75,19 +73,13 @@ type DeltaNode struct {
Dispatcher *Dispatcher
MetaInfo *model.InstanceMeta

DeltaEventEmitter *DeltaEventEmitter
DeltaMetricsTracer *DeltaMetricsTracer
DeltaEventEmitter *DeltaEventEmitter
}

type DeltaEventEmitter struct {
WebsocketBroadcast WebsocketBroadcast
}

type DeltaMetricsTracer struct {
Tracer trace2.Tracer
DeltaDataReporter *messaging.DeltaMetricsTracer
}

// WebsocketBroadcast `WebsocketBroadcast` is a struct that contains three channels, one for each type of message that can be broadcasted.
// @property {ContentChannel} ContentChannel - This is the channel that will be used to send content to the client.
// @property {PieceCommitmentChannel} PieceCommitmentChannel - This is a channel that will be used to send piece
Expand Down Expand Up @@ -266,9 +258,6 @@ func NewLightNode(repo NewLightNodeParams) (*DeltaNode, error) {
// job dispatcher
dispatcher := CreateNewDispatcher()

// delta metrics tracer
dataTracer := messaging.NewDeltaMetricsTracer()

openTelemetryTracerProvider := trace.NewTracerProvider(trace.WithSampler(trace.AlwaysSample()))
defer openTelemetryTracerProvider.Shutdown(context.Background())

Expand All @@ -285,9 +274,6 @@ func NewLightNode(repo NewLightNodeParams) (*DeltaNode, error) {
Dispatcher: dispatcher,
LotusApiNode: api,
Config: repo.Config,
DeltaMetricsTracer: &DeltaMetricsTracer{
DeltaDataReporter: dataTracer,
},
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion core/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core
//
//import (
// "fmt"
// model "github.com/application-research/delta-db/db_models"
// model "delta/models"
// "gorm.io/gorm"
// "time"
//)
Expand Down
2 changes: 1 addition & 1 deletion core/stats.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package core

import model "github.com/application-research/delta-db/db_models"
import model "delta/models"

type StatsService struct {
DeltaNode *DeltaNode
Expand Down
2 changes: 1 addition & 1 deletion core/status_logger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package core

import model "github.com/application-research/delta-db/db_models"
import model "delta/models"

// StatusLogger is used to change the status of each system objects in a async manner.
// Each state content, commp and transfers needs to be updated and logged in the database.
Expand Down
2 changes: 1 addition & 1 deletion core/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
Expand Down
2 changes: 1 addition & 1 deletion core/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package core

import (
"context"
"github.com/application-research/delta-db/db_models"
"delta/models"
"reflect"
"testing"
)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2
github.com/application-research/delta-db v0.0.2-0.20230504034024-a5e4190148d6
github.com/application-research/delta-db v0.0.1
github.com/application-research/filclient v0.5.0-rc1.0.20230331195738-9826f79f0648
github.com/application-research/whypfs-core v0.1.1
github.com/caarlos0/env/v6 v6.10.1
Expand Down Expand Up @@ -49,10 +49,11 @@ require (
github.com/swaggo/echo-swagger v1.4.0
github.com/swaggo/swag v1.16.1
github.com/urfave/cli/v2 v2.24.4
go.opencensus.io v0.24.0
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/sdk v1.14.0
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
gorm.io/driver/postgres v1.4.8
gorm.io/driver/sqlite v1.4.4
gorm.io/gorm v1.24.5
)

Expand Down Expand Up @@ -287,6 +288,7 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.12.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.16.1 // indirect
Expand All @@ -309,8 +311,6 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.4.8 // indirect
gorm.io/driver/sqlite v1.4.4 // indirect
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/application-research/delta-db v0.0.2-0.20230504034024-a5e4190148d6 h1:LGMPeFvr8n+gRorQ1mX/PuvdXG4e0wfCLUVebPkyDcI=
github.com/application-research/delta-db v0.0.2-0.20230504034024-a5e4190148d6/go.mod h1:LkFnhccvtKmSNHCatQNlKNjEAV/30w/e50n+A9hzCaU=
github.com/application-research/delta-db v0.0.1 h1:rvqhS/nvXhl6M8mlbb2bEnN9JBiwy8TGnqn+7hDBXxw=
github.com/application-research/delta-db v0.0.1/go.mod h1:LkFnhccvtKmSNHCatQNlKNjEAV/30w/e50n+A9hzCaU=
github.com/application-research/filclient v0.5.0-rc1.0.20230331195738-9826f79f0648 h1:58+odb1yvlrhuWbmpcAu7IKN4/0+LOP8XjKP3JxOPGo=
github.com/application-research/filclient v0.5.0-rc1.0.20230331195738-9826f79f0648/go.mod h1:HSCZh+v53XTGMwHGyoKpedQH+PlwcmKkMFCYx/Q3hMk=
github.com/application-research/whypfs-core v0.1.1 h1:BY40N15Ge9BlyAT3f4T4B/CAlaL7A1RYaRrNS3HIyEk=
Expand Down
2 changes: 1 addition & 1 deletion jobs/clean_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"delta/core"
"delta/utils"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/ipfs/go-cid"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion jobs/clean_up_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"delta/core"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/ipfs/go-cid"
)

Expand Down
2 changes: 1 addition & 1 deletion jobs/data_transfer_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"delta/core"
"delta/utils"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/application-research/filclient"
)

Expand Down
2 changes: 1 addition & 1 deletion jobs/data_transfer_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"delta/core"
"delta/utils"
"fmt"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"github.com/application-research/filclient"
datatransfer "github.com/filecoin-project/go-data-transfer"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion jobs/deal_status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package jobs
import (
"context"
"delta/core"
model "delta/models"
"encoding/base64"
"fmt"
model "github.com/application-research/delta-db/db_models"
fc "github.com/application-research/filclient"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket"
Expand Down
2 changes: 1 addition & 1 deletion jobs/instance_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jobs

import (
"delta/core"
model "github.com/application-research/delta-db/db_models"
model "delta/models"
"runtime"
"syscall"
)
Expand Down
Loading

0 comments on commit fb642aa

Please sign in to comment.