Skip to content

Commit dfd7304

Browse files
committed
Improve logging
1 parent ef99390 commit dfd7304

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

src/conf/conf.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ import (
1010
yaml "gopkg.in/yaml.v3"
1111
)
1212

13-
// func (conf Conf) newConf() Conf {
14-
// m := make(map[string]Endpoint)
15-
// return Conf{
16-
// Port: 0,
17-
// API: m,
18-
// }
19-
// }
20-
2113
func (conf *Conf) readConfig() {
2214
var content ConfContent
2315
by, err := os.ReadFile(conf.FileName)

src/indexer/cache.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package indexer
22

3-
import cache "github.com/patrickmn/go-cache"
3+
import (
4+
"time"
5+
6+
cache "github.com/patrickmn/go-cache"
7+
)
48

59
func (ind Indexer) setTapIndexCache(key string, val TapIndex) {
610
ind.Cache.Set(key, val, cache.DefaultExpiration)
@@ -13,6 +17,14 @@ func (ind Indexer) getTapIndexCache(key string) (val TapIndex) {
1317
return
1418
}
1519

20+
func (ind Indexer) getTapIndexCacheWithExpiration(key string) (val TapIndex, tim time.Time) {
21+
if x, t, found := ind.Cache.GetWithExpiration(key); found {
22+
val = x.(TapIndex)
23+
tim = t
24+
}
25+
return
26+
}
27+
1628
func (ind Indexer) flushCache() {
1729
ind.Cache.Flush()
1830
}

src/indexer/req.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ func (ind Indexer) req(targetURL, method string) (data []byte, err error) {
2222
)
2323
ind.Lg.IfErrError("can not init request", logseal.F{"error": err})
2424

25-
response, err := client.Do(request)
26-
ind.Lg.IfErrError("request failed", logseal.F{"error": err})
25+
resp, err := client.Do(request)
26+
ind.Lg.IfErrError(
27+
"request failed",
28+
logseal.F{"error": err})
2729

2830
if err == nil {
29-
data, err = io.ReadAll(response.Body)
31+
data, err = io.ReadAll(resp.Body)
3032
ind.Lg.IfErrError(
3133
"unable to read request response", logseal.F{"error": err},
3234
)

src/indexer/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (ind Indexer) RunServer() {
2525
}
2626

2727
func (ind Indexer) ServeContent(w http.ResponseWriter, r *http.Request) {
28-
ind.Lg.Info("got request", logseal.F{"url": r.URL})
28+
ind.Lg.Debug("got request", logseal.F{"url": r.URL})
2929
params := Params{
3030
Ascending: true,
3131
Filter: FilterParams{Enabled: false},
@@ -60,7 +60,7 @@ func (ind Indexer) ServeContent(w http.ResponseWriter, r *http.Request) {
6060
start := time.Now()
6161
params.Endpoint = val
6262
ind.UpdateTapIndex(params)
63-
ind.Lg.Debug(
63+
ind.Lg.Info(
6464
"serve json",
6565
logseal.F{
6666
"url": url, "path": val.Source, "rxfilter": val.RxFilter, "duration": time.Since(start),

src/indexer/ti.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (ind *Indexer) UpdateTapIndex(params Params) {
1414
)
1515

1616
var err error
17-
ti := ind.getTapIndexCache(params.Endpoint.Source)
17+
ti, tim := ind.getTapIndexCacheWithExpiration(params.Endpoint.Source)
1818
if len(ti) < 1 {
1919
ind.DataSources.Params = params
2020
ind.DataSources.Type = params.Endpoint.SourceType
@@ -61,6 +61,13 @@ func (ind *Indexer) UpdateTapIndex(params Params) {
6161
}
6262
ti = ti.applyIgnoreList(params)
6363
ind.setTapIndexCache(params.Endpoint.Source, ti)
64+
} else {
65+
ind.Lg.Debug(
66+
"return from cache",
67+
logseal.F{
68+
"key": params.Endpoint.Source,
69+
"expiration_time": tim,
70+
})
6471
}
6572
}
6673

0 commit comments

Comments
 (0)