Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
feat: implement redis cache if available
Browse files Browse the repository at this point in the history
  • Loading branch information
piraces committed Jun 3, 2023
1 parent 1e4cfc4 commit ca35599
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 15 deletions.
6 changes: 4 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ CGO_ENABLED=1
GOARCH=amd64
GOOS=linux
PORT=8080
SECRET=test
DB_DIR="/db/rsslay.sqlite"
DEFAULT_PROFILE_PICTURE_URL="https://i.imgur.com/MaceU96.png"
SECRET="CHANGE_ME"
Expand All @@ -21,4 +20,7 @@ INFO_RELAY_NAME="rsslay"
INFO_CONTACT=""
MAX_CONTENT_LENGTH=250
LOG_LEVEL=WARN
DELETE_FAILING_FEEDS=false
DELETE_FAILING_FEEDS=false
REDIS_ADDRESS=""
REDIS_USERNAME=""
REDIS_PASSWORD=""
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ ENV INFO_CONTACT=""
ENV MAX_CONTENT_LENGTH=250
ENV LOG_LEVEL="WARN"
ENV DELETE_FAILING_FEEDS=false
ENV REDIS_ADDRESS=""
ENV REDIS_USERNAME=""
ENV REDIS_PASSWORD=""

COPY --from=build /rsslay .
COPY --from=build /app/web/assets/ ./web/assets/
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.fly
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ ENV INFO_CONTACT=""
ENV MAX_CONTENT_LENGTH=250
ENV LOG_LEVEL="WARN"
ENV DELETE_FAILING_FEEDS=false
ENV REDIS_ADDRESS=""
ENV REDIS_USERNAME=""
ENV REDIS_PASSWORD=""

COPY --from=litefs /usr/local/bin/litefs /usr/local/bin/litefs
COPY --from=build /rsslay /usr/local/bin/rsslay
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile.railwayapp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ ARG INFO_CONTACT
ARG MAX_CONTENT_LENGTH
ARG LOG_LEVEL
ARG DELETE_FAILING_FEEDS
ARG REDIS_ADDRESS
ARG REDIS_USERNAME
ARG REDIS_PASSWORD

LABEL org.opencontainers.image.title="rsslay"
LABEL org.opencontainers.image.source=https://github.com/piraces/rsslay
Expand Down Expand Up @@ -84,6 +87,9 @@ ENV INFO_CONTACT=""
ENV MAX_CONTENT_LENGTH=250
ENV LOG_LEVEL="WARN"
ENV DELETE_FAILING_FEEDS=false
ENV REDIS_ADDRESS=$REDIS_ADDRESS
ENV REDIS_USERNAME=$REDIS_USERNAME
ENV REDIS_PASSWORD=$REDIS_PASSWORD

COPY --from=build /rsslay .
COPY --from=build /app/web/assets/ ./web/assets/
Expand Down
16 changes: 15 additions & 1 deletion cmd/rsslay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type Relay struct {
Contact string `envconfig:"INFO_CONTACT" default:"~"`
MaxContentLength int `envconfig:"MAX_CONTENT_LENGTH" default:"250"`
DeleteFailingFeeds bool `envconfig:"DELETE_FAILING_FEEDS" default:"false"`
RedisAddress string `envconfig:"REDIS_ADDRESS" default:""`
RedisUsername string `envconfig:"REDIS_USERNAME" default:""`
RedisPassword string `envconfig:"REDIS_PASSWORD" default:""`

updates chan nostr.Event
lastEmitted sync.Map
Expand Down Expand Up @@ -98,6 +101,17 @@ func ConfigureLogging() {
log.SetOutput(filter)
}

func ConfigureCache() {
if relayInstance.RedisAddress != "" {
custom_cache.RedisConfiguration = &custom_cache.RedisConfig{
Address: relayInstance.RedisAddress,
Username: relayInstance.RedisUsername,
Password: relayInstance.RedisPassword,
}
}
custom_cache.InitializeCache()
}

func (r *Relay) Name() string {
return r.RelayName
}
Expand Down Expand Up @@ -314,7 +328,7 @@ func (r *Relay) GetNIP11InformationDocument() nip11.RelayInformationDocument {
func main() {
CreateHealthCheck()
ConfigureLogging()
custom_cache.InitializeCache()
ConfigureCache()
defer func(db *sql.DB) {
err := db.Close()
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/allegro/bigcache v1.2.1
github.com/eko/gocache/lib/v4 v4.1.3
github.com/eko/gocache/store/bigcache/v4 v4.1.2
github.com/eko/gocache/store/redis/v4 v4.2.0
github.com/fiatjaf/relayer v1.7.3
github.com/hashicorp/logutils v1.0.0
github.com/hellofresh/health-go/v5 v5.1.1
Expand All @@ -18,8 +19,9 @@ require (
github.com/mmcdole/gofeed v1.2.1
github.com/nbd-wtf/go-nostr v0.18.7
github.com/prometheus/client_golang v1.15.1
github.com/redis/go-redis/v9 v9.0.2
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0
)

require (
Expand All @@ -33,6 +35,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.2.0 // indirect
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ=
github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
Expand Down Expand Up @@ -50,10 +52,14 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeC
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/eko/gocache/lib/v4 v4.1.3 h1:i7xVxWWhAESLAcHgp73piJtST63TS7ThFD7LE78vmXc=
github.com/eko/gocache/lib/v4 v4.1.3/go.mod h1:7uSUlaDeRgr17IYCV8kSluhRDXq4SGutWWxTpxpwW3w=
github.com/eko/gocache/store/bigcache/v4 v4.1.2 h1:8uMDpgxTG7BvyLHBFqL3Ao809bVrXfrWqo7v6ALiwTw=
github.com/eko/gocache/store/bigcache/v4 v4.1.2/go.mod h1:Lut5Sk/yI835w02tmwx4ecezYQo445L5sdICsk1zgho=
github.com/eko/gocache/store/redis/v4 v4.2.0 h1:YguIDZuMeVFlQFi0DiYQpL7NvHAckinYFjWxvr0qmLw=
github.com/eko/gocache/store/redis/v4 v4.2.0/go.mod h1:IP4GWCjca/pyruK5GweTZ7zzoFlgQABd3cVMJFEgHfs=
github.com/fiatjaf/relayer v1.7.3 h1:HbE67EFsabLO4bvbuB3uMRfRizsvDxseCIaeQHQstv8=
github.com/fiatjaf/relayer v1.7.3/go.mod h1:cQGM8YSoU/7I79Mg9ULlLQWYm/U54/B/4k60fRXEY2o=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -151,6 +157,8 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/puzpuzpuz/xsync v1.5.2 h1:yRAP4wqSOZG+/4pxJ08fPTwrfL0IzE/LKQ/cw509qGY=
github.com/puzpuzpuz/xsync v1.5.2/go.mod h1:K98BYhX3k1dQ2M63t1YNVDanbwUPmBCAhNmVrrxfiGg=
github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE=
github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
Expand Down Expand Up @@ -187,8 +195,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 h1:Jvc7gsqn21cJHCmAWx0LiimpP18LZmUxkT5Mp7EZ1mI=
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand Down
5 changes: 5 additions & 0 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/piraces/rsslay/pkg/helpers"
"github.com/piraces/rsslay/pkg/metrics"
"github.com/piraces/rsslay/web/templates"
"github.com/prometheus/client_golang/prometheus"
"html/template"
"log"
"net/http"
Expand Down Expand Up @@ -64,6 +65,7 @@ func HandleWebpage(w http.ResponseWriter, r *http.Request, db *sql.DB, mainDomai
var entry Entry
if err := rows.Scan(&entry.PubKey, &entry.Url); err != nil {
log.Printf("[ERROR] failed to scan row iterating feeds: %v", err)
metrics.AppErrors.With(prometheus.Labels{"type": "SQL_SCAN"}).Inc()
continue
}

Expand Down Expand Up @@ -116,6 +118,7 @@ func HandleSearch(w http.ResponseWriter, r *http.Request, db *sql.DB) {
var entry Entry
if err := rows.Scan(&entry.PubKey, &entry.Url); err != nil {
log.Printf("[ERROR] failed to scan row iterating feeds searching: %v", err)
metrics.AppErrors.With(prometheus.Labels{"type": "SQL_SCAN"}).Inc()
continue
}

Expand Down Expand Up @@ -292,10 +295,12 @@ func insertFeed(err error, feedUrl string, publicKey string, sk string, nitter b
log.Printf("[DEBUG] not found feed at url %q as publicKey %s", feedUrl, publicKey)
if _, err := db.Exec(`INSERT INTO feeds (publickey, privatekey, url, nitter) VALUES (?, ?, ?, ?)`, publicKey, sk, feedUrl, nitter); err != nil {
log.Printf("[ERROR] failure: %v", err)
metrics.AppErrors.With(prometheus.Labels{"type": "SQL_WRITE"}).Inc()
} else {
log.Printf("[DEBUG] saved feed at url %q as publicKey %s", feedUrl, publicKey)
}
} else if err != nil {
metrics.AppErrors.With(prometheus.Labels{"type": "SQL_SCAN"}).Inc()
log.Fatalf("[ERROR] failed when trying to retrieve row with pubkey '%s': %v", publicKey, err)
} else {
log.Printf("[DEBUG] found feed at url %q as publicKey %s", feedUrl, publicKey)
Expand Down
87 changes: 86 additions & 1 deletion pkg/custom_cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,104 @@
package custom_cache

import (
"context"
"github.com/allegro/bigcache"
"github.com/eko/gocache/lib/v4/cache"
"github.com/eko/gocache/lib/v4/store"
bigcache_store "github.com/eko/gocache/store/bigcache/v4"
redis_store "github.com/eko/gocache/store/redis/v4"
"github.com/piraces/rsslay/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/redis/go-redis/v9"
"log"
"time"
)

type RedisConfig struct {
Address string
Username string
Password string
}

var MainCache *cache.Cache[[]byte]
var MainCacheRedis *cache.Cache[string]
var Initialized = false
var RedisConfiguration *RedisConfig

func InitializeCache() {
bigcacheClient, _ := bigcache.NewBigCache(bigcache.DefaultConfig(60 * time.Minute))
if RedisConfiguration != nil {
initializeRedisCache()
return
}
initializeBigCache()
}

func Get(key string) (string, error) {
if !Initialized {
InitializeCache()
}
if MainCacheRedis != nil {
return getFromRedis(key)
}
return getFromBigCache(key)
}

func Set(key string, value string) error {
if !Initialized {
InitializeCache()
}
if MainCacheRedis != nil {
return setToRedis(key, value)
}

return setToBigCache(key, value)
}

func initializeBigCache() {
bigcacheClient, _ := bigcache.NewBigCache(bigcache.DefaultConfig(30 * time.Minute))
bigcacheStore := bigcache_store.NewBigcache(bigcacheClient)

MainCache = cache.New[[]byte](bigcacheStore)
Initialized = true
}

func initializeRedisCache() {
redisStore := redis_store.NewRedis(redis.NewClient(&redis.Options{
Addr: RedisConfiguration.Address,
Username: RedisConfiguration.Username,
Password: RedisConfiguration.Password,
}))

MainCacheRedis = cache.New[string](redisStore)
}

func getFromRedis(key string) (string, error) {
value, err := MainCacheRedis.Get(context.Background(), key)
switch err {
case nil:
log.Printf("[DEBUG] Get the key '%s' from the redis cache.", key)
case redis.Nil:
log.Printf("[DEBUG] Failed to find the key '%s' from the redis cache.", key)
default:
log.Printf("[ERROR] Failed to get the value from the redis cache with key '%s': %v", key, err)
metrics.AppErrors.With(prometheus.Labels{"type": "CACHE"}).Inc()
}
return value, err
}

func setToRedis(key string, value string) error {
return MainCacheRedis.Set(context.Background(), key, value, store.WithExpiration(30*time.Minute))
}

func getFromBigCache(key string) (string, error) {
valueBytes, err := MainCache.Get(context.Background(), key)
if err != nil {
log.Printf("[DEBUG] Failed to find the key '%s' from the cache. Error: %v", key, err)
return "", err
}
return string(valueBytes), nil
}

func setToBigCache(key string, value string) error {
return MainCache.Set(context.Background(), key, []byte(value))
}
4 changes: 4 additions & 0 deletions pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/mmcdole/gofeed"
"github.com/piraces/rsslay/pkg/feed"
"github.com/piraces/rsslay/pkg/helpers"
"github.com/piraces/rsslay/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
"log"
"net/url"
"strings"
Expand All @@ -20,6 +22,7 @@ func GetParsedFeedForPubKey(pubKey string, db *sql.DB, deleteFailingFeeds bool,
return nil, entity
} else if err != nil {
log.Printf("[ERROR] failed when trying to retrieve row with pubkey '%s': %v", pubKey, err)
metrics.AppErrors.With(prometheus.Labels{"type": "SQL_SCAN"}).Inc()
return nil, entity
}

Expand Down Expand Up @@ -65,6 +68,7 @@ func updateDatabaseEntry(entity *feed.Entity, db *sql.DB) {
log.Printf("[DEBUG] attempting to set feed at url %q with publicKey %s as nitter instance", entity.URL, entity.PublicKey)
if _, err := db.Exec(`UPDATE feeds SET nitter = ? WHERE publickey = ?`, 1, entity.PublicKey); err != nil {
log.Printf("[ERROR] failure while updating record on db to set as nitter feed: %v", err)
metrics.AppErrors.With(prometheus.Labels{"type": "SQL_WRITE"}).Inc()
} else {
log.Printf("[DEBUG] set feed at url %q with publicKey %s as nitter instance", entity.URL, entity.PublicKey)
}
Expand Down
15 changes: 7 additions & 8 deletions pkg/feed/feed.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package feed

import (
"context"
"crypto/hmac"
"crypto/sha256"
"database/sql"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/piraces/rsslay/pkg/custom_cache"
"github.com/piraces/rsslay/pkg/helpers"
"github.com/piraces/rsslay/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
"html"
"log"
"net/http"
Expand Down Expand Up @@ -88,18 +88,15 @@ func GetFeedURL(url string) string {
}

func ParseFeed(url string) (*gofeed.Feed, error) {
if !custom_cache.Initialized {
custom_cache.InitializeCache()
}

feedBytes, err := custom_cache.MainCache.Get(context.Background(), url)
feedBytes, err := custom_cache.Get(url)
if err == nil {
metrics.CacheHits.Inc()
feed, err := fp.ParseString(string(feedBytes))
feed, err := fp.ParseString(feedBytes)
if err != nil {
return feed, nil
} else {
log.Printf("[ERROR] failure to parse cache stored feed: %v", err)
metrics.AppErrors.With(prometheus.Labels{"type": "CACHE_PARSE"}).Inc()
}
} else {
log.Printf("[DEBUG] entry not found in cache: %v", err)
Expand All @@ -116,9 +113,10 @@ func ParseFeed(url string) (*gofeed.Feed, error) {
for i := range feed.Items {
feed.Items[i].Content = ""
}
err = custom_cache.MainCache.Set(context.Background(), url, []byte(feed.String()))
err = custom_cache.Set(url, feed.String())
if err != nil {
log.Printf("[ERROR] failure to store into cache feed: %v", err)
metrics.AppErrors.With(prometheus.Labels{"type": "CACHE_SET"}).Inc()
}

return feed, nil
Expand Down Expand Up @@ -280,6 +278,7 @@ func PrivateKeyFromFeed(url string, secret string) string {
func DeleteInvalidFeed(url string, db *sql.DB) {
if _, err := db.Exec(`DELETE FROM feeds WHERE url=?`, url); err != nil {
log.Printf("[ERROR] failure to delete invalid feed: %v", err)
metrics.AppErrors.With(prometheus.Labels{"type": "SQL_WRITE"}).Inc()
} else {
log.Printf("[DEBUG] deleted invalid feed with url %q", url)
}
Expand Down
Loading

0 comments on commit ca35599

Please sign in to comment.