Skip to content

Commit

Permalink
Merge pull request #29 from instaclustr/make_ci_pass
Browse files Browse the repository at this point in the history
get CI passing
  • Loading branch information
cjrolo authored Sep 28, 2023
2 parents 3fd7cf9 + 9732510 commit 3e8c0dd
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 148 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ jobs:
# we also need to add the runner and cargo_flags to the key so that a seperate cache is used.
# Otherwise only the last build to finish would get saved to the cache.
key: ${{ matrix.runner }} - ${{ matrix.cargo_flags }}
- name: Install external deps for the prom-remote-api crate
run: sudo apt-get install protobuf-compiler
- name: Install cargo-hack
run: cargo install cargo-hack --version 0.5.8
- name: Check `cargo fmt` was run
run: cargo fmt --all -- --check
# lucas - I strongly reccomend reenabling this in the future,
# but I've disabled it for now so I dont trash this already large diff with formatting changes
#- name: Check `cargo fmt` was run
# run: cargo fmt --all -- --check
- name: Ensure that all crates compile and have no warnings under every possible combination of features
# some things to explicitly point out:
# * clippy also reports rustc warnings and errors
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"prometheus-remote",
"tools",
]
resolver = "2"

[profile.dev]
opt-level = 0
Expand Down
2 changes: 1 addition & 1 deletion brro-compressor/src/compressor/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Constant {
pub fn to_bytes(self) -> Vec<u8> {
// Use Bincode and flate2-rs? Do this at the Stream Level?
let config = BinConfig::get();
bincode::encode_to_vec(&self, config).unwrap()
bincode::encode_to_vec(self, config).unwrap()
}
}

Expand Down
2 changes: 1 addition & 1 deletion brro-compressor/src/compressor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bincode::config::{self, Configuration};
use crate::compressor::constant::{constant};
use crate::compressor::constant::constant;

pub mod noop;
pub mod constant;
Expand Down
6 changes: 3 additions & 3 deletions brro-compressor/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::frame::CompressorFrame;
use crate::frame::CompressorFrame;
use crate::header::CompressorHeader;

pub struct CompressedStream {
Expand All @@ -9,9 +9,9 @@ pub struct CompressedStream {
impl CompressedStream {
/// Creates an empty compressor stream
pub fn new() -> Self {
CompressedStream {
CompressedStream {
header: CompressorHeader::new(),
data_frames: Vec::new(),
}
}
}
}
2 changes: 1 addition & 1 deletion brro-compressor/src/frame/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::compressor::{self, Compressor};
use crate::compressor::Compressor;

/// This is the structure of a compressor frame
pub struct CompressorFrame{
Expand Down
7 changes: 6 additions & 1 deletion brro-compressor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#![allow(clippy::new_without_default)]

// Lucas - Once the project is far enough along I strongly reccomend reenabling dead code checks
#![allow(dead_code)]

pub mod compressor;
pub mod frame;
pub mod preprocessor;
pub mod utils;
mod header;
mod data;
mod data;
3 changes: 0 additions & 3 deletions brro-compressor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use log::{info, debug};
use clap::{Parser, command, arg};

#[macro_use]
extern crate log;

#[derive(Parser, Default, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
Expand Down
8 changes: 4 additions & 4 deletions brro-compressor/src/utils/file_type_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::fs::File;
use std::io::{BufReader, Read, Result, Take, Error, ErrorKind};

enum FileType {
WAV,
RAW,
Wav,
Raw,
}

fn is_wav(reader: &mut Take<BufReader<File>>) -> Result<bool> {
Expand All @@ -21,8 +21,8 @@ fn detect_file_type(filename: &str) -> Result<FileType> {
}

if is_wav(&mut BufReader::new(file).take(12))? {
Ok(FileType::WAV)
Ok(FileType::Wav)
} else {
Ok(FileType::RAW)
Ok(FileType::Raw)
}
}
82 changes: 41 additions & 41 deletions optimizer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::fs::File;
// Lucas - Once the project is far enough along I strongly reccomend reenabling dead code checks
#![allow(dead_code)]

use std::{fs::File, path::Path};
use std::io::Write;
use std::fs;
use std::io::{self, BufRead};
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use hound::{WavSpec, WavWriter};
use clap::{Parser, command, arg};
use clap::builder::Str;
use regex::Regex;
use median::Filter;
use log::{debug, error, info, warn};
use log::{debug, error, info};

#[derive(Debug)]
enum MetricTag {
Expand All @@ -21,6 +22,7 @@ enum MetricTag {
}

impl MetricTag {
#[allow(clippy::wrong_self_convention)]
fn from_float(&self, x: f64) -> i64 {
match self {
MetricTag::Other => {
Expand Down Expand Up @@ -70,26 +72,26 @@ fn read_metrics_from_wav(filename: &str) -> Vec<f64> {
current_channel = 0;
}
}
return raw_data;
raw_data
}

fn generate_wav_header(channels: Option<i32>, bitdepth: u16, samplerate: u32) -> WavSpec {
let spec = hound::WavSpec {

hound::WavSpec {
channels: channels.unwrap_or(4) as u16,
// TODO: Sample rate adaptations
sample_rate: samplerate,
bits_per_sample: bitdepth,
sample_format: hound::SampleFormat::Int
};
return spec;
}
}

/// Write a WAV file with the outputs of data analysis for float data
fn write_optimal_wav(filename: &str, data: Vec<f64>, bitdepth: i32, dc: i64, channels: i32) {
// Make DC a float for operations
let fdc = dc as f64;
let header: WavSpec = generate_wav_header(Some(channels), bitdepth as u16, 8000);
let mut file_path = format!("{}", filename);
let mut file_path = filename.to_string();
file_path.truncate(file_path.len() - 4);
file_path = format!("{}_OPT.wav", file_path);
let file = std::fs::OpenOptions::new().write(true).create(true).read(true).open(file_path).unwrap();
Expand All @@ -106,7 +108,7 @@ fn write_optimal_wav(filename: &str, data: Vec<f64>, bitdepth: i32, dc: i64, cha

fn write_optimal_int_wav(filename: &str, data: Vec<i64>, bitdepth: i32, dc: i64, channels: i32) {
let header: WavSpec = generate_wav_header(Some(channels), bitdepth as u16, 8000);
let mut file_path = format!("{}", filename);
let mut file_path = filename.to_string();
file_path.truncate(file_path.len() - 4);
file_path = format!("{}_OPT.wav", file_path);
let file = std::fs::OpenOptions::new().write(true).create(true).read(true).open(file_path).unwrap();
Expand All @@ -122,15 +124,15 @@ fn write_optimal_int_wav(filename: &str, data: Vec<i64>, bitdepth: i32, dc: i64,
}

fn as_i8(value: f64) -> i8 {
return split_n(value).0 as i8;
split_n(value).0 as i8
}

fn as_i16(value: f64) -> i16 {
return split_n(value).0 as i16;
split_n(value).0 as i16
}

fn as_i32(value: f64) -> i32 {
return split_n(value).0 as i32;
split_n(value).0 as i32
}

// Split a float into an integer
Expand Down Expand Up @@ -160,17 +162,16 @@ fn split_n(x: f64) -> (i64, f64) {
} else { // x >> 64..
(0, 0.0)
}
} else {
if shl < 64 { // x << 1..64
let int = mantissa >> (64 - shl);
let fraction = ((mantissa as u64) << shl) as f64 * FRACT_SCALE;
(int, fraction)
} else if shl < 128 { // x << 64..128
let int = mantissa << (shl - 64);
(int, 0.0)
} else { // x << 128..
(0, 0.0)
}
}
else if shl < 64 { // x << 1..64
let int = mantissa >> (64 - shl);
let fraction = ((mantissa as u64) << shl) as f64 * FRACT_SCALE;
(int, fraction)
} else if shl < 128 { // x << 64..128
let int = mantissa << (shl - 64);
(int, 0.0)
} else { // x << 128..
(0, 0.0)
}
}

Expand All @@ -180,8 +181,8 @@ fn join_u16_into_f64(bits: [u16; 4]) -> f64 {
((bits[2] as u64) << 32) |
((bits[3] as u64) << 48);

let f64_value = f64::from_bits(u64_bits);
f64_value

f64::from_bits(u64_bits)
}

fn get_max(a: i32, b: i32) -> i32 {
Expand Down Expand Up @@ -296,8 +297,8 @@ fn find_bitdepth(max_int: i64, min_int: i64) -> i32 {
_ => 64
};

let recommended_bitdepth = get_max(bitdepth, bitdepth_signed);
recommended_bitdepth

get_max(bitdepth, bitdepth_signed)
}

fn process_args(input_path: &str, arguments: &Args) {
Expand Down Expand Up @@ -352,13 +353,12 @@ fn construct_output_path(filename: &str, new_directory: Option<&str>) -> String
}
}

fn process_data_and_write_output(full_path: &PathBuf, file: &mut File, arguments: &Args) {

fn process_data_and_write_output(full_path: &Path, file: &mut File, arguments: &Args) {
let full_path_str = full_path.to_str().unwrap_or("");
debug!("File: {} ,", full_path_str);
let mut bitdepth = 64;
let mut dc_component: i64 = 0;
let mut fractional = true;
let mut _bitdepth = 64;
let mut _dc_component: i64 = 0;
let mut _fractional = true;
let wav_data = read_metrics_from_wav(full_path_str);
if arguments.dump_raw { writeln!(file, "{:?}", wav_data).expect("Unable to write to file"); }
// Depending on Metric Tag, apply a transformation
Expand All @@ -375,21 +375,21 @@ fn process_data_and_write_output(full_path: &PathBuf, file: &mut File, arguments
}
};
// We split the code here
if iwav_data.len() > 0 {
fractional = false;
if !iwav_data.is_empty() {
_fractional = false;
if arguments.dump_optimized { writeln!(file, "{:?}", iwav_data).expect("Unable to write to file"); }
(bitdepth, dc_component) = analyze_int_data(&iwav_data);
(_bitdepth, _dc_component) = analyze_int_data(&iwav_data);
} else {
(bitdepth, dc_component, fractional) = analyze_data(&wav_data);
(_bitdepth, _dc_component, _fractional) = analyze_data(&wav_data);
}
if bitdepth == 64 || fractional {
if _bitdepth == 64 || _fractional {
debug!("No optimization, exiting");
std::process::exit(0);
} else if arguments.write {
debug!("Writing optimal file!");
match iwav_data.len() {
0 => write_optimal_wav(full_path_str, wav_data, bitdepth, dc_component, 1),
_ => write_optimal_int_wav(full_path_str, iwav_data, bitdepth, dc_component, 1)
0 => write_optimal_wav(full_path_str, wav_data, _bitdepth, _dc_component, 1),
_ => write_optimal_int_wav(full_path_str, iwav_data, _bitdepth, _dc_component, 1)
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions prometheus-remote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@ regex = "1.9.1"
median = "0.3.2"
dtw_rs = "0.9.5"

[profile.dev]
opt-level = 0

[profile.release]
opt-level = 3
codegen-units = 1
14 changes: 7 additions & 7 deletions prometheus-remote/src/flac_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl SimpleFlacReader {
((bits[2] as u64) << 32) |
((bits[3] as u64) << 48);

let f64_value = f64::from_bits(u64_bits);
f64_value

f64::from_bits(u64_bits)
}

}
Expand Down Expand Up @@ -116,7 +116,7 @@ impl FlacMetric {
);
// Transform datetime to string with the format YYYY-MM-DD
let datetime_str = datetime.format("%Y-%m-%d").to_string();
return datetime_str;
datetime_str
}

/// Load sample data into the Flac Object
Expand All @@ -137,7 +137,7 @@ impl FlacMetric {
// Probe the media source stream for a format.
let probed = symphonia::default::get_probe().format(Hint::new().mime_type("FLaC"), mss, &format_opts, &metadata_opts).unwrap();
// Get the format reader yielded by the probe operation.
return probed.format;
probed.format
}

fn get_decoder(&self) -> Box<dyn Decoder> {
Expand All @@ -147,7 +147,7 @@ impl FlacMetric {
let track = format.default_track().unwrap();
// Create a decoder for the track.
let decoder = symphonia::default::get_codecs().make(&track.codec_params, &decoder_opts).unwrap();
return decoder;
decoder
}


Expand Down Expand Up @@ -265,8 +265,8 @@ impl FlacMetric {
((bits[2] as u64) << 32) |
((bits[3] as u64) << 48);

let f64_value = f64::from_bits(u64_bits);

f64_value

f64::from_bits(u64_bits)
}
}
Loading

0 comments on commit 3e8c0dd

Please sign in to comment.