Skip to content
Snippets Groups Projects
Commit 6cb82633 authored by Tigran Avakyan's avatar Tigran Avakyan
Browse files

Added conf params. Still need to call TransmitGetMeasure

parent dc69fcba
Branches
Tags
No related merge requests found
...@@ -360,6 +360,22 @@ func ReceiveFinishRealtime(instance *server.Instance, ...@@ -360,6 +360,22 @@ func ReceiveFinishRealtime(instance *server.Instance,
} }
p.Measure(tag) p.Measure(tag)
//Send the finished signal on first node
if r.GetTopology().IsFirstNode(instance.GetID()) {
jww.INFO.Printf("[%s]: RID %d FIRST NODE ReceiveFinishRealtime"+
" Retrieving and storing metrics", instance, roundID)
// TODO: Where does this go?
//nodeComms := instance.GetNetwork()
//measures = io.TransmitGetMeasure(nodeComms, instance.GetTopology(),roundID)
//logFile = instance.GetMetricsLog()
//if logFile != "" {
// go measure.AppendToMetricsLog(logFile, measures)
//}
}
p.UpdateFinalStates() p.UpdateFinalStates()
if !instance.GetKeepBuffers() { if !instance.GetKeepBuffers() {
...@@ -384,7 +400,9 @@ func ReceiveFinishRealtime(instance *server.Instance, ...@@ -384,7 +400,9 @@ func ReceiveFinishRealtime(instance *server.Instance,
if r.GetTopology().IsFirstNode(instance.GetID()) { if r.GetTopology().IsFirstNode(instance.GetID()) {
jww.INFO.Printf("[%s]: RID %d FIRST NODE ReceiveFinishRealtime"+ jww.INFO.Printf("[%s]: RID %d FIRST NODE ReceiveFinishRealtime"+
" SENDING END ROUND SIGNAL", instance, roundID) " SENDING END ROUND SIGNAL", instance, roundID)
instance.FinishRound(roundID) instance.FinishRound(roundID)
} }
return nil return nil
......
...@@ -939,6 +939,9 @@ func TestReceiveFinishRealtime(t *testing.T) { ...@@ -939,6 +939,9 @@ func TestReceiveFinishRealtime(t *testing.T) {
Ids: buildMockNodeIDs(numNodes), Ids: buildMockNodeIDs(numNodes),
}, },
Index: 0, Index: 0,
Metrics: conf.Metrics{
Log: "",
},
} }
instance := server.CreateServerInstance(&params, &globals.UserMap{}, instance := server.CreateServerInstance(&params, &globals.UserMap{},
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2019 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package conf
// Contains metrics information such as log path
type Metrics struct {
Log string
}
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2019 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package conf
import (
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"testing"
)
var ExpectedMetrics = Metrics{
Log: "~/.elixxir/metrics.log",
}
// This test checks that unmarshalling the params.yaml file
// has the expected Database object.
func TestMetrics_UnmarshallingFileEqualsExpected(t *testing.T) {
buf, _ := ioutil.ReadFile("./params.yaml")
actual := Params{}
err := yaml.Unmarshal(buf, &actual)
if err != nil {
t.Errorf("Unable to decode into struct, %v", err)
}
if !reflect.DeepEqual(ExpectedMetrics, actual.Metrics) {
t.Errorf("Metrics object did not match value")
}
}
...@@ -27,6 +27,7 @@ type Params struct { ...@@ -27,6 +27,7 @@ type Params struct {
Database Database Database Database
Gateways Gateways Gateways Gateways
Permissioning Permissioning Permissioning Permissioning
Metrics Metrics
} }
// NewParams gets elements of the viper object // NewParams gets elements of the viper object
...@@ -66,6 +67,8 @@ func NewParams(vip *viper.Viper) (*Params, error) { ...@@ -66,6 +67,8 @@ func NewParams(vip *viper.Viper) (*Params, error) {
params.Groups.CMix = vip.GetStringMapString("groups.cmix") params.Groups.CMix = vip.GetStringMapString("groups.cmix")
params.Groups.E2E = vip.GetStringMapString("groups.e2e") params.Groups.E2E = vip.GetStringMapString("groups.e2e")
params.Metrics.Log = vip.GetString("metrics.log")
// In the event IDs are not able to be provided, // In the event IDs are not able to be provided,
// we can hash the node addresses as a workaround // we can hash the node addresses as a workaround
if len(params.Node.Ids) == 0 { if len(params.Node.Ids) == 0 {
......
...@@ -48,4 +48,6 @@ batch: 20 ...@@ -48,4 +48,6 @@ batch: 20
verbose: true verbose: true
skipReg: true skipReg: true
keepBuffers: true keepBuffers: true
metrics:
log: "~/.elixxir/metrics.log"
... ...
...@@ -26,6 +26,7 @@ func TestNewParams_ReturnsParamsWhenGivenValidViper(t *testing.T) { ...@@ -26,6 +26,7 @@ func TestNewParams_ReturnsParamsWhenGivenValidViper(t *testing.T) {
Database: ExpectedDatabase, Database: ExpectedDatabase,
Gateways: ExpectedGateways, Gateways: ExpectedGateways,
Permissioning: ExpectedPermissioning, Permissioning: ExpectedPermissioning,
Metrics: ExpectedMetrics,
} }
vip := viper.New() vip := viper.New()
...@@ -80,4 +81,8 @@ func TestNewParams_ReturnsParamsWhenGivenValidViper(t *testing.T) { ...@@ -80,4 +81,8 @@ func TestNewParams_ReturnsParamsWhenGivenValidViper(t *testing.T) {
if !reflect.DeepEqual(expectedParams.Gateways, params.Gateways) { if !reflect.DeepEqual(expectedParams.Gateways, params.Gateways) {
t.Errorf("Params gateways value does not match expected value") t.Errorf("Params gateways value does not match expected value")
} }
if !reflect.DeepEqual(expectedParams.Metrics, params.Metrics) {
t.Errorf("Params metrics value does not match expected value")
}
} }
...@@ -108,6 +108,11 @@ func (i *Instance) GetGraphGenerator() services.GraphGenerator { ...@@ -108,6 +108,11 @@ func (i *Instance) GetGraphGenerator() services.GraphGenerator {
return i.graphGenerator return i.graphGenerator
} }
// GetMetricsLog returns the log path for metrics data
func (i *Instance) GetMetricsLog() string {
return i.params.Metrics.Log
}
//Initializes the first node components of the instance //Initializes the first node components of the instance
func (i *Instance) InitFirstNode() { func (i *Instance) InitFirstNode() {
i.firstNode.Initialize() i.firstNode.Initialize()
......
package measure package measure
import ( import (
"os"
"sync" "sync"
"time" "time"
) )
...@@ -45,3 +46,22 @@ func (m *Metrics) Measure(tag string) time.Time { ...@@ -45,3 +46,22 @@ func (m *Metrics) Measure(tag string) time.Time {
return measure.Timestamp return measure.Timestamp
} }
// AppendToMetricsLog appends a measures to
// a log file which is located in logPath
func AppendToMetricsLog(logPath, measures string) {
f, err := os.OpenFile(logPath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
// warning
}
defer func() {
if f != nil {
_ = f.Close()
}
}()
_, err = f.WriteString(measures)
if err != nil {
// warning
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment