moduleGitlabmoduleMetrics# Class for producing SQL queries with sensitive data stripped out.classObfuscatedSQLREPLACEMENT=/ \d+(\.\d+)? # integers, floats | '.+?' # single quoted strings | \/.+?(?<!\\)\/ # regexps (including escaped slashes) /xMYSQL_REPLACEMENTS=/ ".+?" # double quoted strings /x# Regex to replace consecutive placeholders with a single one indicating# the length. This can be useful when a "IN" statement uses thousands of# IDs (storing this would just be a waste of space).CONSECUTIVE=/(\?(\s*,\s*)?){2,}/# sql - The raw SQL query as a String.definitialize(sql)@sql=sqlend# Returns a new, obfuscated SQL query.defto_sregex=REPLACEMENTifGitlab::Database.mysql?regex=Regexp.union(regex,MYSQL_REPLACEMENTS)end@sql.gsub(regex,'?').gsub(CONSECUTIVE)do|match|"#{match.count(',')+1} values"endendendendend