-
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.
feat: add opentelemetry-collector service
feat: add opentelemetry-collector service feat: add opentelemetry-collector service feat: add opentelemetry-collector service
- Loading branch information
Showing
12 changed files
with
297 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,35 @@ | ||
name: ci | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- opentelemetry-collector/** | ||
- .github/workflows/opentelemetry-collector.yml | ||
jobs: | ||
opentelemetry-collector-test: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup Fluent CI | ||
uses: fluentci-io/setup-fluentci@v5 | ||
with: | ||
wasm: true | ||
plugin: rust | ||
args: | | ||
target_add wasm32-unknown-unknown | ||
build --release --target wasm32-unknown-unknown | ||
working-directory: opentelemetry-collector | ||
env: | ||
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Start opentelemetry-collector Server | ||
run: | | ||
fluentci run target/wasm32-unknown-unknown/release/opentelemetry_collector.wasm start | ||
fluentci run target/wasm32-unknown-unknown/release/opentelemetry_collector.wasm stop | ||
working-directory: opentelemetry-collector | ||
env: | ||
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NIX_CONFIG: extra-access-tokens = github.com=${{ secrets.GH_ACCESS_TOKEN }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 @@ | ||
[package] | ||
authors = [ | ||
"Tsiry Sandratraina <tsiry.sndr@fluentci.io>", | ||
] | ||
description = "Opentelemetry Collector plugin for FluentCI" | ||
edition = "2021" | ||
license = "MIT" | ||
name = "opentelemetry-collector" | ||
version = "0.1.0" | ||
|
||
[lib] | ||
crate-type = [ | ||
"cdylib", | ||
] | ||
|
||
[dependencies] | ||
anyhow = "1.0.82" | ||
extism-pdk = "1.1.0" | ||
fluentci-pdk = "0.2.1" | ||
fluentci-types = "0.1.7" |
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 @@ | ||
Copyright (c) 2024 Tsiry Sandratraina <tsiry.sndr@fluentci.io> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,54 @@ | ||
# Opentelemetry Collector Plugin | ||
|
||
[![fluentci pipeline](https://shield.fluentci.io/x/opentelemetry-collector)](https://pkg.fluentci.io/opentelemetry-collector) | ||
[![ci](https://github.com/fluentci-io/services/actions/workflows/opentelemetry-collector.yml/badge.svg)](https://github.com/fluentci-io/services/actions/workflows/opentelemetry-collector.yml) | ||
|
||
Opentelemetry service plugin for FluentCI. | ||
|
||
## 🚀 Usage | ||
|
||
Add the following command to your CI configuration file: | ||
|
||
```bash | ||
fluentci run --wasm opentelemetry-collector start | ||
``` | ||
|
||
## Functions | ||
|
||
| Name | Description | | ||
| ------ | --------------------------------------------| | ||
| start | Start Opentelemetry Collector | | ||
| stop | Stop Opentelemetry Collector | | ||
|
||
## Code Usage | ||
|
||
Add `fluentci-pdk` crate to your `Cargo.toml`: | ||
|
||
```toml | ||
[dependencies] | ||
fluentci-pdk = "0.2.1" | ||
``` | ||
|
||
Use the following code to call the plugin: | ||
|
||
```rust | ||
use fluentci_pdk::dag; | ||
|
||
// ... | ||
|
||
dag().call("https://pkg.fluentci.io/opentelemetry-collector@v0.1.0?wasm=1", "start", vec![])?; | ||
``` | ||
|
||
## 📚 Examples | ||
|
||
Github Actions: | ||
|
||
```yaml | ||
- name: Setup Fluent CI CLI | ||
uses: fluentci-io/setup-fluentci@v5 | ||
with: | ||
wasm: true | ||
plugin: opentelemetry-collector | ||
args: | | ||
start | ||
``` |
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,11 @@ | ||
[package] | ||
authors = [ | ||
"Tsiry Sandratraina <tsiry.sndr@fluentci.io>", | ||
] | ||
description = "Opentelemetry Collector Plugin for FluentCI" | ||
keywords = [ | ||
"opentelemetry", | ||
] | ||
license = "MIT" | ||
name = "opentelemetry-collector" | ||
version = "0.1.0" |
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,35 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
endpoint: 0.0.0.0:$OPENTELEMETRY_PORT | ||
http: | ||
endpoint: 0.0.0.0:$OPENTELEMETRY_HTTP_PORT | ||
processors: | ||
batch: | ||
|
||
exporters: | ||
otlp: | ||
endpoint: otelcol:4317 | ||
|
||
extensions: | ||
health_check: | ||
endpoint: localhost:13133 | ||
pprof: | ||
zpages: | ||
|
||
service: | ||
extensions: [health_check, pprof, zpages] | ||
pipelines: | ||
traces: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [otlp] | ||
metrics: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [otlp] | ||
logs: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [otlp] |
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,60 @@ | ||
use anyhow::Error; | ||
use fluentci_pdk::dag; | ||
|
||
pub fn setup_flox() -> Result<(), Error> { | ||
let os = dag().get_os()?; | ||
if os == "macos" { | ||
dag() | ||
.pipeline("setup-flox")? | ||
.with_exec(vec![r#"type brew > /dev/null 2> /dev/null || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)""#])? | ||
.with_exec(vec!["type flox > /dev/null 2> /dev/null || brew install flox"])? | ||
.stdout()?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn setup() -> Result<String, Error> { | ||
setup_flox()?; | ||
dag() | ||
.pipeline("setup")? | ||
.with_exec(vec!["mkdir", "-p", ".fluentci/opentelemetry-collector"])? | ||
.stdout()?; | ||
|
||
let pwd = dag().get_env("PWD")?; | ||
let otel_port = dag().get_env("OPENTELEMETRY_PORT")?; | ||
let otel_http_port = dag().get_env("OPENTELEMETRY_HTTP_PORT")?; | ||
let otel_config = dag().get_env("OPENTELEMETRY_CONFIG")?; | ||
|
||
if otel_port.is_empty() { | ||
dag().set_envs(vec![("OPENTELEMETRY_PORT".into(), "4317".into())])?; | ||
} | ||
if otel_http_port.is_empty() { | ||
dag().set_envs(vec![("OPENTELEMETRY_HTTP_PORT".into(), "4318".into())])?; | ||
} | ||
|
||
if otel_config.is_empty() { | ||
dag().set_envs(vec![( | ||
"OPENTELEMETRY_CONFIG".into(), | ||
format!("{}/otel-config.yaml", pwd), | ||
)])?; | ||
} | ||
|
||
let stdout = dag() | ||
.flox()? | ||
.with_workdir(".fluentci/opentelemetry-collector")? | ||
.with_exec(vec![ | ||
"flox", | ||
"install", | ||
"opentelemetry-collector-contrib", | ||
"overmind", | ||
"tmux", | ||
])? | ||
.with_exec(vec!["[ -f otel-config.yaml.template ] || pkgx wget https://raw.githubusercontent.com/fluentci-io/services/main/opentelemetry-collector/otel-config.yaml.template"])? | ||
.with_exec(vec!["[ -f $OPENTELEMETRY_CONFIG ] || pkgx envsubst < otel-config.yaml.template > $OPENTELEMETRY_CONFIG "])? | ||
.with_exec(vec![ | ||
"grep -q opentelemetry-collector: Procfile || echo -e 'opentelemetry-collector: otelcontribcol --config $OPENTELEMETRY_CONFIG \\n' >> Procfile", | ||
])? | ||
.stdout()?; | ||
|
||
Ok(stdout) | ||
} |
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,49 @@ | ||
use extism_pdk::*; | ||
use fluentci_pdk::dag; | ||
|
||
pub mod helpers; | ||
|
||
#[plugin_fn] | ||
pub fn start(_args: String) -> FnResult<String> { | ||
helpers::setup()?; | ||
|
||
let port = dag().get_env("OPENTELEMETRY_PORT")?; | ||
let http_port = dag().get_env("OPENTELEMETRY_HTTP_PORT")?; | ||
|
||
let stdout = dag() | ||
.flox()? | ||
.with_workdir(".fluentci/opentelemetry-collector")? | ||
.with_exec(vec!["overmind", "--version"])? | ||
.with_exec(vec!["type", "overmind"])? | ||
.with_exec(vec!["type", "otelcontribcol"])? | ||
.with_exec(vec!["otelcontribcol", "--version"])? | ||
.with_exec(vec![ | ||
"echo -e \"OpenTelemetry Collector starting on port $OPENTELEMETRY_PORT\"", | ||
])? | ||
.with_exec(vec![ | ||
"overmind start -f Procfile --daemonize || flox activate -- overmind restart opentelemetry-collector", | ||
])? | ||
.wait_on(port.parse()?, None)? | ||
.wait_on(http_port.parse()?, None)? | ||
.with_exec(vec!["overmind", "status"])? | ||
.stdout()?; | ||
Ok(stdout) | ||
} | ||
|
||
#[plugin_fn] | ||
pub fn stop(args: String) -> FnResult<String> { | ||
helpers::setup()?; | ||
|
||
let args = if args.is_empty() { | ||
"opentelemetry-collector".to_string() | ||
} else { | ||
args | ||
}; | ||
|
||
let stdout = dag() | ||
.flox()? | ||
.with_workdir(".fluentci/opentelemetry-collector")? | ||
.with_exec(vec!["overmind", "stop", &args])? | ||
.stdout()?; | ||
Ok(stdout) | ||
} |
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 @@ | ||
../target |