Unverified Commit 220aa434 authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #94 from pastorsx/sp_dev_loc-serv-rnis-remove-ue

New js-packages, metrics-engine http endpoint
parents 7532e969 d86f59c6
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ repo:
          meep-platform-ctrl-api: js-packages/meep-platform-ctrl-client
          meep-sandbox-ctrl-api: js-packages/meep-sandbox-ctrl-client
          meep-mon-engine-api: js-packages/meep-mon-engine-client
          meep-gis-engine-api: js-packages/meep-gis-engine-client
      meep-platform-swagger-ui:
        src: js-apps/meep-swagger-ui
        bin: bin/meep-platform-swagger-ui
@@ -253,13 +254,13 @@ repo:
      meep-logger:
        src: go-packages/meep-logger
        lint: true
      meep-metric-store:
        src: go-packages/meep-metric-store
        lint: true
      meep-metrics-engine-notification-client:
        src: go-packages/meep-metrics-engine-notification-client
        lint: false
        api: go-packages/meep-metrics-engine-notification-client/api/swagger.yaml
      meep-metric-store:
        src: go-packages/meep-metric-store
        lint: true
      meep-mg-app-client:
        src: go-packages/meep-mg-app-client
        lint: false
@@ -307,6 +308,9 @@ repo:

    # Javascript Packages
    js-packages:
      meep-metrics-engine-client:
        src: js-packages/meep-metrics-engine-client
        lint: false
      meep-mon-engine-client:
        src: js-packages/meep-mon-engine-client
        lint: false
@@ -316,3 +320,4 @@ repo:
      meep-sandbox-ctrl-client:
        src: js-packages/meep-sandbox-ctrl-client
        lint: false
+217 −22
Original line number Diff line number Diff line
@@ -22,6 +22,31 @@ consumes:
produces:
- "application/json"
paths:
  /metrics/query/http:
    post:
      tags:
      - "Metrics"
      description: "Returns Http metrics according to specificed parameters"
      operationId: "postHttpQuery"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "params"
        description: "Query parameters"
        required: true
        schema:
          $ref: "#/definitions/HttpQueryParams"
        x-exportParamName: "Params"
      responses:
        200:
          description: "OK"
          schema:
            $ref: "#/definitions/HttpMetricList"
        404:
          description: "Not found"
        500:
          description: "Internal server error"
  /metrics/query/network:
    post:
      tags:
@@ -239,49 +264,61 @@ paths:
        500:
          description: "Internal server error"
definitions:
  NetworkQueryParams:
  HttpQueryParams:
    type: "object"
    properties:
      tags:
        type: "array"
        description: "Tag names to match in query. Supported values:<br> <li>src:\
          \ Source network element name <li>dest: Destination network element name"
        description: "Tag names to match in query. Supported values:<br> <li>logger_name:\
          \ Logger instances that issued the http notification or processed the request\
          \ <li>direction: Notification or Request type of http metric"
        items:
          $ref: "#/definitions/Tag"
      fields:
        type: "array"
        description: "Field names to return in query response. Supported values:<br>\
          \ <li>lat: Round-trip latency (ms)<br> <li>ul: Uplink throughput from src\
          \ to dest (Mbps) <li>dl: Downlink throughput from dest to src (Mbps) <li>ulos:\
          \ Uplink packet loss from src to dest (%) <li>dlos: Downlink packet loss\
          \ from dest to src (%)"
          \ <li>id: Http metrics identifier<br> <li>endpoint: Http metrics queried\
          \ endpoint<br> <li>url: Http metrics queried endpoint with query parameters<br>\
          \ <li>method: Http metrics method<br> <li>resp_code: Http metrics response\
          \ status code<br> <li>resp_body: Http metrics response body<br> <li>body:\
          \ Http metrics body<br> <li>proc_time: Request processing time in ms"
        items:
          type: "string"
          description: "Queried value"
          enum:
          - "lat"
          - "ul"
          - "dl"
          - "ulos"
          - "dlos"
          - "id"
          - "endpoint"
          - "url"
          - "method"
          - "resp_code"
          - "resp_body"
          - "body"
          - "proc_time"
          - "logger_name"
          - "direction"
      scope:
        $ref: "#/definitions/Scope"
    description: "Network metrics query parameters"
    description: "Http metrics query parameters"
    example:
      scope:
        duration: "10s"
        limit: 60
      fields:
      - "lat"
      - "ul"
      - "dl"
      - "ulos"
      - "dlos"
      - "id"
      - "endpoint"
      - "url"
      - "method"
      - "resp_code"
      - "resp_body"
      - "body"
      - "proc_time"
      - "logger_name"
      - "direction"
      tags:
      - name: "src"
        value: "ue1-iperf"
      - name: "dest"
        value: "zone1-fog1-iperf"
      - name: "logger_name"
        value: "meep-loc-serv"
      - name: "direction"
        value: "RX"
  Tag:
    type: "object"
    properties:
@@ -313,6 +350,164 @@ definitions:
    example:
      duration: "10s"
      limit: 60
  HttpMetricList:
    type: "object"
    properties:
      name:
        type: "string"
        example: "http metrics"
        description: "Response name"
      columns:
        type: "array"
        description: "columns included in response based on queried values"
        items:
          type: "string"
          description: "Queried value"
      values:
        type: "array"
        items:
          $ref: "#/definitions/HttpMetric"
    description: "Http metrics query response"
    example:
      columns:
      - "time"
      - "id"
      - "endpoint"
      - "url"
      - "method"
      - "resp_code"
      - "resp_body"
      - "body"
      - "proc_time"
      - "logger_name"
      - "direction"
      values:
      - time: "2019-11-24T12:45:00-5:00"
        id: 5
        endpoint: "/location/v1/subscription/userTracking"
        url: "/location/v1/subscription/userTracking?validQueryParam"
        method: "GET"
        resp_code: 200
        resp_body: {}
        body: {}
        proc_time: 345
        logger_name: "loc-serv"
        direction: "RX"
      - time: "2019-11-24T12:45:00-5:00"
        id: 6
        endpoint: "/location/v1/subscription/userTracking"
        url: "/location/v1/subscription/userTracking?validQueryParam"
        method: "GET"
        resp_code: 200
        resp_body: {}
        body: {}
        proc_time: 456
        logger_name: "loc-serv"
        direction: "RX"
      name: "http metrics"
  HttpMetric:
    type: "object"
    properties:
      time:
        type: "string"
        example: "2019-11-24T12:45:00-5:00"
        description: "Time of http metrics"
      id:
        type: "integer"
        example: 5
        description: "Http metrics identifier"
      endpoint:
        type: "string"
        example: "/location/v1/subscription/userTracking"
        description: "Http metrics queried endpoint"
      url:
        type: "string"
        example: "/location/v1/subscription/userTracking?validQueryParam"
        description: "Http metrics queried endpoint with query parameters"
      method:
        type: "string"
        example: "GET"
        description: "Http metrics method"
      resp_code:
        type: "string"
        example: "200"
        description: "Http metrics response status code"
      resp_body:
        type: "string"
        example: "{}"
        description: "Http metrics response body"
      body:
        type: "string"
        example: "{}"
        description: "Http metrics body"
      proc_time:
        type: "string"
        example: "345"
        description: "Request processing time in ms"
      logger_name:
        type: "string"
        example: "loc-serv"
        description: "Service processing the http metric"
      direction:
        type: "string"
        example: "Request"
        description: "Http type"
    description: "Value of a single http metric"
    example:
      time: "2019-11-24T12:45:00-5:00"
      id: 5
      endpoint: "/location/v1/subscription/userTracking"
      url: "/location/v1/subscription/userTracking?validQueryParam"
      method: "GET"
      resp_code: 200
      resp_body: {}
      body: {}
      proc_time: 345
      logger_name: "loc-serv"
      direction: "Request"
  NetworkQueryParams:
    type: "object"
    properties:
      tags:
        type: "array"
        description: "Tag names to match in query. Supported values:<br> <li>src:\
          \ Source network element name <li>dest: Destination network element name"
        items:
          $ref: "#/definitions/Tag"
      fields:
        type: "array"
        description: "Field names to return in query response. Supported values:<br>\
          \ <li>lat: Round-trip latency (ms)<br> <li>ul: Uplink throughput from src\
          \ to dest (Mbps) <li>dl: Downlink throughput from dest to src (Mbps) <li>ulos:\
          \ Uplink packet loss from src to dest (%) <li>dlos: Downlink packet loss\
          \ from dest to src (%)"
        items:
          type: "string"
          description: "Queried value"
          enum:
          - "lat"
          - "ul"
          - "dl"
          - "ulos"
          - "dlos"
      scope:
        $ref: "#/definitions/Scope"
    description: "Network metrics query parameters"
    example:
      scope:
        duration: "10s"
        limit: 60
      fields:
      - "lat"
      - "ul"
      - "dl"
      - "ulos"
      - "dlos"
      tags:
      - name: "src"
        value: "ue1-iperf"
      - name: "dest"
        value: "zone1-fog1-iperf"
  NetworkMetricList:
    type: "object"
    properties:
+7 −0
Original line number Diff line number Diff line
@@ -97,6 +97,13 @@ var routes = Routes{
		v2.PostEventQuery,
	},

	Route{
		"PostHttpQuery",
		strings.ToUpper("Post"),
		"/metrics/v2/metrics/query/http",
		v2.PostHttpQuery,
	},

	Route{
		"PostNetworkQuery",
		strings.ToUpper("Post"),
+4 −0
Original line number Diff line number Diff line
@@ -32,6 +32,10 @@ func PostEventQuery(w http.ResponseWriter, r *http.Request) {
	mePostEventQuery(w, r)
}

func PostHttpQuery(w http.ResponseWriter, r *http.Request) {
	mePostHttpQuery(w, r)
}

func PostNetworkQuery(w http.ResponseWriter, r *http.Request) {
	mePostNetworkQuery(w, r)
}
+124 −0
Original line number Diff line number Diff line
@@ -335,6 +335,130 @@ func mePostEventQuery(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, string(jsonResponse))
}

func mePostHttpQuery(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Debug("mePostHttpQuery")

	// Retrieve network metric query parameters from request body
	var params HttpQueryParams
	if r.Body == nil {
		err := errors.New("Request body is missing")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&params)
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Make sure metrics store is up
	if metricStore == nil {
		err := errors.New("No active scenario to get metrics from")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}

	// Parse tags
	tags := make(map[string]string)
	for _, tag := range params.Tags {
		tags[tag.Name] = tag.Value
	}

	// Get scope
	duration := ""
	limit := 0
	if params.Scope != nil {
		duration = params.Scope.Duration
		limit = int(params.Scope.Limit)
	}
	// Get metrics
	valuesArray, err := metricStore.GetInfluxMetric(ms.HttpLogMetricName, tags, params.Fields, duration, limit)
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if len(valuesArray) == 0 {
		err := errors.New("No matching metrics found")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}

	// Prepare & send response
	var response HttpMetricList
	response.Name = "http metrics"
	response.Columns = append(params.Fields, "time")
	response.Values = make([]HttpMetric, len(valuesArray))
	for index, values := range valuesArray {
		metric := &response.Values[index]
		metric.Time = values["time"].(string)
		if values[ms.HttpLoggerName] != nil {
			if val, ok := values[ms.HttpLoggerName].(string); ok {
				metric.LoggerName = val
			}
		}
		if values[ms.HttpLoggerDirection] != nil {
			if val, ok := values[ms.HttpLoggerDirection].(string); ok {
				metric.Direction = val
			}
		}

		if values[ms.HttpLogId] != nil {
			metric.Id = ms.JsonNumToInt32(values[ms.HttpLogId].(json.Number))
		}
		if values[ms.HttpLogEndpoint] != nil {
			if val, ok := values[ms.HttpLogEndpoint].(string); ok {
				metric.Endpoint = val
			}
		}
		if values[ms.HttpUrl] != nil {
			if val, ok := values[ms.HttpUrl].(string); ok {
				metric.Url = val
			}
		}
		if values[ms.HttpMethod] != nil {
			if val, ok := values[ms.HttpMethod].(string); ok {
				metric.Method = val
			}
		}
		if values[ms.HttpBody] != nil {
			if val, ok := values[ms.HttpBody].(string); ok {
				metric.Body = val
			}
		}
		if values[ms.HttpRespBody] != nil {
			if val, ok := values[ms.HttpRespBody].(string); ok {
				metric.RespBody = val
			}
		}
		if values[ms.HttpRespCode] != nil {
			if val, ok := values[ms.HttpRespCode].(string); ok {
				metric.RespCode = val
			}
		}
		if values[ms.HttpProcTime] != nil {
			if val, ok := values[ms.HttpProcTime].(string); ok {
				metric.ProcTime = val
			}
		}
	}

	jsonResponse, err := json.Marshal(response)
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteHeader(http.StatusOK)
	fmt.Fprintf(w, string(jsonResponse))
}

func mePostNetworkQuery(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Debug("mePostNetworkQuery")
Loading