Skip to content

Commit

Permalink
WIP #588 refactor how new analytics system works
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed Sep 28, 2020
1 parent 044e6be commit 287c182
Show file tree
Hide file tree
Showing 15 changed files with 536 additions and 299 deletions.
5 changes: 4 additions & 1 deletion otoroshi/app/cluster/cluster.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import redis.RedisClientMasterSlaves
import security.IdGenerator
import ssl._
import storage.drivers.inmemory.{Memory, SwappableInMemoryRedis}
import storage.stores.{KvRawDataStore, TeamDataStore, TenantDataStore}
import storage.stores.{DataExporterConfigDataStore, KvRawDataStore, TeamDataStore, TenantDataStore}
import utils.http.Implicits._
import otoroshi.utils.syntax.implicits._
import utils.http.MtlsConfig
Expand Down Expand Up @@ -1340,6 +1340,9 @@ class SwappableInMemoryDataStores(configuration: Configuration,
private lazy val _teamDataStore = new TeamDataStore(redis, env)
override def teamDataStore: TeamDataStore = _teamDataStore

private lazy val _dataExporterConfigDataStore = new DataExporterConfigDataStore(redis, env)
override def dataExporterConfigDataStore: DataExporterConfigDataStore = _dataExporterConfigDataStore

override def privateAppsUserDataStore: PrivateAppsUserDataStore = _privateAppsUserDataStore
override def backOfficeUserDataStore: BackOfficeUserDataStore = _backOfficeUserDataStore
override def serviceGroupDataStore: ServiceGroupDataStore = _serviceGroupDataStore
Expand Down
17 changes: 1 addition & 16 deletions otoroshi/app/controllers/adminapi/GlobalConfigController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controllers.adminapi
import actions.ApiAction
import akka.http.scaladsl.util.FastFuture
import env.Env
import events.{AddExporter, AdminApiEvent, Alerts, Audit, GlobalConfigModification, RemoveExporter}
import events.{AdminApiEvent, Alerts, Audit, GlobalConfigModification}
import models.GlobalConfig
import otoroshi.models.RightsChecker
import play.api.Logger
Expand Down Expand Up @@ -73,14 +73,6 @@ class GlobalConfigController(ApiAction: ApiAction, cc: ControllerComponents)(imp
)
ak.save()
.map(_ => {
//add or remove freshly created/removed dataExporter
val excl = conf.dataExporters.diff(ak.dataExporters) ++ ak.dataExporters.diff(conf.dataExporters)
if (excl.nonEmpty) {
conf.dataExporters.diff(ak.dataExporters)
.foreach(exporter => env.otoroshiEventsActor ! RemoveExporter(exporter))
ak.dataExporters.diff(conf.dataExporters)
.foreach(exporter => env.otoroshiEventsActor ! AddExporter(exporter))
}
Ok(Json.obj("done" -> true)) // TODO : rework
})
}
Expand Down Expand Up @@ -122,13 +114,6 @@ class GlobalConfigController(ApiAction: ApiAction, cc: ControllerComponents)(imp
)
ak.save()
.map(_ => {
//add or remove freshly created/removed dataExporter
if (!conf.dataExporters.forall(ak.dataExporters.contains(_))) {
conf.dataExporters.filterNot(ak.dataExporters.contains(_))
.foreach(exporter => env.otoroshiEventsActor ! RemoveExporter(exporter))
ak.dataExporters.filterNot(conf.dataExporters.contains(_))
.foreach(exporter => env.otoroshiEventsActor ! AddExporter(exporter))
}
Ok(Json.obj("done" -> true)) // TODO : rework
})
}
Expand Down
4 changes: 3 additions & 1 deletion otoroshi/app/env/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,9 @@ class Env(val configuration: Configuration,
}(otoroshiExecutionContext)

timeout(1000.millis).andThen {
case _ => jobManager.start()
case _ =>
jobManager.start()
otoroshiEventsActor! StartExporters()
}(otoroshiExecutionContext)

timeout(5000.millis).andThen {
Expand Down
Loading

0 comments on commit 287c182

Please sign in to comment.