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

grpc: factor out base classes for gRPC based drivers #276

Merged
merged 25 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5c1e96f
grpc: move metrics and credentials under common
alltilla Sep 3, 2024
f23a392
grpc: create DestDriver and DestWorker base classes
alltilla Sep 3, 2024
0ca9289
otel: derive DestDriver and DestWorker from grpc base classes
alltilla Sep 3, 2024
727e675
loki: derive DestinationDriver and DestinationWorker from grpc base c…
alltilla Sep 3, 2024
81fcc2c
bigquery: derive DestinationDriver and DestinationWorker from grpc ba…
alltilla Sep 3, 2024
be88488
bigquery: support auth()
alltilla Sep 5, 2024
a391b8f
loki: support batch_bytes() and add size related metrics
alltilla Sep 5, 2024
229b58b
loki: support compression()
alltilla Sep 5, 2024
5bd7a18
otel: support keep_alive() in destination
alltilla Sep 5, 2024
2378f51
grpc: create SourceDriver and SourceWorker base classes
alltilla Sep 6, 2024
146cae6
otel: derive SourceDriver and SourceWorker from grpc base classes
alltilla Sep 6, 2024
b498093
grpc: factor out common grpc keywords for parsers
alltilla Sep 5, 2024
8d3d9a9
merge-grammar: factor out locate_file()
alltilla Sep 5, 2024
50271e3
merge-grammar: factor out main()
alltilla Sep 5, 2024
e12bce7
merge-grammar: make including more general
alltilla Sep 5, 2024
420a53e
merge-grammar: collect blocks once
alltilla Sep 5, 2024
29974d9
merge-grammar: factor out print_preprocessed_grammar()
alltilla Sep 5, 2024
9e2629a
merge-grammar: support REQUIRE command
alltilla Sep 5, 2024
7c64172
grpc: create a common grammar file
alltilla Sep 3, 2024
32f79d5
otel: use grpc-grammar.ym
alltilla Sep 5, 2024
66b5895
loki: use grpc-grammar.ym
alltilla Sep 6, 2024
841df10
bigquery: use grpc-grammar.ym
alltilla Sep 6, 2024
32f50f8
grpc/otel: handle credentials creation error
alltilla Sep 16, 2024
295f02e
grpc: replace std::pair<x,y>{} with std::make_pair()
alltilla Sep 16, 2024
9413815
news: add entries for #276
alltilla Sep 17, 2024
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
79 changes: 55 additions & 24 deletions lib/merge-grammar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
#############################################################################
# Copyright (c) 2024 Axoflow
# Copyright (c) 2024 Attila Szakacs <[email protected]>
# Copyright (c) 2010-2017 Balabit
#
# This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -33,36 +35,65 @@
import sys
import codecs

grammar_file = os.path.join(os.environ.get('top_srcdir', ''), 'lib/cfg-grammar.y')
if not os.path.isfile(grammar_file):
grammar_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cfg-grammar.y')
if not os.path.isfile(grammar_file):
sys.exit('Error opening cfg-grammar.y')
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
COMMON_GRAMMAR_FILE = 'lib/cfg-grammar.y'
BLOCKS = {}


def locate_file(file_name):
full_path = os.path.join(os.environ.get('top_srcdir', ''), file_name)
if not os.path.isfile(full_path):
full_path = os.path.join(ROOT_DIR, file_name)
if not os.path.isfile(full_path):
sys.exit('Error opening ' + file_name)
return full_path


def print_to_stdout(line):
if sys.hexversion >= 0x3000000:
sys.stdout.buffer.write(line.encode("utf-8"))
else:
print(line.encode("utf-8"), end='')

def include_block(block_type):
start_marker = 'START_' + block_type
end_marker = 'END_' + block_type

with codecs.open(grammar_file, encoding="utf-8") as f:
in_block = False
def collect_block_definitions(file_name):
with codecs.open(locate_file(file_name), encoding="utf-8") as f:
block_name = None
block = []
for line in f:
if start_marker in line:
in_block = True
elif end_marker in line:
in_block = False
elif in_block:
print_to_stdout(line)

for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")):
if 'INCLUDE_DECLS' in line:
include_block('DECLS')
elif 'INCLUDE_RULES' in line:
include_block('RULES')
else:
print_to_stdout(line)
if line.startswith('/* START_') and line.endswith(' */\n'):
block_name = line[len('/* START_'):-len(' */\n')]
elif block_name and line == '/* END_' + block_name + ' */\n':
BLOCKS[block_name] = BLOCKS.get(block_name, '') + ''.join(block)
OverOrion marked this conversation as resolved.
Show resolved Hide resolved
block_name = None
block = []
elif block_name:
block.append(line)


def include_block(block_type):
try:
print_to_stdout(BLOCKS[block_type])
except KeyError:
sys.exit('Block not found: ' + block_type)


def print_preprocessed_grammar():
for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")):
if line.startswith('/* INCLUDE_') and line.endswith(' */\n'):
block_name = line[len('/* INCLUDE_'):-len(' */\n')]
include_block(block_name)
elif line.startswith('/* REQUIRE ') and line.endswith(' */\n'):
file_name = line[len('/* REQUIRE '):-len(' */\n')]
collect_block_definitions(file_name)
else:
print_to_stdout(line)


def main():
collect_block_definitions(COMMON_GRAMMAR_FILE)
print_preprocessed_grammar()


if __name__ == '__main__':
main()
3 changes: 1 addition & 2 deletions modules/grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ if (ENABLE_GRPC)
gRPC::grpc++
protobuf::libprotobuf)

add_subdirectory(credentials)
add_subdirectory(metrics)
add_subdirectory(common)
add_subdirectory(protos)
endif()

Expand Down
3 changes: 1 addition & 2 deletions modules/grpc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
include modules/grpc/protos/Makefile.am

include modules/grpc/credentials/Makefile.am
include modules/grpc/metrics/Makefile.am
include modules/grpc/common/Makefile.am

include modules/grpc/otel/Makefile.am
include modules/grpc/loki/Makefile.am
Expand Down
5 changes: 2 additions & 3 deletions modules/grpc/bigquery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(BIGQUERY_CPP_SOURCES
bigquery-dest.h
bigquery-worker.hpp
bigquery-worker.cpp
bigquery-worker.h
)

set(BIGQUERY_SOURCES
Expand All @@ -21,15 +20,15 @@ set(BIGQUERY_SOURCES
add_module(
TARGET bigquery-cpp
SOURCES ${BIGQUERY_CPP_SOURCES}
DEPENDS ${MODULE_GRPC_LIBS} grpc-protos
DEPENDS ${MODULE_GRPC_LIBS} grpc-protos grpc-common-cpp
INCLUDES ${BIGQUERY_PROTO_BUILDDIR} ${PROJECT_SOURCE_DIR}/modules/grpc
LIBRARY_TYPE STATIC
)

add_module(
TARGET bigquery
GRAMMAR bigquery-grammar
DEPENDS bigquery-cpp
DEPENDS bigquery-cpp grpc-common-cpp
INCLUDES ${PROJECT_SOURCE_DIR}/modules/grpc
SOURCES ${BIGQUERY_SOURCES}
)
Expand Down
6 changes: 4 additions & 2 deletions modules/grpc/bigquery/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ if ENABLE_GRPC
noinst_LTLIBRARIES += modules/grpc/bigquery/libbigquery_cpp.la

modules_grpc_bigquery_libbigquery_cpp_la_SOURCES = \
$(grpc_metrics_sources) \
modules/grpc/bigquery/bigquery-dest.h \
modules/grpc/bigquery/bigquery-dest.hpp \
modules/grpc/bigquery/bigquery-dest.cpp \
modules/grpc/bigquery/bigquery-worker.h \
modules/grpc/bigquery/bigquery-worker.hpp \
modules/grpc/bigquery/bigquery-worker.cpp

modules_grpc_bigquery_libbigquery_cpp_la_CXXFLAGS = \
$(AM_CXXFLAGS) \
$(PROTOBUF_CFLAGS) \
$(GRPCPP_CFLAGS) \
$(GRPC_COMMON_CFLAGS) \
-I$(GOOGLEAPIS_PROTO_BUILDDIR) \
-I$(top_srcdir)/modules/grpc \
-I$(top_srcdir)/modules/grpc/bigquery \
Expand All @@ -34,12 +33,14 @@ modules_grpc_bigquery_libbigquery_la_SOURCES = \

modules_grpc_bigquery_libbigquery_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(GRPC_COMMON_CFLAGS) \
-I$(top_srcdir)/modules/grpc/bigquery \
-I$(top_builddir)/modules/grpc/bigquery \
-I$(top_srcdir)/modules/grpc

modules_grpc_bigquery_libbigquery_la_LIBADD = \
$(MODULE_DEPS_LIBS) \
$(GRPC_COMMON_LIBS) \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la \
$(top_builddir)/modules/grpc/bigquery/libbigquery_cpp.la

Expand All @@ -48,6 +49,7 @@ nodist_EXTRA_modules_grpc_bigquery_libbigquery_la_SOURCES = force-cpp-linker-wit
modules_grpc_bigquery_libbigquery_la_LDFLAGS = $(MODULE_LDFLAGS)
EXTRA_modules_grpc_bigquery_libbigquery_la_DEPENDENCIES = \
$(MODULE_DEPS_LIBS) \
$(GRPC_COMMON_LIBS) \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la \
$(top_builddir)/modules/grpc/bigquery/libbigquery_cpp.la

Expand Down
Loading
Loading