Skip to content

Commit

Permalink
Try to fix weird behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Nov 8, 2019
1 parent 73126c5 commit c575d39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
5 changes: 3 additions & 2 deletions otoroshi/app/gateway/handlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ class GatewayRequestHandler(snowMonkey: SnowMonkey,

ServiceLocation(req.host, globalConfig) match {
case None =>
Errors.craftResponseResult(s"Service not found", NotFound, req, None, Some("errors.service.not.found"))
Errors.craftResponseResult(s"Service not found: invalid host", NotFound, req, None, Some("errors.service.not.found.invalid.host"))
case Some(ServiceLocation(domain, serviceEnv, subdomain)) => {
val uriParts = req.relativeUri.split("/").toSeq

Expand All @@ -818,8 +818,9 @@ class GatewayRequestHandler(snowMonkey: SnowMonkey,
.craftResponseResult(s"Service not found", NotFound, req, None, Some("errors.service.not.found"))
case Some(desc) if !desc.enabled =>
Errors
.craftResponseResult(s"Service not found", NotFound, req, None, Some("errors.service.not.found"))
.craftResponseResult(s"Service unavailable", ServiceUnavailable, req, None, Some("errors.service.unavailable"))
case Some(rawDesc) if rawDesc.redirection.enabled && rawDesc.redirection.hasValidCode => {
// TODO: event here
FastFuture.successful(
Results
.Status(rawDesc.redirection.code)
Expand Down
37 changes: 29 additions & 8 deletions otoroshi/app/models/descriptor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ case class ServiceDescriptorQuery(subdomain: String,
}

def addServices(services: Seq[ServiceDescriptor])(implicit ec: ExecutionContext, env: Env): Future[Boolean] = {
val key = this.asKey
existsCache.put(key, true)
serviceIdsCache.put(key, services.map(_.id))
servicesCache.put(key, services)
env.datastores.serviceDescriptorDataStore.addFastLookups(this, services)
if (services.isEmpty) {
FastFuture.successful(true)
} else {
val key = this.asKey
existsCache.put(key, true)
serviceIdsCache.put(key, services.map(_.id))
servicesCache.put(key, services)
env.datastores.serviceDescriptorDataStore.addFastLookups(this, services)
}
}

def remServices(services: Seq[ServiceDescriptor])(implicit ec: ExecutionContext, env: Env): Future[Boolean] = {
Expand Down Expand Up @@ -2697,7 +2701,24 @@ trait ServiceDescriptorDataStore extends BasicStore[ServiceDescriptor] {
query
.getServices(false)
.fast
.flatMap(services => sortServices(services, query, requestHeader))
.flatMap {
case services if services.isEmpty => {
// fast lookup should not store empty results, so ...
ServiceDescriptorDataStore.logger.warn(s"FastLookup false positive for ${query.toHost}, doing a fullscan instead ...")
findAll().flatMap { descriptors =>
val validDescriptors = descriptors.filter { sr =>
if (!sr.enabled) {
false
} else {
utils.RegexPool(sr.toHost).matches(query.toHost)
}
}
query.addServices(validDescriptors)
sortServices(validDescriptors, query, requestHeader)
}
}
case services => sortServices(services, query, requestHeader)
}
}
case false => {
ServiceDescriptorDataStore.logger.debug("Full scan of services, should not pass here anymore ...")
Expand All @@ -2715,10 +2736,10 @@ trait ServiceDescriptorDataStore extends BasicStore[ServiceDescriptor] {
}
} map { filteredDescriptors =>
filteredDescriptors.headOption
} andThen {
}/* andThen {
case _ =>
ServiceDescriptorDataStore.logger.debug(s"Found microservice in ${System.currentTimeMillis() - start} ms.")
}
}*/
}
}

Expand Down

0 comments on commit c575d39

Please sign in to comment.