func TestPrometheusClientCounterWithFullLabels(t *testing.T) {
	config.Global.Set("prometheus.namelabel", true)
	config.Global.Set("prometheus.sitecodelabel", true)
	store := data.NewSimpleInMemoryStore()
	test.ExecuteCompletePipe(t, store)

	// It is kinda complicated to collect values from CounterVecs,
	// so for now this test simply makes sure that the application doesn't
	// crash if extended node labels are activated.
}
Example #2
0
func TestLoadingLegacyNodesJson(t *testing.T) {
	assert := assert.New(t)
	nodeJsonPath := "../../../../../../nodes.json"

	store := data.NewSimpleInMemoryStore()
	importer := &FFMapBackendDataLoader{Store: store}
	err := importer.LoadNodesFromFile(nodeJsonPath)
	assert.Nil(err)
	assert.True(0 < len(store.GetNodeInfos()))
}
Example #3
0
func TestCompletePipe(t *testing.T) {
	assert := assert.New(t)
	log.SetLevel(log.ErrorLevel)
	store := data.NewSimpleInMemoryStore()
	test.ExecuteCompletePipe(t, store)

	graphGenerator := &meshviewer.GraphGenerator{Store: store}
	nodesGenerator := &meshviewer.NodesJsonGenerator{Store: store}

	graph := graphGenerator.GenerateGraph()
	assert.NotNil(graph)
	assert.Equal(169, len(graph.Batadv.Nodes))
	assert.Equal(66, len(graph.Batadv.Links))

	nodes := nodesGenerator.GetNodesJson()
	assert.NotNil(nodes)
}
Example #4
0
func TestGeneratingNodeGraph(t *testing.T) {
	assert := assert.New(t)
	log.SetLevel(log.ErrorLevel)
	assert.True(true)
	store := data.NewSimpleInMemoryStore()
	test.ExecuteCompletePipe(t, store)

	graphGenerator := &GraphGenerator{Store: store}
	graphGenerator.UpdateGraphJson()

	graphData := &GraphJson{}
	err := json.Unmarshal([]byte(graphGenerator.cachedJsonString), graphData)

	assert.Nil(err)
	assert.NotNil(graphData)
	testForDoublettes(assert, graphData.Batadv.Nodes)
}
Example #5
0
func TestCorrectGraphFormat(t *testing.T) {
	assert := assert.New(t)
	store := data.NewSimpleInMemoryStore()
	for _, neighbour := range neighbourInfos {
		store.PutNodeNeighbours(neighbour)
	}
	store.PutNodeStatusInfo("001122334455", nodeStatus[0])

	graphGenerator := &GraphGenerator{Store: store}
	_, nodeList := graphGenerator.buildNodeTableAndList()
	assert.NotNil(nodeList)
	assert.Equal(1, len(nodeList))
	assert.Equal("001122334455", nodeList[0].NodeId)
	// Access to the map after unmarshalling has no stable order, so both bat macs
	// could be in the id field, but either way should be fine
	assert.True(nodeList[0].Id == "001122aa44aa" || nodeList[0].Id == "001122aa44cc")
}
Example #6
0
func CreateDataStore() {
	dbType := conf.UString("store.type", "memory")
	switch dbType {
	case "memory":
		DataStore = data.NewSimpleInMemoryStore()
	case "bolt":
		storagePath := conf.UString("store.path", "/opt/gluon-collector/collector.db")
		boltStore, err := data.NewBoltStore(storagePath)
		if err != nil {
			log.WithFields(log.Fields{
				"error":     err,
				"storePath": storagePath,
				"storeType": dbType,
			}).Fatal("Can't create bolt store")
		} else {
			Closeables = append(Closeables, boltStore)
			DataStore = boltStore
		}
	default:
		log.Fatalf("Unknown store type %s", dbType)
	}
}
Example #7
0
func TestNodesJsonHasFlaggedUplinks(t *testing.T) {
	assert := assert.New(t)
	store := data.NewSimpleInMemoryStore()
	test.ExecuteCompletePipe(t, store)

	statistics := data.StatisticsStruct{}
	err := json.Unmarshal([]byte(uplinkStats), &statistics)
	assert.Nil(err)

	store.PutStatistics(statistics)

	generator := &NodesJsonGenerator{Store: store}
	nodesJson := generator.GetNodesJson()

	uplinkFound := false
	for _, node := range nodesJson.Nodes {
		if node.Flags.Uplink && node.Nodeinfo.NodeId == "e8de27252554" {
			uplinkFound = true
			break
		}
	}
	assert.True(uplinkFound, "No node was flagged as uplink")

	statistics = data.StatisticsStruct{}
	err = json.Unmarshal([]byte(nonUplinkStats), &statistics)
	assert.Nil(err)

	uplinkFound = false
	store.PutStatistics(statistics)
	nodesJson = generator.GetNodesJson()
	for _, node := range nodesJson.Nodes {
		if !node.Flags.Uplink && node.Nodeinfo.NodeId == "e8de27252554" {
			uplinkFound = true
			break
		}
	}
	assert.True(uplinkFound, "A node was not correctly flagged")
}
func TestPrometheusClientCounter(t *testing.T) {
	assert := assert.New(t)
	assert.True(true)

	var expectedClientCounts = []float64{13, 11, 15}
	finishChan := make(chan bool)

	store := data.NewSimpleInMemoryStore()
	processPipeline := pipeline.NewProcessPipeline(&prometheus.ClientCountPipe{Store: store},
		&collectors.StatisticsCollector{Store: store})

	prometheus.TotalClientCounter.Set(10.0)

	var packetCount int = 0
	go processPipeline.Dequeue(func(response data.ParsedResponse) {
		value := collectGaugeValue(prometheus.TotalClientCounter)
		assert.Equal(expectedClientCounts[packetCount], value)
		packetCount = packetCount + 1
		if packetCount == len(expectedClientCounts) {
			finishChan <- true
			close(finishChan)
		}
	})

	feedClientsStat(processPipeline, 3)
	// Give the collector pipe a little time to execute its go routin
	// in production it is very very unrealistic that we will have two Statistics
	// Responses from the same node in the channel at the same time.
	time.Sleep(time.Millisecond * 50)
	feedClientsStat(processPipeline, 1)
	time.Sleep(time.Millisecond * 50)
	feedClientsStat(processPipeline, 5)

	for range finishChan {
		processPipeline.Close()
	}
}