summaryrefslogtreecommitdiff
path: root/bpf
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-05 18:26:47 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-05 18:26:47 +0530
commit4b44400700d0fb12cc7d86ecc020a30d78aa74c6 (patch)
treeb280addcb03f03d7e1e27836d1c161902522fa43 /bpf
parentbd99f6b4d67c386daf604c94999e5de72584f883 (diff)
bpf: better error management
Diffstat (limited to 'bpf')
-rw-r--r--bpf/main.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/bpf/main.go b/bpf/main.go
index 1f5610d..4f1360e 100644
--- a/bpf/main.go
+++ b/bpf/main.go
@@ -58,10 +58,16 @@ func Run(iface *net.Interface, queries *db.Queries, ctxDb context.Context) {
for {
select {
case <-bpfTicker.C:
- usageMap.update(objs.IngressIp4UsageMap, objs.EgressIp4UsageMap)
+ err := usageMap.update(objs.IngressIp4UsageMap, objs.EgressIp4UsageMap)
+ if err != nil {
+ log.Printf("updating usageMap: %s", err)
+ }
+
case <-dbTicker.C:
- usageMap.dbPush(queries, ctxDb)
- continue
+ err := usageMap.updateDb(queries, ctxDb)
+ if err != nil {
+ log.Printf("updating Database: %s", err)
+ }
}
}
}
@@ -80,7 +86,7 @@ func (usageStat UsageStat) expired(timeStart *time.Time) bool {
return false
}
-func (usageMap UsageMap) dbPush(queries *db.Queries, ctxDb context.Context) {
+func (usageMap UsageMap) updateDb(queries *db.Queries, ctxDb context.Context) error {
timeStart := time.Now()
for key, value := range usageMap {
@@ -102,14 +108,16 @@ func (usageMap UsageMap) dbPush(queries *db.Queries, ctxDb context.Context) {
Ingress: int32(value.ingress),
})
if err != nil {
- log.Println(err)
+ return err
}
delete(usageMap, key)
}
+
+ return nil
}
-func (usageMap UsageMap) update(ingress *ebpf.Map, egress *ebpf.Map) {
+func (usageMap UsageMap) update(ingress *ebpf.Map, egress *ebpf.Map) error {
timeStart := time.Now()
batchKeys := make([]uint32, 4096)
batchValues := make([]uint64, 4096)
@@ -137,8 +145,7 @@ func (usageMap UsageMap) update(ingress *ebpf.Map, egress *ebpf.Map) {
if errors.Is(err, ebpf.ErrKeyNotExist) {
break
} else if err != nil {
- fmt.Println(err)
- break
+ return err;
}
}
@@ -164,8 +171,9 @@ func (usageMap UsageMap) update(ingress *ebpf.Map, egress *ebpf.Map) {
if errors.Is(err, ebpf.ErrKeyNotExist) {
break
} else if err != nil {
- fmt.Println(err)
- break
+ return err
}
}
+
+ return nil
}