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

example支持cls产品 #112

Merged
merged 2 commits into from Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added examples/cls/__init__.py
Empty file.
Empty file.
34 changes: 34 additions & 0 deletions examples/cls/v20201016/cls_kv.proto
@@ -0,0 +1,34 @@
syntax = "proto2";

package cls;

message Log
{
required int64 time = 1;
message Content
{
required string key = 1;
required string value = 2;
}
repeated Content contents= 2;
}

message LogTag
{
required string key = 1;
required string value = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些未对齐,看起来是空格和tab混排造成的,麻烦统一一下吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}

message LogGroup
{
repeated Log logs= 1;
optional string contextFlow= 2;
optional string filename = 3;
optional string source = 4;
repeated LogTag logTags = 5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样的

}

message LogGroupList
{
repeated LogGroup logGroupList = 1;
}
283 changes: 283 additions & 0 deletions examples/cls/v20201016/cls_kv_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions examples/cls/v20201016/createlogset.py
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createlogset.py =》 create_logset.py 或者 create_log_set.py ,我不太确定logset是否是cls的术语

import os

from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
# 导入对应产品模块的client models。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不必要的空行

from tencentcloud.cls.v20201016 import cls_client, models
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

分两行导入,不要两个模块逗号隔开

from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile

try:
# 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
cred = credential.Credential(
os.environ.get("TENCENTCLOUD_SECRET_ID"),
os.environ.get("TENCENTCLOUD_SECRET_KEY"))

# 实例化一个http选项,可选的,没有特殊需求可以跳过。
httpProfile = HttpProfile()
httpProfile.reqMethod = "POST" # post请求(默认为post请求)
httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)
httpProfile.endpoint = "cls.tencentcloudapi.com" # 指定接入地域域名(默认就近接入)
httpProfile.keepAlive = True

# 实例化一个client选项,可选的,没有特殊需求可以跳过。
clientProfile = ClientProfile()
clientProfile.signMethod = "TC3-HMAC-SHA256" # 指定签名算法(默认为HmacSHA256)
clientProfile.unsignedPayload = True
Copy link
Member

@zqfan zqfan Jul 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这并非公开的字段,而且这种控制类的请求并不建议打开,
整个配置示例字段其实并无十分的必要。下同

clientProfile.httpProfile = httpProfile

client = cls_client.ClsClient(cred, "ap-guangzhou", clientProfile)
req = models.CreateTopicRequest()
req.LogsetId = "xxx"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议格式符合真实值

req.TopicName = "xxx"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议取一个稍有意义的名字

resp = client.CreateTopic(req)

# 输出json格式的字符串回包
print("%s" % resp.to_json_string())

except TencentCloudSDKException as err:
print("%s" % err)