-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is not a complete solution but has the base form for how the project is laid out and has an example showing how it can be used in a project. To test with telegraf you'll need to use the changes in this PR: influxdata/telegraf#6024
- Loading branch information
Timidger
committed
Jun 20, 2019
1 parent
d23c530
commit 97061ed
Showing
11 changed files
with
706 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
[submodule "example/telegraf-plugin-go-glue"] | ||
path = example/telegraf-plugin-go-glue | ||
url = https://github.com/StarryInternet/telegraf-plugin-go-glue | ||
[submodule "telegraf-plugin-go-glue"] | ||
path = telegraf-plugin-go-glue | ||
url = https://github.com/StarryInternet/telegraf-plugin-go-glue |
This file contains 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,20 @@ | ||
# line length | ||
error_on_line_overflow = true | ||
max_width = 100 | ||
|
||
# comments | ||
comment_width = 100 | ||
wrap_comments = false # rustfmt is broken currently and doesn't softwrap | ||
normalize_comments = true | ||
|
||
# commas | ||
trailing_comma = "Never" | ||
match_block_trailing_comma = true | ||
|
||
# code | ||
use_try_shorthand = true | ||
binop_separator = "Back" | ||
format_strings = false # rustfmt string handling is horribly busted | ||
|
||
# imports | ||
reorder_imports = true |
This file contains 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,19 @@ | ||
[package] | ||
name = "telegraf-plugin" | ||
version = "0.1.0" | ||
authors = ["Timidger <pcarpenter@starry.com>"] | ||
edition = "2018" | ||
build = "build.rs" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[build-dependencies] | ||
bindgen = "0.49.*" | ||
|
||
[dependencies] | ||
chrono = "0.4" | ||
libc = "0.2" | ||
syn = { version = "0.15", features = ["full", "fold"] } | ||
quote = "0.6" | ||
proc-macro2 = "0.4" |
This file contains 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,15 @@ | ||
// Copyright 2019. Starry, Inc. All Rights Reserved. | ||
fn main() { | ||
let builder = bindgen::builder() | ||
.derive_debug(true) | ||
.derive_default(true) | ||
.derive_copy(true) | ||
.generate_comments(true) | ||
.blacklist_function("sample_config") | ||
.blacklist_function("description") | ||
.blacklist_function("gather") | ||
.header("telegraf-plugin-go-glue/c_api.h") | ||
.ctypes_prefix("libc"); | ||
let generated = builder.generate().unwrap(); | ||
generated.write_to_file("src/gen.rs").unwrap(); | ||
} |
This file contains 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,12 @@ | ||
[package] | ||
name = "telegraf-plugin-example" | ||
version = "0.1.0" | ||
authors = ["Timidger <pcarpenter@starry.com>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate_type = ["staticlib"] | ||
|
||
[dependencies] | ||
libc = "0.2" | ||
telegraf-plugin = { path = "../" } |
This file contains 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,41 @@ | ||
[tasks.rust_build] | ||
command = "cargo" | ||
args = ["build"] | ||
|
||
[tasks.copy_go_files] | ||
script = [ | ||
''' | ||
cp target/debug/libtelegraf_plugin_example.a ./plugin.a | ||
cp telegraf-plugin-go-glue/lib.go ./ | ||
cp telegraf-plugin-go-glue/c_api.h ./ | ||
''' | ||
] | ||
|
||
[tasks.go_build] | ||
command = "go" | ||
args = ["build", "-buildmode=plugin", "-o=plugin.so"] | ||
dependencies = ["rust_build", "copy_go_files"] | ||
|
||
[tasks.cleanup] | ||
script = [ | ||
''' | ||
rm plugin.a | ||
rm lib.go | ||
rm c_api.h | ||
if [ -f plugin.so ]; then | ||
chmod a+x plugin.so | ||
fi | ||
''' | ||
] | ||
|
||
# This must run after the Rust build, | ||
# so that it can link the Rust artifact to it. | ||
[tasks.build] | ||
dependencies = [ | ||
"rust_build", | ||
"go_build", | ||
"cleanup" | ||
] | ||
|
||
[config] | ||
on_error_task = "cleanup" |
This file contains 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,25 @@ | ||
// Copyright 2019. Starry, Inc. All Rights Reserved. | ||
use telegraf_plugin::link_to_go; | ||
|
||
macro_rules! map( | ||
{ $($key:expr => $value:expr),* } => { | ||
{ | ||
#[allow(unused_mut)] | ||
let mut m = ::std::collections::HashMap::new(); | ||
$( | ||
m.insert($key, $value); | ||
)* | ||
m | ||
} | ||
}; | ||
); | ||
|
||
#[link_to_go("Description of the plugin", "<sample_config>")] | ||
fn collect_metric() { | ||
AddField( | ||
"rust-metric".into(), | ||
map! {"rust_key".into() => "rust_value".into()}, | ||
map! {"rust_field".into() => 100000000.into()}, | ||
None | ||
) | ||
} |
This file contains 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 @@ | ||
../telegraf-plugin-go-glue/ |
Oops, something went wrong.