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

Add Ruby app metrics support #172

Merged
merged 40 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
439d266
Introduce new metrics buildpack
schneems Jul 13, 2023
5f449e6
Update build output
schneems Jul 19, 2023
32a611b
Attempting workaround with exec.d
schneems Jul 18, 2023
7074806
Run agentmon with Ubuntu's start-stop-daemon
schneems Jul 19, 2023
669ef6f
Fix spelling
schneems Jul 19, 2023
f247694
Move background loop logic from bash to Rust
schneems Jul 19, 2023
2bba03c
Add metrics integration test with WIP libcnb-test feature
schneems Aug 9, 2023
54605d4
Enable agentmon logging
schneems Aug 9, 2023
cc1684e
Clippy
schneems Aug 9, 2023
0d6cbbc
Fix tool key
schneems Aug 10, 2023
a50891a
Prefix image with `buildpack-`
schneems Aug 10, 2023
8528b0b
Update agentmon_loop
schneems Aug 10, 2023
7bae992
Remove unneeded enum contortions
schneems Aug 10, 2023
c5510f3
Inline binary logic and consolidate test logic
schneems Aug 11, 2023
802b9a6
Hardcode agentmon url, improve caching
schneems Aug 11, 2023
61adc80
Move metrics logic inside of heroku/ruby
schneems Aug 28, 2023
e988a9e
Revert "Update build output"
schneems Aug 28, 2023
be5d071
Changelog entry and fix tests
schneems Aug 28, 2023
ab2e6da
Update buildpacks/ruby/Cargo.toml
schneems Sep 11, 2023
ce540e4
Prefer unwrap_or_else over match with Ok(_)
schneems Sep 11, 2023
2897d75
Remove changelog prefix
schneems Sep 11, 2023
e41ae1f
Prefer unwrap_or_else over match with Ok(_)
schneems Sep 11, 2023
aade4c0
Prefer HasMap::from() over mut HashMap::new()
schneems Sep 11, 2023
dcea764
Fix docs
schneems Sep 11, 2023
a7d3d4c
Use `Path::try_exists()` instead of `exists()`
schneems Sep 11, 2023
b68c177
Fix stringly typed errors
schneems Sep 11, 2023
283e600
Env var key is static & add disable instructions
schneems Sep 11, 2023
991adb4
Static env var keys and tests
schneems Sep 11, 2023
abcf16d
Make error more specific
schneems Sep 11, 2023
daa1074
Simplify spawning daemon
schneems Sep 11, 2023
b5540ad
Match functionality to function name
schneems Sep 11, 2023
8e40054
Log when barnes is installed, or isn't
schneems Sep 11, 2023
81d2fa4
Address process booting determinism
schneems Sep 12, 2023
98ab37c
Update buildpacks/ruby/src/layers/metrics_agent_install.rs
schneems Sep 12, 2023
6627345
Remove unneeded BuildpackReference::Crate
schneems Sep 12, 2023
40a5b81
Fix accidentally removed line
schneems Sep 12, 2023
41c12fe
Remove unused workspace declarations
schneems Sep 12, 2023
4ef43ee
Add download checksum for agentmon TGZ
schneems Sep 18, 2023
43cbaa6
Update changelog to use Keep a Changelog format
schneems Sep 18, 2023
f4abf4d
Prefer shared tooling
schneems Sep 18, 2023
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions buildpacks/ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ thiserror = "1"
ureq = "2"
url = "2"
clap = { version = "4", features = ["derive"] }
sha2 = "0.10.7"

[dev-dependencies]
libcnb-test = "=0.14.0"
Expand Down
24 changes: 24 additions & 0 deletions buildpacks/ruby/src/layers/metrics_agent_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use libcnb::{
layer::{Layer, LayerResultBuilder},
};
use serde::{Deserialize, Serialize};
use sha2::Digest;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use tar::Archive;
Expand All @@ -26,6 +27,7 @@ use tempfile::NamedTempFile;
/// ```
const DOWNLOAD_URL: &str =
Malax marked this conversation as resolved.
Show resolved Hide resolved
"https://agentmon-releases.s3.us-east-1.amazonaws.com/agentmon-0.3.1-linux-amd64.tar.gz";
const DOWNLOAD_SHA: &str = "f9bf9f33c949e15ffed77046ca38f8dae9307b6a0181c6af29a25dec46eb2dac";

#[derive(Debug)]
pub(crate) struct MetricsAgentInstall {
Expand Down Expand Up @@ -57,6 +59,9 @@ pub(crate) enum MetricsAgentInstallError {

#[error("Could not write file: {0}")]
CouldNotWriteDestinationFile(std::io::Error),

#[error("Checksum of download failed. Expected {DOWNLOAD_SHA} got {0}")]
ChecksumFailed(String),
}

impl Layer for MetricsAgentInstall {
Expand Down Expand Up @@ -153,6 +158,15 @@ impl Layer for MetricsAgentInstall {
}
}

// Check integrity of download, `sha_some` is awesome.
fn sha_some(path: &Path) -> Result<String, std::io::Error> {
schneems marked this conversation as resolved.
Show resolved Hide resolved
let mut hasher = sha2::Sha256::new();
let contents = fs_err::read(path)?;
hasher.update(&contents);

Ok(format!("{:x}", hasher.finalize()))
}

fn write_execd_script(
agentmon: &Path,
layer_path: &Path,
Expand Down Expand Up @@ -212,6 +226,16 @@ fn download_untar(

download(url, agentmon_tgz.path())?;

sha_some(agentmon_tgz.path())
.map_err(MetricsAgentInstallError::CouldNotOpenFile)
.and_then(|checksum| {
if DOWNLOAD_SHA == checksum {
Ok(())
} else {
Err(MetricsAgentInstallError::ChecksumFailed(checksum))
}
})?;

untar(agentmon_tgz.path(), destination)?;

Ok(())
Expand Down