Commit aed88f78 authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

rebase to develop

parent e7f904cb
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ func CtrlEngineInit() (err error) {
	}

	// Connect to Metric Store
	metricStore, err = ms.NewMetricStore("", influxDBAddr)
	metricStore, err = ms.NewMetricStore("", influxDBAddr, redisDBAddr)
	if err != nil {
		log.Error("Failed connection to Redis: ", err)
		return err
@@ -596,7 +596,9 @@ func ceSendEvent(w http.ResponseWriter, r *http.Request) {
	// Log successful event in metric store
	eventStr, err := json.Marshal(event)
	if err == nil {
		err = metricStore.SetEventMetric(eventType, string(eventStr))
		var metric ms.EventMetric
		metric.Event = string(eventStr)
		err = metricStore.SetEventMetric(eventType, metric)
	}
	if err != nil {
		log.Error("Failed to set event metric")
+0 −78
Original line number Diff line number Diff line
/*
 * Copyright (c) 2019  InterDigital Communications, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package server

import (
	"net/http"

	v1 "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server/v1"
	v2 "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server/v2"
)

// Init - Metrics engine initialization
func Init() (err error) {
	//no v1.Init()
	err = v2.Init()
	if err != nil {
		return err
	}
	return nil
}

func MetricsGet(w http.ResponseWriter, r *http.Request) {
	v1.MetricsGet(w, r)
}

func PostEventQuery(w http.ResponseWriter, r *http.Request) {
	v2.PostEventQuery(w, r)
}

func PostNetworkQuery(w http.ResponseWriter, r *http.Request) {
	v2.PostNetworkQuery(w, r)
}

func CreateEventSubscription(w http.ResponseWriter, r *http.Request) {
	v2.CreateEventSubscription(w, r)
}

func CreateNetworkSubscription(w http.ResponseWriter, r *http.Request) {
	v2.CreateNetworkSubscription(w, r)
}

func DeleteEventSubscriptionById(w http.ResponseWriter, r *http.Request) {
	v2.DeleteEventSubscriptionById(w, r)
}

func DeleteNetworkSubscriptionById(w http.ResponseWriter, r *http.Request) {
	v2.DeleteNetworkSubscriptionById(w, r)
}

func GetEventSubscription(w http.ResponseWriter, r *http.Request) {
	v2.GetEventSubscription(w, r)
}

func GetEventSubscriptionById(w http.ResponseWriter, r *http.Request) {
	v2.GetEventSubscriptionById(w, r)
}

func GetNetworkSubscription(w http.ResponseWriter, r *http.Request) {
	v2.GetNetworkSubscription(w, r)
}

func GetNetworkSubscriptionById(w http.ResponseWriter, r *http.Request) {
	v2.GetNetworkSubscriptionById(w, r)
}
+24 −12
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ import (
	"strings"

	"github.com/gorilla/mux"

	v1 "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server/v1"
	v2 "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server/v2"
)

type Route struct {
@@ -65,6 +68,15 @@ func IndexV2(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello World! on v2")
}

func Init() (err error) {
	//no v1.Init()
	err = v2.Init()
	if err != nil {
		return err
	}
	return nil
}

var routes = Routes{
	Route{
		"Index",
@@ -77,83 +89,83 @@ var routes = Routes{
		"MetricsGet",
		strings.ToUpper("Get"),
		"/v1/metrics",
		MetricsGet,
		v1.MetricsGet,
	},

	Route{
		"IndexV2",
		"GET",
		"/v2/",
		Index,
		IndexV2,
	},

	Route{
		"PostEventQuery",
		strings.ToUpper("Post"),
		"/v2/metrics/query/event",
		PostEventQuery,
		v2.PostEventQuery,
	},

	Route{
		"PostNetworkQuery",
		strings.ToUpper("Post"),
		"/v2/metrics/query/network",
		PostNetworkQuery,
		v2.PostNetworkQuery,
	},

	Route{
		"CreateEventSubscription",
		strings.ToUpper("Post"),
		"/v2/metrics/subscriptions/event",
		CreateEventSubscription,
		v2.CreateEventSubscription,
	},

	Route{
		"CreateNetworkSubscription",
		strings.ToUpper("Post"),
		"/v2/metrics/subscriptions/network",
		CreateNetworkSubscription,
		v2.CreateNetworkSubscription,
	},

	Route{
		"DeleteEventSubscriptionById",
		strings.ToUpper("Delete"),
		"/v2/metrics/subscriptions/event/{subscriptionId}",
		DeleteEventSubscriptionById,
		v2.DeleteEventSubscriptionById,
	},

	Route{
		"DeleteNetworkSubscriptionById",
		strings.ToUpper("Delete"),
		"/v2/metrics/subscriptions/network/{subscriptionId}",
		DeleteNetworkSubscriptionById,
		v2.DeleteNetworkSubscriptionById,
	},

	Route{
		"GetEventSubscription",
		strings.ToUpper("Get"),
		"/v2/metrics/subscriptions/event",
		GetEventSubscription,
		v2.GetEventSubscription,
	},

	Route{
		"GetEventSubscriptionById",
		strings.ToUpper("Get"),
		"/v2/metrics/subscriptions/event/{subscriptionId}",
		GetEventSubscriptionById,
		v2.GetEventSubscriptionById,
	},

	Route{
		"GetNetworkSubscription",
		strings.ToUpper("Get"),
		"/v2/metrics/subscriptions/network",
		GetNetworkSubscription,
		v2.GetNetworkSubscription,
	},

	Route{
		"GetNetworkSubscriptionById",
		strings.ToUpper("Get"),
		"/v2/metrics/subscriptions/network/{subscriptionId}",
		GetNetworkSubscriptionById,
		v2.GetNetworkSubscriptionById,
	},
}
+6 −22
Original line number Diff line number Diff line
@@ -36,8 +36,7 @@ import (

const influxDBAddr = "http://meep-influxdb:8086"
const metricEvent = "events"
const metricLatency = "latency"
const metricTraffic = "traffic"
const metricNetwork = "network"

const moduleName string = "meep-metrics-engine"
const redisAddr string = "meep-redis-master:6379"
@@ -132,7 +131,7 @@ func processActiveScenarioUpdate(event string) {
func activateScenario() {
	// Connect to Metric Store
	var err error
	metricStore, err = ms.NewMetricStore(activeScenarioName, influxDBAddr)
	metricStore, err = ms.NewMetricStore(activeScenarioName, influxDBAddr, redisAddr)
	if err != nil {
		log.Error("Failed connection to Influx: ", err)
		return
@@ -192,23 +191,8 @@ func meGetMetrics(w http.ResponseWriter, r *http.Request, metricType string) (me
		getTags[tmpTags["name"]] = tmpTags["value"]
	}

	//	var getFields []string
	for _, field := range params.Fields {
		//		getFields = append(getFields, field)
		//temporary code to differentiate looking at 2 different tables
		if metricType != metricEvent {
			if metricType == "tbd" {
				//takes latency as soon as latency is part of the query
				if field == "lat" {
					metricType = metricLatency
				} else {
					metricType = metricTraffic
				}
			}
		}
	}
	if metricStore != nil {
		metrics, err = metricStore.GetMetric(metricType, getTags, params.Fields, params.Scope.Duration, int(params.Scope.Limit))
		metrics, err = metricStore.GetInfluxMetric(metricType, getTags, params.Fields, params.Scope.Duration, int(params.Scope.Limit))

		responseColumns = params.Fields
		responseColumns = append(responseColumns, "time")
@@ -261,7 +245,7 @@ func mePostEventQuery(w http.ResponseWriter, r *http.Request) {
}

func mePostNetworkQuery(w http.ResponseWriter, r *http.Request) {
	metrics, respColumns, err := meGetMetrics(w, r, "tbd")
	metrics, respColumns, err := meGetMetrics(w, r, metricNetwork)

	if err != nil {
		log.Error(err.Error())
@@ -500,7 +484,7 @@ func processEventNotification(subsId string) {

		if metricStore != nil {

			metrics, err := metricStore.GetMetric(metricEvent, eventRegistration.requestedTags, eventRegistration.params.EventQueryParams.Fields, eventRegistration.params.EventQueryParams.Scope.Duration, int(eventRegistration.params.EventQueryParams.Scope.Limit))
			metrics, err := metricStore.GetInfluxMetric(metricEvent, eventRegistration.requestedTags, eventRegistration.params.EventQueryParams.Fields, eventRegistration.params.EventQueryParams.Scope.Duration, int(eventRegistration.params.EventQueryParams.Scope.Limit))

			if err == nil {
				response.Columns = eventRegistration.params.EventQueryParams.Fields
@@ -538,7 +522,7 @@ func processNetworkNotification(subsId string) {
		response.Name = "network metrics"

		if metricStore != nil {
			metrics, err := metricStore.GetMetric(metricLatency, networkRegistration.requestedTags, networkRegistration.params.NetworkQueryParams.Fields, networkRegistration.params.NetworkQueryParams.Scope.Duration, int(networkRegistration.params.NetworkQueryParams.Scope.Limit))
			metrics, err := metricStore.GetInfluxMetric(metricNetwork, networkRegistration.requestedTags, networkRegistration.params.NetworkQueryParams.Fields, networkRegistration.params.NetworkQueryParams.Scope.Duration, int(networkRegistration.params.NetworkQueryParams.Scope.Limit))

			if err == nil {
				response.Columns = networkRegistration.params.NetworkQueryParams.Fields
+8 −10
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import (
	"time"

	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
	ms "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-metric-store"
)

const moduleMetrics string = "metrics"
@@ -266,20 +267,17 @@ func (u *destination) logRxTx() {
	u.prevRxLog.rxPkt = curRxPkt
	u.prevRxLog.rxPktDrop = curRxPktDrop

	// Store traffic metric
	err = metricStore.SetTrafficMetric(u.remoteName, PodName, tput, loss)
	if err != nil {
		log.Error("Failed to set traffic metric")
	}
	// Store latency metric
	// Store network metric
	srcDest := u.hostName + ":" + u.remoteName

	var metric ms.NetworkMetric
	semLatencyMap.Lock()
	err = metricStore.SetLatencyMetric(u.hostName, u.remoteName, latestLatencyResultsMap[srcDest])
	metric.Lat = latestLatencyResultsMap[srcDest]
	semLatencyMap.Unlock()

	metric.Tput = tput
	metric.Loss = loss
	err = metricStore.SetCachedNetworkMetric(u.remoteName, u.hostName, metric)
	if err != nil {
		log.Error("Failed to set latency metric")
		log.Error("Failed to set network metric")
	}

	log.WithFields(log.Fields{
Loading