Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log before regex matching #8169

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .circleci/not-on-master.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/usr/bin/env bash
set -Eeuo pipefail

if [ "${CIRCLE_BRANCH}" == "master" ]; then
echo "Skipping this step on master..."
else
exec "$@"
fi
echo "Skipping this step on master..."
1 change: 1 addition & 0 deletions app/controllers/WkorgProxyController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class WkorgProxyController @Inject()(ws: WSClient,

private def matchesPageWithWildcard(routeWithWildcard: String, actualRequest: String): Boolean = {
val wildcardRegex = "^" + Regex.quote(routeWithWildcard).replace("*", "\\E.*\\Q") + "$"
logger.info(f"[debug-regex]: matching $actualRequest against regex $wildcardRegex")
actualRequest.matches(wildcardRegex)
}

Expand Down
7 changes: 5 additions & 2 deletions app/mail/MailchimpTag.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package mail

import com.scalableminds.util.enumeration.ExtendedEnumeration
import com.typesafe.scalalogging.LazyLogging

object MailchimpTag extends ExtendedEnumeration {
object MailchimpTag extends ExtendedEnumeration with LazyLogging {
type MailchimpTag = Value

val RegisteredAsUser, RegisteredAsAdmin, HasAnnotated, HasInvitedTeam, HasUploadedOwnDataset,
HasViewedPublishedDataset, WasActiveInWeeksTwoOrThree, WasInactiveInWeeksTwoAndThree = Value

def format(tag: MailchimpTag): String =
def format(tag: MailchimpTag): String = {
logger.info(f"[debug-regex]: matching $tag to lower-case mailchimp tag")
"[A-Z]".r
.replaceAllIn(tag.toString, { m =>
"_" + m.group(0).toLowerCase()
})
.drop(1)
}

override def fromString(s: String): Option[mail.MailchimpTag.Value] =
super.fromString(underscoreToCamel(s))
Expand Down
3 changes: 3 additions & 0 deletions app/models/annotation/nml/NmlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ object NmlParser extends LazyLogging with ProtoGeometryImplicits with ColorGener
val regex = "^stringListValue-(\\d+)".r
val valuesWithIndex: Seq[(Int, String)] = node.attributes.flatMap {
case attribute: Attribute =>
logger.info(f"[debug-regex]: matching ${attribute.key} for as string list value in NML")
attribute.key match {
case regex(indexStr) =>
indexStr.toIntOpt.map { index =>
Expand Down Expand Up @@ -551,8 +552,10 @@ object NmlParser extends LazyLogging with ProtoGeometryImplicits with ColorGener

private def parseAdditionalCoordinateValues(node: XMLNode): Seq[AdditionalCoordinateProto] = {
val regex = "^additionalCoordinate-(\\w)".r

node.attributes.flatMap {
case attribute: Attribute =>
logger.info(f"[debug-regex]: matching ${attribute.key} for as additionalCoordinateValue in NML")
attribute.key match {
case regex(axisName) =>
Some(new AdditionalCoordinateProto(axisName, attribute.value.toString().toInt))
Expand Down
5 changes: 4 additions & 1 deletion app/opengraph/OpenGraphService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.scalableminds.util.accesscontext.DBAccessContext
import com.scalableminds.util.enumeration.ExtendedEnumeration
import com.scalableminds.util.tools.Fox
import com.scalableminds.webknossos.datastore.models.datasource.{Category, DataLayerLike}
import com.typesafe.scalalogging.LazyLogging
import models.annotation.AnnotationDAO
import models.dataset.{Dataset, DatasetDAO, DatasetLayerDAO}
import models.organization.{Organization, OrganizationDAO}
Expand All @@ -32,7 +33,8 @@ class OpenGraphService @Inject()(datasetDAO: DatasetDAO,
datasetLayerDAO: DatasetLayerDAO,
annotationDAO: AnnotationDAO,
shortLinkDAO: ShortLinkDAO,
conf: WkConf) {
conf: WkConf)
extends LazyLogging {

private val thumbnailWidth = 1000
private val thumbnailHeight = 300
Expand All @@ -59,6 +61,7 @@ class OpenGraphService @Inject()(datasetDAO: DatasetDAO,
implicit ec: ExecutionContext,
ctx: DBAccessContext): Fox[OpenGraphTags] =
for {
_ <- Fox.successful(logger.info(f"[debug-regex]: matching $uriPath for openGraph tags"))
(uriPathResolved, sharingTokenResolved) <- resolveShortLinkIfNeeded(uriPath, sharingToken)
ctxWithToken = URLSharing.fallbackTokenAccessContext(sharingTokenResolved)
pageType = detectPageType(uriPathResolved)
Expand Down
5 changes: 4 additions & 1 deletion app/utils/sql/SqlEscaping.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils.sql

trait SqlEscaping {
import com.typesafe.scalalogging.LazyLogging

trait SqlEscaping extends LazyLogging {
protected def escapeLiteral(aString: String): String = {
// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
var hasBackslash = false
Expand Down Expand Up @@ -35,6 +37,7 @@ trait SqlEscaping {
// Removing the escaped quotes to split at commas not surrounded by quotes
// Splitting *the original string* at split positions obtained from matching there
val withoutEscapedQuotes = trimmed.replace("\\\"", "__")
logger.info(f"[debug-regex]: matching $withoutEscapedQuotes as arrayLiteral from SQL")
val splitPositions: List[Int] =
",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)".r.findAllMatchIn(withoutEscapedQuotes).map(_.start).toList.sorted
val split = splitAtPositions(splitPositions, trimmed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.scalableminds.util.geometry

import com.scalableminds.util.tools.Math.ceilDiv
import com.typesafe.scalalogging.LazyLogging
import net.liftweb.common.Full
import play.api.libs.json.{JsObject, Json}

Expand Down Expand Up @@ -76,7 +77,7 @@ case class BoundingBox(topLeft: Vec3Int, width: Int, height: Int, depth: Int) {
Json.obj("topLeft" -> topLeft, "width" -> width, "height" -> height, "depth" -> depth)
}

object BoundingBox {
object BoundingBox extends LazyLogging {

import play.api.libs.json._

Expand All @@ -86,7 +87,8 @@ object BoundingBox {
def empty: BoundingBox =
BoundingBox(Vec3Int.zeros, 0, 0, 0)

def fromLiteral(s: String): Option[BoundingBox] =
def fromLiteral(s: String): Option[BoundingBox] = {
logger.info(f"[debug-regex]: matching $s as boundingbox")
s match {
case literalPattern(minX, minY, minZ, width, height, depth) =>
try {
Expand All @@ -103,6 +105,7 @@ object BoundingBox {
case _ =>
None
}
}

def fromSQL(ints: List[Int]): Option[BoundingBox] =
if (ints.length == 6)
Expand Down
23 changes: 14 additions & 9 deletions util/src/main/scala/com/scalableminds/util/geometry/Vec3Int.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.scalableminds.util.geometry

import com.scalableminds.util.tools.ExtendedTypes.ExtendedString
import com.typesafe.scalalogging.LazyLogging
import play.api.libs.json.Json._
import play.api.libs.json._

Expand Down Expand Up @@ -80,14 +81,15 @@ case class Vec3Int(x: Int, y: Int, z: Int) {
def hasNegativeComponent: Boolean = x < 0 || y < 0 || z < 0
}

object Vec3Int {
object Vec3Int extends LazyLogging {
private val magLiteralRegex = """(\d+)-(\d+)-(\d+)""".r
private val uriLiteralRegex = """(\d+),(\d+),(\d+)""".r

def fromMagLiteral(s: String, allowScalar: Boolean = false): Option[Vec3Int] =
s.toIntOpt match {
case Some(scalar) if allowScalar => Some(Vec3Int.full(scalar))
case _ =>
logger.info(f"[debug-regex]: matching $s as mag literal in Vec3Int")
s match {
case magLiteralRegex(x, y, z) =>
try {
Expand All @@ -100,14 +102,17 @@ object Vec3Int {
}
}

def fromUriLiteral(s: String): Option[Vec3Int] = s match {
case uriLiteralRegex(x, y, z) =>
try {
Some(Vec3Int(Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z)))
} catch {
case _: NumberFormatException => None
}
case _ => None
def fromUriLiteral(s: String): Option[Vec3Int] = {
logger.info(f"[debug-regex]: matching $s as mag Vec3Int uri literal")
s match {
case uriLiteralRegex(x, y, z) =>
try {
Some(Vec3Int(Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z)))
} catch {
case _: NumberFormatException => None
}
case _ => None
}
}

def fromList(l: List[Int]): Option[Vec3Int] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.scalableminds.webknossos.datastore.dataformats.wkw
import com.scalableminds.util.geometry.Vec3Int
import com.scalableminds.webknossos.datastore.models.datasource.DataLayer
import com.scalableminds.webknossos.datastore.models.BucketPosition
import com.typesafe.scalalogging.LazyLogging

trait WKWDataFormatHelper {
trait WKWDataFormatHelper extends LazyLogging {

val dataFileExtension: String = "wkw"
val FILENAME_HEADER_WKW: String = s"header.$dataFileExtension"
Expand All @@ -19,6 +20,7 @@ trait WKWDataFormatHelper {
// Assumes single-bucket wkw files, as for volume tracings
protected def parseWKWFilePath(path: String): Option[BucketPosition] = {
val CubeRx = s"(|.*/)(\\d+|\\d+-\\d+-\\d+)/z(\\d+)/y(\\d+)/x(\\d+).$dataFileExtension".r
logger.info(f"[debug-regex]: matching $path as WKWFilePath")
path match {
case CubeRx(_, magStr, z, y, x) =>
Vec3Int.fromMagLiteral(magStr, allowScalar = true).map { mag =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.scalableminds.webknossos.datastore.datareaders.zarr3
import com.scalableminds.util.enumeration.ExtendedEnumeration
import com.scalableminds.webknossos.datastore.datareaders.{ArrayDataType, zarr3}
import com.scalableminds.webknossos.datastore.datareaders.ArrayDataType.ArrayDataType
import com.typesafe.scalalogging.LazyLogging

object Zarr3DataType extends ExtendedEnumeration {
object Zarr3DataType extends ExtendedEnumeration with LazyLogging {
type Zarr3DataType = Value
val bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, complex64, complex128,
raw, extension = Value
Expand All @@ -14,12 +15,13 @@ object Zarr3DataType extends ExtendedEnumeration {
override def fromString(s: String): Option[zarr3.Zarr3DataType.Value] = {

val rawPattern = "(r\\d+)".r
super
.fromString(s)
.orElse(s match {
super.fromString(s).orElse {
logger.info(f"[debug-regex]: matching $s as Zarr3DataType")
s match {
case rawPattern(_) => Some(Zarr3DataType.raw)
case _ => None
})
}
}
}

def toArrayDataType(dataType: Zarr3DataType): ArrayDataType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ object CumsumParser extends LazyLogging {
reader.nextLong()
}
reader.endObject()
list.sorted.map { case formRx(x, y, z, w, h, d) => (x.toLong, y.toLong, z.toLong, w.toLong, h.toLong, d.toLong) }.toList
list.sorted.map { item =>
logger.info(f"[debug-regex]: matching $item as cumsum-json BoundingBox")
item match { case formRx(x, y, z, w, h, d) => (x.toLong, y.toLong, z.toLong, w.toLong, h.toLong, d.toLong) }
}.toList
}

private def parseCumSum(reader: JsonReader,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.scalableminds.webknossos.tracingstore.tracings.skeleton

import com.scalableminds.webknossos.datastore.SkeletonTracing.Tree
import com.typesafe.scalalogging.LazyLogging

import scala.util.matching.Regex
import scala.util.matching.Regex.Match

object TreeUtils {
object TreeUtils extends LazyLogging {
type FunctionalNodeMapping = Function[Int, Int]
type FunctionalGroupMapping = Function[Int, Int]

Expand Down Expand Up @@ -63,6 +64,7 @@ object TreeUtils {
val newId = if (sourceNodeIds.contains(oldId)) f(oldId) else oldId
"#" + newId
}
logger.info(f"[debug-regex]: matching $comment as node reference in skeleton tree comment")
nodeIdReferenceRegex.replaceAllIn(comment, m => replacer(m))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ trait VolumeDataZipHelper
// assume additionalAxes,x,y,z
val chunkPathRegex = s"(|.*/)(\\d+|\\d+-\\d+-\\d+)/c\\.(.+)".r

logger.info(f"[debug-regex]: matching $path as zarr chunk path")
path match {
case chunkPathRegex(_, magStr, dimsStr) =>
val dims: Seq[String] = dimsStr.split("\\.").toSeq
Expand Down Expand Up @@ -144,6 +145,7 @@ trait VolumeDataZipHelper
private def getMagFromWkwOrZarrHeaderFilePath(path: String): Option[Vec3Int] = {
val wkwHeaderRx = s"(|.*/)(\\d+|\\d+-\\d+-\\d+)/$FILENAME_HEADER_WKW".r
val zarr3HeaderRx = s"(|.*/)(\\d+-\\d+-\\d+)/${Zarr3ArrayHeader.FILENAME_ZARR_JSON}".r
logger.info(f"[debug-regex]: matching $path as wkwHeaderPath or zarr3HeaderPath")
path match {
case wkwHeaderRx(_, magLiteral) =>
Vec3Int.fromMagLiteral(magLiteral, allowScalar = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ trait BucketKeys extends MortonEncoding with WKWDataFormatHelper with LazyLoggin

private def parseBucketKeyXYZ(key: String) = {
val keyRx = "([0-9a-z-]+)/(\\d+|\\d+-\\d+-\\d+)/-?\\d+-\\[(\\d+),(\\d+),(\\d+)]".r
logger.info(f"[debug-regex]: matching $key as volume tracing bucket key")
key match {
case keyRx(name, magStr, xStr, yStr, zStr) =>
getBucketPosition(xStr, yStr, zStr, magStr, None).map(bucketPosition => (name, bucketPosition))
Expand All @@ -118,6 +119,7 @@ trait BucketKeys extends MortonEncoding with WKWDataFormatHelper with LazyLoggin
additionalAxes: Seq[AdditionalAxis]): Option[(String, BucketPosition)] = {
val additionalCoordinateCapture = Array.fill(additionalAxes.length)("(\\d+)").mkString(",")
val keyRx = s"([0-9a-z-]+)/(\\d+|\\d+-\\d+-\\d+)/-?\\d+-\\[$additionalCoordinateCapture]\\[(\\d+),(\\d+),(\\d+)]".r
logger.info(f"[debug-regex]: matching $key as ND volume tracing bucket key")
val matchOpt = keyRx.findFirstMatchIn(key)
matchOpt match {
case Some(aMatch) =>
Expand Down