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

feat etcd: Init etcd client #837

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

eskedesu
Copy link


Note: by creating a PR or an issue you automatically agree to the CLA. See CONTRIBUTING.md. Feel free to remove this note, the agreement holds.

cmake/install/userver-etcd-config.cmake Show resolved Hide resolved
#include <userver/components/component_config.hpp>
#include <userver/components/component_context.hpp>
#include <userver/storages/etcd/client.hpp>

Copy link
Collaborator

Choose a reason for hiding this comment

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

во все публичные хедеры нужно добавить документацию
в заголовок файла
перед каждым классом
перед каждым методом


namespace storages::etcd {

class Client final {
Copy link
Collaborator

Choose a reason for hiding this comment

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

может лучше не final, а абстрактный класс? чтобы можно было замокать для тестирования клиента конфигов с использованием etcd


struct ClientSettings final {
std::vector<std::string> endpoints;
std::uint32_t retries;
Copy link
Collaborator

Choose a reason for hiding this comment

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

attempts

}

std::string BuildPutData(const std::string& key, const std::string& value) {
formats::json::StringBuilder sb;
Copy link
Collaborator

Choose a reason for hiding this comment

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

тут скорость не так важна
можно и просто из inline.hpp взять MakeObject("key", x, "value", y)

minimum: 1
request_timeout_ms:
type: integer
description: Number of miliseconds to timeout request
Copy link
Collaborator

Choose a reason for hiding this comment

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

between request attempts

Client(clients::http::Client& http_client, ClientSettings settings);
void Put(const std::string& key, const std::string& value);
[[nodiscard]] std::vector<std::string> Range(const std::string& key);
void DeleteRange(const std::string& key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

для клиента конфигов нам нужны:

  1. получение значения по ключу
  2. получение всех значений (это range&)
  3. вотч на все значения
    возможно не все, а только те, что начинаются с определенного префикса

Client(clients::http::Client& http_client, ClientSettings settings);
void Put(const std::string& key, const std::string& value);
[[nodiscard]] std::vector<std::string> Range(const std::string& key);
void DeleteRange(const std::string& key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

для клиента конфигов очень хочется иметь юнит-тест

Client(clients::http::Client& http_client, ClientSettings settings);
void Put(const std::string& key, const std::string& value);
[[nodiscard]] std::vector<std::string> Range(const std::string& key);
void DeleteRange(const std::string& key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

для клиента конфигов очень хочется иметь testsuite-тест, который получает значения конфига из мока

return sb.GetString();
}

bool ShouldRetry(std::shared_ptr<clients::http::Response> response) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

тут что-то должно быть? для того, чтобы фолбечиться на другой бекенд при отказе одно

@@ -0,0 +1,63 @@
#pragma once
Copy link
Collaborator

Choose a reason for hiding this comment

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

без storages/


USERVER_NAMESPACE_BEGIN

namespace storages::etcd {
Copy link
Collaborator

Choose a reason for hiding this comment

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

без storages


class Component final : public components::ComponentBase {
public:
static constexpr std::string_view kName = "etcd";
Copy link
Collaborator

Choose a reason for hiding this comment

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

etcd-client


Component(const components::ComponentConfig&, const components::ComponentContext&);

~Component() = default;
Copy link
Collaborator

Choose a reason for hiding this comment

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

не нужно


namespace storages::etcd {

struct KVEvent final {
Copy link
Collaborator

Choose a reason for hiding this comment

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

KeyValueEvent, не нужно сокращать такие короткие имена

"watch task",
[stream_response = std::move(stream_response), produser = queue->GetProducer()] mutable {
std::string body_part;
const auto deadline = engine::Deadline::FromDuration(std::chrono::seconds{100'000'000});
Copy link
Collaborator

Choose a reason for hiding this comment

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

можно просто не указывать дедлайн

const auto watch_response = formats::json::FromString(body_part);
LOG_ERROR() << watch_response;
if (!watch_response["result"].HasMember("events")) {
LOG_INFO() << "No events in watch part response, skipping";
Copy link
Collaborator

Choose a reason for hiding this comment

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

дебаг

}
const auto key = crypto::base64::Base64Decode(event["kv"]["key"].As<std::string>());
const auto value = crypto::base64::Base64Decode(event["kv"]["value"].As<std::string>());
const auto version = std::stoi(event["kv"]["version"].As<std::string>());
Copy link
Collaborator

Choose a reason for hiding this comment

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

парсинг евента нужно точно через chaotic делать

.CreateRequest()
.post(url_builder(endpoint), data)
.retry(settings_.retries)
.timeout(1'000'000'000)
Copy link
Collaborator

Choose a reason for hiding this comment

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

в статический конфиг

#pragma once

#include <chrono>
#include <cstdint>
Copy link
Collaborator

Choose a reason for hiding this comment

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

давай сразу клиента конфига сделаешь до полноценного watch event'а - так будет проще понять, какой API требуется и что еще необходимо сделать

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants