yats.git

commit 92e4d568d93c07f514445faecc883cd7cc717f70

Author: Paolo Lulli <paolo@lulli.net>

Query logs written with different CN

 server/db/event.go | 12 ++++++++++++
 server/db/metric.go | 13 +++++++++++++
 server/model/models.go | 16 +++++++++-------
 server/rest/rest-event.go | 8 ++++++++
 server/rest/rest-metric.go | 8 ++++++++


diff --git a/server/db/event.go b/server/db/event.go
index d9738e187a22d647f706ba0b4f1fbd06c1a65c9a..0d53fa9772409a4401c3ec72e7cc9026a721b6d0 100644
--- a/server/db/event.go
+++ b/server/db/event.go
@@ -26,3 +26,15 @@ 	timeAsBytes, _ := tstamp.UTC().MarshalText()
 	q := fmt.Sprintf("insert into event ( id_client, etime, name) values ('%s','%s','%s');", idClient, string(timeAsBytes), eventName)
 	Session.Query(q).Exec()
 }
+func CanReadSourceEvent(idClient string, sourceApp string) bool {
+	m := map[string]interface{}{}
+
+	q := fmt.Sprintf(" SELECT name,app,type from sources where id_client='%s' and app='%s' and type='event';", idClient, sourceApp)
+	fmt.Println(q)
+	iter := Session.Query(q).Iter()
+
+	for iter.MapScan(m) {
+		return true
+	}
+	return false
+}




diff --git a/server/db/metric.go b/server/db/metric.go
index 8a42c2ca4f4f84330f4eb947419cf36885de5f88..bb357e5fcbb1d591eda31abbca0ee087910ba829 100644
--- a/server/db/metric.go
+++ b/server/db/metric.go
@@ -79,3 +79,16 @@ 	timeAsBytes, _ := tstamp.UTC().MarshalText()
 	q := fmt.Sprintf("insert into metric ( id_client, mtime, name, value) values ('%s','%s','%s','%s');", idClient, string(timeAsBytes), metricName, metricValue)
 	Session.Query(q).Exec()
 }
+
+func CanReadSourceMetric(idClient string, sourceApp string, metricName string) bool {
+	m := map[string]interface{}{}
+
+	q := fmt.Sprintf(" SELECT name,app,type from sources where id_client='%s' and app='%s' and type='metric' and name='%s';", idClient, sourceApp, metricName)
+	fmt.Println(q)
+	iter := Session.Query(q).Iter()
+
+	for iter.MapScan(m) {
+		return true
+	}
+	return false
+}




diff --git a/server/model/models.go b/server/model/models.go
index beaf4bfebe0e9c0d3bcea80049a276510b853aa8..7454b638278c3aac1594c6f8f72565700977bb67 100644
--- a/server/model/models.go
+++ b/server/model/models.go
@@ -44,14 +44,16 @@ 	Description string
 }
 
 type MetricSearchRequest struct {
-	From     int64  `json:"from" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
-	To       int64  `json:"to" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
-	IdClient string `json:"id_client" parquet:"name=id_client, type=BYTE_ARRAY, convertedtype=UTF8"`
-	Name     string `json:"name" parquet:"name=name, type=BYTE_ARRAY, convertedtype=UTF8"`
+	From              int64  `json:"from" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
+	To                int64  `json:"to" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
+	IdClient          string `json:"id_client" parquet:"name=id_client, type=BYTE_ARRAY, convertedtype=UTF8"`
+	Name              string `json:"name" parquet:"name=name, type=BYTE_ARRAY, convertedtype=UTF8"`
+	SourceApplication string `json:"source_application" parquet:"name=source_application, type=BYTE_ARRAY, convertedtype=UTF8"`
 }
 
 type EventSearchRequest struct {
-	From     int64  `json:"from" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
-	To       int64  `json:"to" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
-	IdClient string `json:"id_client" parquet:"name=id_client, type=BYTE_ARRAY, convertedtype=UTF8"`
+	From              int64  `json:"from" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
+	To                int64  `json:"to" parquet:"name=mtime, type=INT64, convertedtype=TIMESTAMP_MILLIS"`
+	IdClient          string `json:"id_client" parquet:"name=id_client, type=BYTE_ARRAY, convertedtype=UTF8"`
+	SourceApplication string `json:"source_application" parquet:"name=source_application, type=BYTE_ARRAY, convertedtype=UTF8"`
 }




diff --git a/server/rest/rest-event.go b/server/rest/rest-event.go
index 7cac661564009aefb5ec3aaf9bdec3380e5f54cb..36f767df7aaa87bc01e55aefa78e976869720a7d 100644
--- a/server/rest/rest-event.go
+++ b/server/rest/rest-event.go
@@ -43,6 +43,7 @@ 		}
 
 		clientCN := GetClientCN(c, cfg)
 		fmt.Printf("%s / %s ", clientCN, event.Name)
+
 		if event.Etime == 0 {
 			db.SaveEvent(clientCN, event.Name)
 		} else {
@@ -75,6 +76,13 @@ 		}
 
 		clientCN := GetClientCN(c, cfg)
 		fmt.Printf("Client ID: %s\n ", clientCN)
+
+		if event.SourceApplication != "" {
+			if !db.CanReadSourceEvent(clientCN, event.SourceApplication) {
+				c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "-1"})
+			}
+			clientCN = event.SourceApplication
+		}
 
 		var eventsPack []model.EventModel
 		if event.To == 0 {




diff --git a/server/rest/rest-metric.go b/server/rest/rest-metric.go
index 1d971744337b0abb0f5f16e0ef8e1864e471c1c2..deda405937fac497431c29b9e84b68c77635f149 100644
--- a/server/rest/rest-metric.go
+++ b/server/rest/rest-metric.go
@@ -78,6 +78,14 @@ 			return
 		}
 
 		clientCN := GetClientCN(c, cfg)
+
+		if metric.SourceApplication != "" {
+			if !db.CanReadSourceMetric(clientCN, metric.SourceApplication, metric.Name) {
+				c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "-1"})
+			}
+			clientCN = metric.SourceApplication
+		}
+
 		fmt.Printf("%s / %s ", clientCN, metric.Name)
 
 		var metricsPack []model.MetricModel