Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/common/formatter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ envoy_cc_library(
"//source/common/config:utility_lib",
"//source/common/protobuf",
"//source/server:generic_factory_context_lib",
"@abseil-cpp//absl/status:statusor",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)
Expand Down
4 changes: 3 additions & 1 deletion source/common/formatter/substitution_format_string.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "source/common/formatter/substitution_format_string.h"

#include "absl/status/statusor.h"

namespace Envoy {
namespace Formatter {

Expand Down Expand Up @@ -51,7 +53,7 @@ absl::StatusOr<FormatterPtr> SubstitutionFormatStringUtils::fromProtoConfig(
return nullptr;
}

FormatterPtr
absl::StatusOr<FormatterPtr>
SubstitutionFormatStringUtils::createJsonFormatter(const Protobuf::Struct& struct_format,
bool omit_empty_values,
const std::vector<CommandParserPtr>& commands) {
Expand Down
8 changes: 5 additions & 3 deletions source/common/formatter/substitution_format_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "source/common/runtime/runtime_features.h"
#include "source/server/generic_factory_context.h"

#include "absl/status/statusor.h"

namespace Envoy {
namespace Formatter {

Expand Down Expand Up @@ -44,9 +46,9 @@ class SubstitutionFormatStringUtils {
/**
* Generate a Json formatter object from proto::Struct config
*/
static FormatterPtr createJsonFormatter(const Protobuf::Struct& struct_format,
bool omit_empty_values,
const std::vector<CommandParserPtr>& commands = {});
static absl::StatusOr<FormatterPtr>
createJsonFormatter(const Protobuf::Struct& struct_format, bool omit_empty_values,
const std::vector<CommandParserPtr>& commands = {});
};

} // namespace Formatter
Expand Down
5 changes: 3 additions & 2 deletions source/extensions/access_loggers/file/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ AccessLog::InstanceSharedPtr FileAccessLogFactory::createAccessLogInstance(
}
break;
case envoy::extensions::access_loggers::file::v3::FileAccessLog::AccessLogFormatCase::kJsonFormat:
formatter = Formatter::SubstitutionFormatStringUtils::createJsonFormatter(
fal_config.json_format(), false, command_parsers);
formatter = THROW_OR_RETURN_VALUE(Formatter::SubstitutionFormatStringUtils::createJsonFormatter(
fal_config.json_format(), false, command_parsers),
Formatter::FormatterPtr);
break;
case envoy::extensions::access_loggers::file::v3::FileAccessLog::AccessLogFormatCase::
kTypedJsonFormat: {
Expand Down
5 changes: 3 additions & 2 deletions source/extensions/access_loggers/fluentd/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ AccessLog::InstanceSharedPtr FluentdAccessLogFactory::createAccessLogInstance(
std::vector<Formatter::CommandParserPtr>);

Formatter::FormatterPtr json_formatter =
Formatter::SubstitutionFormatStringUtils::createJsonFormatter(proto_config.record(), false,
commands);
THROW_OR_RETURN_VALUE(Formatter::SubstitutionFormatStringUtils::createJsonFormatter(
proto_config.record(), false, commands),
Formatter::FormatterPtr);
FluentdFormatterPtr fluentd_formatter =
std::make_unique<FluentdFormatterImpl>(std::move(json_formatter));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST(FluentdFormatterImplTest, FormatMsgpack) {
(*log_struct.mutable_fields())["LogType"].set_string_value("%ACCESS_LOG_TYPE%");

auto json_formatter =
Formatter::SubstitutionFormatStringUtils::createJsonFormatter(log_struct, false);
Formatter::SubstitutionFormatStringUtils::createJsonFormatter(log_struct, false).value();

auto fluentd_formatter = FluentdFormatterImpl(std::move(json_formatter));
auto expected_json = "{\"Message\":\"SomeValue\",\"LogType\":\"NotSet\"}";
Expand Down
Loading