[KYUUBI #1000] Use underscore instead hyphen in path
<!--
Thanks for sending a pull request!
Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html
2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
-->
<!--
Please clarify why the changes are needed. For instance,
1. If you add a feature, you can talk about the use case of it.
2. If you fix a bug, you can clarify why it is a bug.
-->
Use underscore instead hyphen in path, friendly to sql.
- [X] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #1000 from hddong/fix-underscore.
Closes #1000
8b3459a5 [hongdongdong] Use underscore instead hyphen in path
Authored-by: hongdongdong <hongdongdong@cmss.chinamobile.com>
Signed-off-by: ulysses-you <ulyssesyou18@gmail.com>
(cherry picked from commit 94d60ea505)
Signed-off-by: ulysses-you <ulyssesyou18@gmail.com>
This commit is contained in:
parent
328d5b2d47
commit
92c2ebcbf3
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.kyuubi.events
|
||||||
|
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
trait KyuubiEvent extends Product {
|
||||||
|
final lazy val eventType: String = {
|
||||||
|
this.getClass.getSimpleName.stripSuffix("Event")
|
||||||
|
.replaceAll("(.)([A-Z])", "$1_$2")
|
||||||
|
.toLowerCase(Locale.ROOT)
|
||||||
|
}
|
||||||
|
|
||||||
|
def partitions: Seq[(String, String)]
|
||||||
|
|
||||||
|
final def toJson: String = JsonProtocol.productToJson(this)
|
||||||
|
}
|
||||||
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.kyuubi.events
|
||||||
|
|
||||||
|
import java.net.InetAddress
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
import org.apache.kyuubi.{Utils, WithKyuubiServer}
|
||||||
|
import org.apache.kyuubi.config.KyuubiConf
|
||||||
|
import org.apache.kyuubi.operation.JDBCTestUtils
|
||||||
|
import org.apache.kyuubi.operation.OperationState._
|
||||||
|
|
||||||
|
class EventLoggingServiceSuite extends WithKyuubiServer with JDBCTestUtils {
|
||||||
|
|
||||||
|
private val logRoot = Utils.createTempDir()
|
||||||
|
private val currentDate = Utils.getDateFromTimestamp(System.currentTimeMillis())
|
||||||
|
|
||||||
|
override protected val conf: KyuubiConf = {
|
||||||
|
KyuubiConf()
|
||||||
|
.set(KyuubiConf.SERVER_EVENT_LOGGERS, Seq("JSON"))
|
||||||
|
.set(KyuubiConf.SERVER_EVENT_JSON_LOG_PATH, logRoot.toString)
|
||||||
|
.set(KyuubiConf.ENGINE_EVENT_LOGGERS, Seq("JSON"))
|
||||||
|
.set(KyuubiConf.ENGINE_EVENT_JSON_LOG_PATH, logRoot.toString)
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected def jdbcUrl: String = getJdbcUrl
|
||||||
|
|
||||||
|
test("statementEvent: generate, dump and query") {
|
||||||
|
val hostName = InetAddress.getLocalHost.getCanonicalHostName
|
||||||
|
val serverStatementEventPath =
|
||||||
|
Paths.get(logRoot.toString, "kyuubi_statement", s"day=$currentDate", s"server-$hostName.json")
|
||||||
|
val engineStatementEventPath =
|
||||||
|
Paths.get(logRoot.toString, "spark_statement", s"day=$currentDate", "*.json")
|
||||||
|
val sql = "select timestamp'2021-06-01'"
|
||||||
|
|
||||||
|
withJdbcStatement() { statement =>
|
||||||
|
statement.execute(sql)
|
||||||
|
|
||||||
|
// check server statement events
|
||||||
|
val serverTable = serverStatementEventPath.getParent
|
||||||
|
val resultSet = statement.executeQuery(s"SELECT * FROM `json`.`${serverTable}`" +
|
||||||
|
"where statement = \"" + sql + "\"")
|
||||||
|
val states = Array(INITIALIZED, PENDING, RUNNING, FINISHED, CLOSED)
|
||||||
|
var stateIndex = 0
|
||||||
|
while (resultSet.next()) {
|
||||||
|
assert(resultSet.getString("user") == Utils.currentUser)
|
||||||
|
assert(resultSet.getString("statement") == sql)
|
||||||
|
assert(resultSet.getString("state") == states(stateIndex).toString)
|
||||||
|
stateIndex += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// check engine statement events
|
||||||
|
val engineTable = engineStatementEventPath.getParent
|
||||||
|
val resultSet2 = statement.executeQuery(s"SELECT * FROM `json`.`${engineTable}`" +
|
||||||
|
"where statement = \"" + sql + "\"")
|
||||||
|
val engineStates = Array(INITIALIZED, PENDING, RUNNING, COMPILED, FINISHED)
|
||||||
|
stateIndex = 0
|
||||||
|
while (resultSet2.next()) {
|
||||||
|
assert(resultSet2.getString("Event") ==
|
||||||
|
"org.apache.kyuubi.engine.spark.events.SparkStatementEvent")
|
||||||
|
assert(resultSet2.getString("statement") == sql)
|
||||||
|
assert(resultSet2.getString("state") == engineStates(stateIndex).toString)
|
||||||
|
stateIndex += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test("test Kyuubi session event") {
|
||||||
|
withSessionConf()(Map.empty)(Map(KyuubiConf.SESSION_NAME.key -> "test1")) {
|
||||||
|
withJdbcStatement() { statement =>
|
||||||
|
statement.execute("SELECT 1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val eventPath =
|
||||||
|
Paths.get(logRoot.toString, "kyuubi-session", s"day=$currentDate")
|
||||||
|
withSessionConf()(Map.empty)(Map("spark.sql.shuffle.partitions" -> "2")) {
|
||||||
|
withJdbcStatement() { statement =>
|
||||||
|
val res = statement.executeQuery(
|
||||||
|
s"SELECT * FROM `json`.`$eventPath` where sessionName = 'test1' order by totalOperations")
|
||||||
|
assert(res.next())
|
||||||
|
assert(res.getString("user") == Utils.currentUser)
|
||||||
|
assert(res.getString("sessionName") == "test1")
|
||||||
|
assert(res.getLong("startTime") > 0)
|
||||||
|
assert(res.getInt("totalOperations") == 0)
|
||||||
|
assert(res.next())
|
||||||
|
assert(res.getInt("totalOperations") == 1)
|
||||||
|
assert(res.getLong("endTime") > 0)
|
||||||
|
assert(!res.next())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user