Skip to content
Snippets Groups Projects
Commit 34f4dcf4 authored by S.H.'s avatar S.H.
Browse files

Add benchmark measurements

parent af732489
Branches
Tags
No related merge requests found
Pipeline #270498 failed
package rtdt_benchmark
import (
"encoding/json"
"fmt"
"os"
"time"
)
type Rtdt_Benchmark struct {
MneGnmiRcv time.Time
MneGnmiSend time.Time
}
var CurrentBenchmark Rtdt_Benchmark
func AppendToJsonFile(r *Rtdt_Benchmark) {
var benchmarks []Rtdt_Benchmark
if _, err := os.Stat("/etc/gnmi-target/mne_share/measure_mne.json"); err == nil {
data, err := os.ReadFile("/etc/gnmi-target/mne_share/measure_mne.json")
if err != nil {
fmt.Println("Error reading file:", err)
return
}
if len(data) > 0 {
err = json.Unmarshal(data, &benchmarks)
if err != nil {
fmt.Println("Error unmarshaling JSON:", err)
return
}
}
} else if !os.IsNotExist(err) {
fmt.Println("Error checking file status:", err)
return
}
// Append the new benchmark
benchmarks = append(benchmarks, *r)
// Marshal and write back to file
outData, err := json.MarshalIndent(benchmarks, "", " ")
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return
}
err = os.WriteFile("/etc/gnmi-target/mne_share/measure_mne.json", outData, 0644)
if err != nil {
fmt.Println("Error writing to file:", err)
}
}
......@@ -37,6 +37,7 @@ import (
"github.com/openconfig/ygot/ytypes"
"google.golang.org/protobuf/proto"
rtdt_benchmark "code.fbi.h-da.de/danet/gnmi-target/benchmark"
"code.fbi.h-da.de/danet/gnmi-target/handler"
not "code.fbi.h-da.de/danet/gnmi-target/internal/notifications"
dpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
......@@ -145,7 +146,7 @@ func (s *Server) callback(newConfig ygot.ValidatedGoStruct, existingConf ygot.Va
// TODO: This will be moved.
func (s *Server) PublishNotificationsToSubscribers(notifications []*gnmi.Notification) error {
fmt.Println("In PublishNotificationsToSubscribers()")
fmt.Println("Notifications:", notifications)
fmt.Println("Notifications:", notifications)
for _, specificDiff := range notifications {
// First for gnmi Updates
updates := specificDiff.GetUpdate()
......@@ -700,6 +701,8 @@ func (s *Server) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetResponse,
// Set implements the Set RPC in gNMI spec.
func (s *Server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse, error) {
rtdt_benchmark.CurrentBenchmark = rtdt_benchmark.Rtdt_Benchmark{}
rtdt_benchmark.CurrentBenchmark.MneGnmiRcv = time.Now()
s.config.Lock()
defer s.config.Unlock()
......@@ -770,6 +773,7 @@ func (s *Server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse,
s.config.Data = rootStruct
// notify subscribers about the changes
fmt.Println("------------ In Set(): diff is:", diff)
err = s.PublishNotificationsToSubscribers(diff)
if err != nil {
msg := fmt.Sprintf("error while publishing config changes to subscribers: %v", err)
......@@ -777,10 +781,12 @@ func (s *Server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse,
return nil, status.Error(codes.Internal, msg)
}
rtdt_benchmark.CurrentBenchmark.MneGnmiSend = time.Now()
rtdt_benchmark.AppendToJsonFile(&rtdt_benchmark.CurrentBenchmark)
return &pb.SetResponse{
Prefix: req.GetPrefix(),
Response: results,
Timestamp: time.Now().UnixNano(),
Timestamp: rtdt_benchmark.CurrentBenchmark.MneGnmiSend.UnixNano(),
}, nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment