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

Provide infrastructure to migrate legacy analyzers to Spicy inside the Zeek tree. #2651

Merged
merged 3 commits into from
Feb 1, 2023

Conversation

rsmmr
Copy link
Member

@rsmmr rsmmr commented Dec 14, 2022

As initial examples, this branch ports the Syslog and Finger analyzers
over. We leave the old analyzers in place for now and activate them
iff we compile without any Spicy.

Needs zeek-spicy-infra branches in zeek/spicy#1333, zeek/spicy-plugin#155, zeek/cmake#57, and https://github.com/zeek/zeek-testing-private/pull/11.

@rsmmr rsmmr changed the title Provide infrastructure to migrate legacy analyzers to Spicy. Provide infrastructure to migrate legacy analyzers to Spicy inside the Zeek tree. Dec 14, 2022
@rsmmr rsmmr force-pushed the topic/robin/zeek-spicy-infra branch 4 times, most recently from a5e8e2f to be93d57 Compare December 15, 2022 11:41
@awelzel
Copy link
Contributor

awelzel commented Jan 6, 2023

Hey - I've tried to build branch locally and am running into an issue:

[error] /home/awelzel/corelight-oss/zeek/src/analyzer/protocol/finger/finger.spicy:42:22-46:2: call does not match any function: spicy_rt::initializeParsedUnit(<value_ref<spicy_rt::ParsedUnit>>, <value_ref<Finger::Reply>>, <const __library_type("::hilti::rt::TypeInfo const*")>)

This seems like it should be something local, but I did the recursive submodule update and otherwise usual build.l

set -x
PREFIX=${PREFIX:-/opt/zeek-dev}

export CFLAGS="-ggdb -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"
export CXXFLAGS="-ggdb -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"
export LDFLAGS="-fuse-ld=lld"

./configure \
    --ccache \
    --generator=Ninja \
    --build-dir=./build \
    --prefix=$PREFIX \
    --enable-debug \
    --build-type=debug \
    --disable-zkg \
    --disable-btest \
    --disable-python \
    --disable-zeekctl \
    --disable-zeek-client \
    --disable-broker-tests \
    --enable-static-binpac  \
    --enable-static-broker \
    --binary-package \
    --sanitizers=address \
    --enable-fuzzers \
    $*

@awelzel
Copy link
Contributor

awelzel commented Jan 6, 2023

This seems like it should be something local, but I did the recursive submodule update and otherwise usual build.

Okay: I've had an existing installation in /opt/zeek-dev and appears that spicyz picks the installed version of spicy_rt.hlt over the one that can be found through the provided -L <...>/zeek/auxil/spicy/spicy/spicy/lib from the source tree.

That seems slightly surprising (when compared to -I from cc which will preceed system directories) and likely sub-optimal for the builtin case here. After removing /opt/zeek-dev locally the error from above is gone.

@rsmmr
Copy link
Member Author

rsmmr commented Jan 9, 2023

That seems slightly surprising (when compared to -I from cc which will preceed system directories) and likely sub-optimal for the builtin case here. After removing /opt/zeek-dev locally the error from above is gone.

Ack, I'll look into that.

@rsmmr
Copy link
Member Author

rsmmr commented Jan 25, 2023

This is ready, but I'll start the merge process with the subprojects and will file a few individual PRs there to get their pieces in place first. Once that's all in, I'll turn the main Zeek PR to ready for review.

@rsmmr rsmmr force-pushed the topic/robin/zeek-spicy-infra branch 3 times, most recently from a58509c to 4b3f93c Compare January 30, 2023 10:02
@rsmmr rsmmr marked this pull request as ready for review January 30, 2023 10:03
@rsmmr
Copy link
Member Author

rsmmr commented Jan 30, 2023

This is ready for review.

@rsmmr rsmmr requested a review from bbannier January 30, 2023 10:03
@bbannier
Copy link
Contributor

bbannier commented Jan 30, 2023

Before going into the details I wanted to check whether it supports all the use cases we wanted (not all tested in CI). We need to be able to build against an externally installed Spicy (shared or static) and/or against a different version of the plugin, configured with --with-spicy and --with-spicy-plugin. It looks like this is currently broken already when only using one of external Spicy/spicy-plugin, even at configure time.

The migration of the Finger analyzer looks okay to me, but CI for that currently hinges on us never making the different sanitizer CI jobs use Spicy (they are currently --disable-spicy). Maybe we need a dedicated CI for testing legacy analyzers in a job explicitly without Spicy (maybe as a nightly job @awelzel started putting infra in?).

@awelzel
Copy link
Contributor

awelzel commented Jan 30, 2023

and/or against a different version of the plugin, configured with --with-spicy and --with-spicy-plugin. It looks like this is currently broken already when only using one of external Spicy/spicy-plugin, even at configure time.

Mostly FWIW: I could see us removing --with-spicy-plugin and ask developers for manual bumping/pointing the submodule instead. For AF_Packet we do not have a similar option and I'd like to avoid the proliferation.

The --with-spicy should continue to work, it's such a time-saver when doing one-off container builds that one can just install Spicy's binary packages directly.

Maybe we need a dedicated CI for testing legacy analyzers in a job explicitly without Spicy (maybe as a nightly job @awelzel started putting infra in?).

I don't think there's actual infra, but I might be missing a bit what you're referring to.

@rsmmr
Copy link
Member Author

rsmmr commented Jan 30, 2023

Arne:

Mostly FWIW: I could see us removing --with-spicy-plugin

Agree with that.

The --with-spicy should continue to work, it's such a time-saver when doing one-off container builds that one can just install Spicy's binary packages directly.

Actually, I'd prefer for that to go, too. We have such a proliferation of Zeek/Spicy/Plugin versions and ways to install them, it's hard to keep that all working in all combinations. In particular, having one extern but the other not, feels like we could skip.

We do have --disable-spicy, and that's actually the only one I use. When I don't want the internal Spicy, I use that and then install Spicy (source or binary) and the plugin separately. Would that work for you (and your container builds), too?

Maybe we need a dedicated CI for testing legacy analyzers in a job explicitly without Spicy (maybe as a nightly job @awelzel started putting infra in?).

I don't think there's actual infra, but I might be missing a bit what you're referring to.

@rsmmr
Copy link
Member Author

rsmmr commented Jan 30, 2023

Benjamin:

The migration of the Finger analyzer looks okay to me, but CI for that currently hinges on us never making the different sanitizer CI jobs use Spicy (they are currently --disable-spicy). Maybe we need a dedicated CI for testing legacy analyzers in a job explicitly without Spicy (maybe as a nightly job @awelzel started putting infra in?).

Yep, I noticed that too: looks like we should have a dedicated (non-sanitizer) CI run with --disable-spicy.

@awelzel
Copy link
Contributor

awelzel commented Jan 30, 2023

We do have --disable-spicy, and that's actually the only one I use. When I don't want the internal Spicy, I use that and then install Spicy (source or binary) and the plugin separately. Would that work for you (and your container builds), too?

Hmm, cringing a bit, but if it pains you too much I'll adapt or use more ccache magic.

Other thought is that bundling dependencies isn't great for distributions (some packaging guidelines suggest to submit upstream patches to allow for external dependencies), but we're probably far from that and Zeek/Spicy are rather closely coupled so that whatever a distribution ships may not actually work with the latest Zeek version anyway (or analyzers).

As of spicy-plugin: There's another thought to go even further: In the scenario that one passes --disable-spicy and builds everything externally, do we provide a way to leverage Spicy analyzers maintained within Zeek's source tree? If not (or if that would just complicate things), I could also see us merging the plugin completely for Zeek 6.0 with the sentiment that in-tree Spicy analyzers can only be leveraged with the builtin spicy plugin. If we want to support in-tree analyzers with an external plugin, that's a different story, but might be a scenario to avoid.

Sorry for all the text, I'll try to look, run this tomorrow 🤞

@timwoj
Copy link
Contributor

timwoj commented Jan 30, 2023

I gave it a cursory glance and it all looks ok to me. My only question is whether we have a plan to deprecate/eventually remove the "legacy" version of the analyzer. Given that we're always building with spicy by default, how long should we expect the old version to live on?

Along those same lines, should there be some sort of warning during configure if there are in-tree spicy plugins, but you've disabled spicy?

@rsmmr
Copy link
Member Author

rsmmr commented Jan 31, 2023

Ok, let's do this: For now, I'll try to get the options back to working so that we don't need to make this call right now; I think I see what broken them. But longer term, we probably still want to think about what combinations we want to keep supporting.

@rsmmr
Copy link
Member Author

rsmmr commented Jan 31, 2023

My only question is whether we have a plan to deprecate/eventually remove the "legacy" version of the analyzer. Given that we're always building with spicy by default, how long should we expect the old version to live on?

Something to talk about, but my take is that at some point we should stop supporting running without Spicy at all (i.e., remove —disable-spicy), and then it becomes an individual per-analyzer decision as we port them over. Then we either immediately remove legacy analyzers once we have Spicy version, or we allow each a grace period of, say, one major release where we keep a knob to turn them back on.

Along those same lines, should there be some sort of warning during configure if there are in-tree spicy plugins, but you've disabled spicy?

Sure, I'll add something.

@rsmmr
Copy link
Member Author

rsmmr commented Jan 31, 2023

Updated this with (1) supporting external Spicy/plugin versions again (tested in all combinations on macOS), and (2) add warnings about legacy/missing analyzers without Spicy.

Copy link
Contributor

@bbannier bbannier left a comment

Choose a reason for hiding this comment

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

From the Spicy and CMake side this looks okay to me, only left trivial issues.

CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
testing/scripts/diff-remove-spicy-abspath Outdated Show resolved Hide resolved
@bbannier bbannier linked an issue Jan 31, 2023 that may be closed by this pull request
scripts/base/protocols/finger/spicy-events.zeek Outdated Show resolved Hide resolved
scripts/base/protocols/finger/spicy-events.zeek Outdated Show resolved Hide resolved
scripts/base/protocols/syslog/spicy-events.zeek Outdated Show resolved Hide resolved
src/analyzer/protocol/finger/finger.spicy Outdated Show resolved Hide resolved
testing/scripts/have-spicy Outdated Show resolved Hide resolved
testing/btest/coverage/default-load-baseline.test Outdated Show resolved Hide resolved
@timwoj
Copy link
Contributor

timwoj commented Jan 31, 2023

Something to talk about, but my take is that at some point we should stop supporting running without Spicy at all (i.e., remove —disable-spicy), and then it becomes an individual per-analyzer decision as we port them over. Then we either immediately remove legacy analyzers once we have Spicy version, or we allow each a grace period of, say, one major release where we keep a knob to turn them back on.

I'd agree with removing --disable-spicy, if we can figure out how to make the builds work on lower-memory machines. For example, my NUC with 8GB of RAM cannot complete a build unless I turn off spicy. The build eventually hangs, and then the compiler crashes due to being OOM.

@rsmmr
Copy link
Member Author

rsmmr commented Feb 1, 2023

For example, my NUC with 8GB of RAM cannot complete a build unless I turn off spicy. The build eventually hangs, and then the compiler crashes due to being OOM.

Is that even with -j1?

@rsmmr rsmmr force-pushed the topic/robin/zeek-spicy-infra branch from 0ab0ac0 to e20cef6 Compare February 1, 2023 07:30
@awelzel awelzel linked an issue Feb 1, 2023 that may be closed by this pull request
@rsmmr rsmmr force-pushed the topic/robin/zeek-spicy-infra branch from e20cef6 to d9d3518 Compare February 1, 2023 10:32
As initial examples, this branch ports the Syslog and Finger analyzers
over. We leave the old analyzers in place for now and activate them
iff we compile without any Spicy.

Needs `zeek-spicy-infra` branches in `spicy/`, `spicy-plugin/`,
`CMake/`, and `zeek/zeek-testing-private`.

Note that the analyzer events remain associated with the Spicy plugin
for now: that's where they will show up with `-NN`, and also inside
the Zeekygen documentation.

We switch CMake over to linking the runtime library into the plugin,
vs. at the top-level through object libraries.
This should work now. It affects only the toolchain libraries
`libhilti`/`libspicy`. the runtime libraries `libhilti-rt` and
`libspicy-rt` are always built static (but they are small). Zeek
itself doesn't link against the toolchain anymore now anyways, but a
number of the Spicy tools do.

Note, we have an issue with Broker I believe: it looks like it always
overrides BUILD_SHARED_LIBS to `OFF`

Addresses #2675.
@rsmmr rsmmr force-pushed the topic/robin/zeek-spicy-infra branch from d9d3518 to 2512fd1 Compare February 1, 2023 10:39
@rsmmr rsmmr merged commit a2dfd39 into master Feb 1, 2023
@rsmmr rsmmr deleted the topic/robin/zeek-spicy-infra branch February 1, 2023 11:01
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.

libspicy and libhilti should build as shared objects Huge container image sizes (compare 4.x vs 5.x)
4 participants