-
Notifications
You must be signed in to change notification settings - Fork 500
[CONFIGURATION] File configuration - yaml parser #3519
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
25ffa24
[CONFIGURATION] File configuration - yaml parser
marcalff b7d7484
Merge branch 'main' into merge_config_yaml_parser
marcalff ca68022
Merge branch 'main' into merge_config_yaml_parser
marcalff 5927a67
Refresh code from PR #2518, to fix review comments.
marcalff 3f99d32
Refresh code from PR #2518, to fix review comments.
marcalff 7aad664
Merge branch 'main' into merge_config_yaml_parser
marcalff 8aa248f
Refresh code from PR #2518, to fix review comments.
marcalff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
sdk/include/opentelemetry/sdk/configuration/configuration_parser.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "opentelemetry/sdk/configuration/configuration.h" | ||
#include "opentelemetry/sdk/configuration/document_node.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace configuration | ||
{ | ||
|
||
class ConfigurationParser | ||
{ | ||
public: | ||
static std::unique_ptr<Configuration> Parse(std::unique_ptr<Document> doc); | ||
}; | ||
|
||
} // namespace configuration | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "opentelemetry/sdk/configuration/document_node.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace configuration | ||
{ | ||
|
||
class Document | ||
{ | ||
public: | ||
Document() = default; | ||
Document(Document &&) = default; | ||
Document(const Document &) = default; | ||
Document &operator=(Document &&) = default; | ||
Document &operator=(const Document &other) = default; | ||
virtual ~Document() = default; | ||
|
||
virtual std::unique_ptr<DocumentNode> GetRootNode() = 0; | ||
}; | ||
|
||
} // namespace configuration | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
177 changes: 177 additions & 0 deletions
177
sdk/include/opentelemetry/sdk/configuration/document_node.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace configuration | ||
{ | ||
|
||
class DocumentNodeConstIterator; | ||
class PropertiesNodeConstIterator; | ||
|
||
class DocumentNode | ||
{ | ||
public: | ||
// FIXME: proper sizing | ||
static constexpr std::size_t MAX_NODE_DEPTH = 100; | ||
|
||
DocumentNode() = default; | ||
DocumentNode(DocumentNode &&) = default; | ||
DocumentNode(const DocumentNode &) = default; | ||
DocumentNode &operator=(DocumentNode &&) = default; | ||
DocumentNode &operator=(const DocumentNode &other) = default; | ||
virtual ~DocumentNode() = default; | ||
|
||
virtual std::string Key() const = 0; | ||
|
||
virtual bool AsBoolean() const = 0; | ||
virtual std::size_t AsInteger() const = 0; | ||
virtual double AsDouble() const = 0; | ||
virtual std::string AsString() const = 0; | ||
|
||
virtual std::unique_ptr<DocumentNode> GetRequiredChildNode(const std::string &name) const = 0; | ||
virtual std::unique_ptr<DocumentNode> GetChildNode(const std::string &name) const = 0; | ||
|
||
virtual bool GetRequiredBoolean(const std::string &name) const = 0; | ||
virtual bool GetBoolean(const std::string &name, bool default_value) const = 0; | ||
|
||
virtual std::size_t GetRequiredInteger(const std::string &name) const = 0; | ||
virtual std::size_t GetInteger(const std::string &name, std::size_t default_value) const = 0; | ||
|
||
virtual double GetRequiredDouble(const std::string &name) const = 0; | ||
virtual double GetDouble(const std::string &name, double default_value) const = 0; | ||
|
||
virtual std::string GetRequiredString(const std::string &name) const = 0; | ||
virtual std::string GetString(const std::string &name, | ||
const std::string &default_value) const = 0; | ||
|
||
virtual DocumentNodeConstIterator begin() const = 0; | ||
virtual DocumentNodeConstIterator end() const = 0; | ||
|
||
virtual std::size_t num_children() const = 0; | ||
virtual std::unique_ptr<DocumentNode> GetChild(std::size_t index) const = 0; | ||
|
||
virtual PropertiesNodeConstIterator begin_properties() const = 0; | ||
virtual PropertiesNodeConstIterator end_properties() const = 0; | ||
|
||
protected: | ||
std::string DoSubstitution(const std::string &text) const; | ||
std::string DoOneSubstitution(const std::string &text) const; | ||
|
||
bool BooleanFromString(const std::string &value) const; | ||
std::size_t IntegerFromString(const std::string &value) const; | ||
double DoubleFromString(const std::string &value) const; | ||
}; | ||
|
||
class DocumentNodeConstIteratorImpl | ||
{ | ||
public: | ||
DocumentNodeConstIteratorImpl() = default; | ||
DocumentNodeConstIteratorImpl(DocumentNodeConstIteratorImpl &&) = default; | ||
DocumentNodeConstIteratorImpl(const DocumentNodeConstIteratorImpl &) = default; | ||
DocumentNodeConstIteratorImpl &operator=(DocumentNodeConstIteratorImpl &&) = default; | ||
DocumentNodeConstIteratorImpl &operator=(const DocumentNodeConstIteratorImpl &other) = default; | ||
virtual ~DocumentNodeConstIteratorImpl() = default; | ||
|
||
virtual void Next() = 0; | ||
virtual std::unique_ptr<DocumentNode> Item() const = 0; | ||
virtual bool Equal(const DocumentNodeConstIteratorImpl *rhs) const = 0; | ||
}; | ||
|
||
class PropertiesNodeConstIteratorImpl | ||
{ | ||
public: | ||
PropertiesNodeConstIteratorImpl() = default; | ||
PropertiesNodeConstIteratorImpl(PropertiesNodeConstIteratorImpl &&) = default; | ||
PropertiesNodeConstIteratorImpl(const PropertiesNodeConstIteratorImpl &) = default; | ||
PropertiesNodeConstIteratorImpl &operator=(PropertiesNodeConstIteratorImpl &&) = default; | ||
PropertiesNodeConstIteratorImpl &operator=(const PropertiesNodeConstIteratorImpl &other) = | ||
default; | ||
virtual ~PropertiesNodeConstIteratorImpl() = default; | ||
|
||
virtual void Next() = 0; | ||
virtual std::string Name() const = 0; | ||
virtual std::unique_ptr<DocumentNode> Value() const = 0; | ||
virtual bool Equal(const PropertiesNodeConstIteratorImpl *rhs) const = 0; | ||
}; | ||
|
||
class DocumentNodeConstIterator | ||
{ | ||
public: | ||
DocumentNodeConstIterator(std::unique_ptr<DocumentNodeConstIteratorImpl> impl) | ||
: impl_(std::move(impl)) | ||
{} | ||
DocumentNodeConstIterator(DocumentNodeConstIterator &&) = default; | ||
DocumentNodeConstIterator(const DocumentNodeConstIterator &) = delete; | ||
DocumentNodeConstIterator &operator=(DocumentNodeConstIterator &&) = default; | ||
DocumentNodeConstIterator &operator=(const DocumentNodeConstIterator &other) = delete; | ||
~DocumentNodeConstIterator() = default; | ||
|
||
bool operator==(const DocumentNodeConstIterator &rhs) const | ||
{ | ||
return (impl_->Equal(rhs.impl_.get())); | ||
} | ||
|
||
bool operator!=(const DocumentNodeConstIterator &rhs) const | ||
{ | ||
return (!impl_->Equal(rhs.impl_.get())); | ||
} | ||
|
||
std::unique_ptr<DocumentNode> operator*() const { return impl_->Item(); } | ||
|
||
DocumentNodeConstIterator &operator++() | ||
{ | ||
impl_->Next(); | ||
return *this; | ||
} | ||
|
||
private: | ||
std::unique_ptr<DocumentNodeConstIteratorImpl> impl_; | ||
}; | ||
|
||
class PropertiesNodeConstIterator | ||
{ | ||
public: | ||
PropertiesNodeConstIterator(std::unique_ptr<PropertiesNodeConstIteratorImpl> impl) | ||
: impl_(std::move(impl)) | ||
{} | ||
PropertiesNodeConstIterator(PropertiesNodeConstIterator &&) = default; | ||
PropertiesNodeConstIterator(const PropertiesNodeConstIterator &) = delete; | ||
PropertiesNodeConstIterator &operator=(PropertiesNodeConstIterator &&) = default; | ||
PropertiesNodeConstIterator &operator=(const PropertiesNodeConstIterator &other) = delete; | ||
~PropertiesNodeConstIterator() = default; | ||
|
||
bool operator==(const PropertiesNodeConstIterator &rhs) const | ||
{ | ||
return (impl_->Equal(rhs.impl_.get())); | ||
} | ||
|
||
bool operator!=(const PropertiesNodeConstIterator &rhs) const | ||
{ | ||
return (!impl_->Equal(rhs.impl_.get())); | ||
} | ||
|
||
std::string Name() const { return impl_->Name(); } | ||
std::unique_ptr<DocumentNode> Value() const { return impl_->Value(); } | ||
|
||
PropertiesNodeConstIterator &operator++() | ||
{ | ||
impl_->Next(); | ||
return *this; | ||
} | ||
|
||
private: | ||
std::unique_ptr<PropertiesNodeConstIteratorImpl> impl_; | ||
}; | ||
|
||
} // namespace configuration | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
27 changes: 27 additions & 0 deletions
27
sdk/include/opentelemetry/sdk/configuration/invalid_schema_exception.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <stdexcept> | ||
#include <string> | ||
|
||
#include "opentelemetry/sdk/configuration/document.h" | ||
#include "opentelemetry/sdk/configuration/document_node.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace configuration | ||
{ | ||
|
||
class InvalidSchemaException : public std::runtime_error | ||
{ | ||
public: | ||
InvalidSchemaException(const std::string &msg) : std::runtime_error(msg) {} | ||
}; | ||
|
||
} // namespace configuration | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
40 changes: 40 additions & 0 deletions
40
sdk/include/opentelemetry/sdk/configuration/ryml_document.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <ryml.hpp> | ||
#include <string> | ||
|
||
#include "opentelemetry/sdk/configuration/document.h" | ||
#include "opentelemetry/sdk/configuration/document_node.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace configuration | ||
{ | ||
|
||
class RymlDocument : public Document | ||
{ | ||
public: | ||
static std::unique_ptr<Document> Parse(const std::string &source, const std::string &content); | ||
|
||
RymlDocument(ryml::Tree tree) : tree_(std::move(tree)) {} | ||
RymlDocument(RymlDocument &&) = delete; | ||
RymlDocument(const RymlDocument &) = delete; | ||
RymlDocument &operator=(RymlDocument &&) = delete; | ||
RymlDocument &operator=(const RymlDocument &other) = delete; | ||
~RymlDocument() override = default; | ||
|
||
std::unique_ptr<DocumentNode> GetRootNode() override; | ||
|
||
private: | ||
ryml::Tree tree_; | ||
}; | ||
|
||
} // namespace configuration | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.