如何理解apacheimpala的zlib压缩查询概要文件

7ivaypg9  于 2021-05-31  发布在  Hadoop
关注(0)|答案(2)|浏览(415)

impala当前将查询配置文件日志保存在/var/log/impala/profiles,每行的格式为

<Epoch-Timestamp> <QueryID> <zlib-compressed-data>

正如他们在https://impala.apache.org/docs/build/html/topics/impala_logging.html
为了节省空间,这些查询配置文件现在存储在/var/log/impala/profiles中的zlib压缩文件中
我想用一些实用程序来解码/解压zlib压缩数据,而不是用25000公开的webui。
从日志和文档中,我可以看出zlib压缩数据是使用base64编码的。我可以写一个python代码来解压zlib压缩,

import base64
import datetime
import zlib

profile_data = "1587093056765 c94ef1f2e35015a2:feb1867165d545a7 eJyVVE1P1EAYLkhkXRBcI7ANMRlvkMhm+rXd3ehh2S1xI4LS5eNgYqadtzChtMt0yoe/gHg1MR78Df4AD540MSYevHry6MEf4NEpFVwImJgmk74znfd5n+d536r3ynefpMAP0Qyj9/26CYEW6GBYWLOI3gjA02pVW6ta1DItYs9ODKl3y6VORHzB9qAbCxJ22Q5MFCcVpXztbDw5UJpW1MK0PBl2050dwg8nlP+7Xjoaa8VRBL4AilYT4EM8jsVIK445ZRERMVd3U+ZvJ4JwUfHDOKXASUPXMcaFdnsRdQ97MNpacZpd51m3Ob/oFNsQkDQUqO2NwEEPuISLRDLWhhA2yQmMUnAiirJSbutYx3PYnNNshI2GhhtWtWJXzVrNkBhjnZ0eCQlaA56wOFpnxyFFe3mM9IpVwXM+3bIqdgWjFWfRaboOmvFSFlJEqBFYhBIPaGBVA6h6tA5AjLpm2j6u2r5vWbqNjdnxJRD7Md9GTUo5JMm4pst08tEahqFZ+nRu4XJPSNAEzUQSmuY8Z5WR/NAVkl1hobPUcR847dG/m2kyuPywmMeZXFekbkVXomQEOu07dcvEZl2npmlbdc8LGnUc4JqODewR3dAIjJ58nN0ennccd725cd3dDXPMTN8pn4N8RYJ4oVw1NHOAWCRmi25m3OVCm5ptWpmZQ6fmq79KfdWdwe7LdupfH7F+Ic7wP+fiMda5vjvXH+cN6euqs8T7W/VfLp0263Q2IYp6VS0o5bE/tUsaIYtAXVN+vvy++vrNx0+Db799+Zwv6sZ4ThsOwE+z1KXHIYkiFm2igEUs2QJ6YwV2U0jE6UZpgXEZ8ngfBSD87JPViMMmSwRwtJvByoEczXVxgct+lqP7tHyzReSIxpvLPUeiZYVxOasfvr77MaCUb7VCJikvZAnXCRMnx6/eHw0ql0791Eq8/0iqxRkJ2XOSETi5ePkvZeCFUruglgsruAxAUX4DOJOTpw=="

pdata = profile_data.split(" ")

ts = datetime.datetime.fromtimestamp(int(pdata[0]) / 1000.0).isoformat()
queryID = pdata[1]

encodedData = base64.b64decode(pdata[2])
zlib_data = zlib.decompress(encodedData)

print(zlib_data)

上面的python实用程序提供了以下输出,其中包含一些有意义的信息,但并不完整。

b'\x19<\x18,Query (id=c94ef1f2e35015a2:feb1867165d545a7)\x15\x04\x19,\x18\x11InactiveTotalTime\x15\n\x16\x00\x00\x18\tTotalTime\x15\n\x16\x00\x00\x16\x01\x11\x1b\x00\x19\x08\x1b\x00\x00\x18\x07Summary\x15\x00\x19,\x18\x11InactiveTotalTime\x15\n\x16\x00\x00\x18\tTotalTime\x15\n\x16\x00\x00\x16\x01\x11\x1b\x11\x88\x0eConnected User\x04root\x0bCoordinator\x19quickstart.cloudera:22000\x08DDL Type\x0cCREATE_TABLE\nDefault Db\x0bexperiments\x0eDelegated User\x00\x08End Time\x1d2020-04-17 03:10:56.764883000\x0eImpala VersionWimpalad version 2.5.0-cdh5.7.0 RELEASE (build ad3f5adabedf56fe6bd9eea39147c067cc552703)\x0fNetwork Address\x0f127.0.0.1:33152\x1bQuery Options (non default)\x00\x0bQuery State\x08FINISHED\x0cQuery Status\x02OK\nQuery Type\x03DDL\nSession ID!9540492d44759bbf:90f082030ba231ae\x0cSession Type\x07BEESWAX\rSql Statement\x17create table t1 (x int)\nStart Time\x1d2020-04-17 03:10:56.417452000\x04User\x04root\x19\xf8\x11\nSession ID\x0cSession Type\nStart Time\x08End Time\nQuery Type\x0bQuery State\x0cQuery Status\x0eImpala Version\x04User\x0eConnected User\x0eDelegated User\x0fNetwork Address\nDefault Db\rSql Statement\x0bCoordinator\x1bQuery Options (non default)\x08DDL Type\x1b\x00\x19,\x18\x00\x19\x06\x19\x08\x00\x18\x0eQuery Timeline\x19V\x00\xec\x93\xe0U\x98\x9c\xc5\xc8\x02\xae\xda\xcd\xca\x02\xae\xda\xcd\xca\x02\x19X\x0fStart execution\x11Planning finished\x10Request finished\x11First row fetched\x10Unregister query\x00\x00\x18\x0cImpalaServer\x15\x00\x19\\\x18\x12CatalogOpExecTimer\x15\n\x16\xc4\xd1\xba\xe8\x01\x00\x18\x14ClientFetchWaitTimer\x15\n\x16\x96\xbe\x88\x02\x00\x18\x11InactiveTotalTime\x15\n\x16\x00\x00\x18\x17RowMaterializationTimer\x15\n\x16\x00\x00\x18\tTotalTime\x15\n\x16\x00\x00\x16\x01\x11\x1b\x00\x19\x08\x1b\x01\x8a\x008\x12CatalogOpExecTimer\x14ClientFetchWaitTimer\x17RowMaterializationTimer\x00\x00'

任何以编程方式理解/解析impala概要文件日志的指针都非常有用。

ryhaxcpt

ryhaxcpt1#

升级。编辑成包含源代码和一些注解。
我猜这就是你要找的剧本(摘自《 Impala Git》)

import base64
    import datetime
    import zlib
    from thrift.protocol import TCompactProtocol
    from thrift.TSerialization import deserialize
    from RuntimeProfile.ttypes import TRuntimeProfileTree

    def decode_profile_line(line):
      space_separated = line.split(" ")
      if len(space_separated) == 3:
        ts = int(space_separated[0])
        print datetime.datetime.fromtimestamp(ts / 1000.0).isoformat(), space_separated[1]
        base64_encoded = space_separated[2]
      elif len(space_separated) == 1:
        base64_encoded = space_separated[0]
      else:
        raise Exception("Unexpected line: " + line)
      possibly_compressed = base64.b64decode(base64_encoded)
      # Handle both compressed and uncompressed Thrift profiles
      try:
        thrift = zlib.decompress(possibly_compressed)
      except zlib.error:
        thrift = possibly_compressed

      tree = TRuntimeProfileTree()
      deserialize(tree, thrift, protocol_factory=TCompactProtocol.TCompactProtocolFactory())
      tree.validate()

    return tree

    encoded_line = "timestamp queryid encoded_profile_string"
    decoded_tree = decode_profile_line(encoded_line)

基本上,它的功能与代码片段中的相同,但它也会在之后破译特定于节俭的编码。”thrift”代表apache thrift本身的库(更多信息请参见apache thrift文档和git),runtimeprofile是impala的结构定义(您可以在impala git中查看),其中包含节点和脚本执行摘要:

// A flattened tree of runtime profiles, obtained by an
    // pre-order traversal
    struct TRuntimeProfileTree {
      1: required list<TRuntimeProfileNode> nodes
      2: optional ExecStats.TExecSummary exec_summary
    }

让我们仔细看看thrift中的“反序列化”方法:

def deserialize(base,
            buf,
            protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
      transport = TTransport.TMemoryBuffer(buf)
      protocol = protocol_factory.getProtocol(transport)
      base.read(protocol)
      return base

“base”表示将返回给您的树及其所有节点和子节点。因此,从现在开始有两种选择:
浏览 Impala 代码;似乎所有必要的定义都存储在git的这个子文件夹中;有可能复制他们的逻辑。
从“protocol\u factory.getprotocol(transport)”中编写定制的“反序列化”和调试输出,以定义“基”树(同样:在impala源代码中查找必要的节点可能更容易一些)。

to94eoyn

to94eoyn2#

这可能会帮助其他人遇到这个问题。apache impala存储库中有一个解析运行时配置文件日志的示例脚本,这是一个开始构建自己工具的好地方-https://github.com/apache/impala/blob/master/bin/parse-thrift-profile.py. 它被绑定到impala开发环境中——特别是它需要编译节俭定义并从中生成python,这需要一个工作的开发环境。在撰写本文时,您可以通过查看 Impala 并设置部分环境来实现这一点:

git clone https://github.com/apache/impala.git
cd impala
. bin/impala-config.sh
./bin/bootstrap_toolchain.py
./buildall.sh -cmake_only -noclean
make thrift-deps
./bin/parse-thrift-profile.py ./impala_profile_log_1.1-1594189561854

相关问题