Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
};

dlang-nix = {
url = "github:PetarKirov/dlang.nix?branch=feat/build-dub-package&rev=dab4c199ad644dc23b0b9481e2e5a063e9492b84";
url = "github:PetarKirov/dlang.nix/feat/build-dub-package";
inputs = {
flake-compat.follows = "flake-compat";
flake-parts.follows = "flake-parts";
Expand Down
4 changes: 2 additions & 2 deletions packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
// optionalAttrs isLinux {
folder-size-metrics = pkgs.callPackage ./folder-size-metrics { };
}
// optionalAttrs (system == "x86_64-linux") {
// optionalAttrs (system == "x86_64-linux") rec {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to make this attrset recursive:

Suggested change
// optionalAttrs (system == "x86_64-linux") rec {
// optionalAttrs (system == "x86_64-linux") {

mcl = pkgs.callPackage ./mcl {
buildDubPackage = inputs'.dlang-nix.legacyPackages.buildDubPackage.override {
ldc = inputs'.dlang-nix.packages."ldc-binary-1_34_0";
dCompiler = inputs'.dlang-nix.packages."ldc-binary-1_38_0";
};
inherit (legacyPackages.inputs.nixpkgs) cachix nix nix-eval-jobs;
};
Expand Down
22 changes: 15 additions & 7 deletions packages/mcl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,36 @@
...
}:
let
inherit (pkgs.hostPlatform) isLinux isx86;
deps =
with pkgs;
[
nix
nix-eval-jobs
]
++ (with pkgs; [
gitMinimal
gawk
dmidecode
jc
edid-decode
coreutils-full
util-linux
xorg.xrandr
glxinfo
perl
alejandra
openssh
cachix
]);
curl
])
++ lib.optionals (isLinux && isx86) [
dmidecode
glxinfo
nixos-install-tools
systemd
];
excludedTests = (
lib.concatStringsSep "|" [
"(nix\\.(build|run))"
"(nix\\.(build|run|eval))"
"fetchJson|(coda\.)"
"checkPackage"
"generateShardMatrix"
Expand All @@ -52,17 +62,15 @@ buildDubPackage rec {
nativeBuildInputs = [ pkgs.makeWrapper ] ++ deps;

postFixup = ''
wrapProgram $out/bin/${pname} --set PATH "${lib.makeBinPath deps}"
wrapProgram $out/bin/${pname} --set PATH "${lib.makeBinPath deps}" --set LD_LIBRARY_PATH "${lib.makeLibraryPath deps}"
'';

dubBuildFlags = [
"--compiler=dmd"
"-b"
"debug"
];

dubTestFlags = [
"--compiler=dmd"
"--"
"-e"
excludedTests
Expand Down
91 changes: 89 additions & 2 deletions packages/mcl/src/src/mcl/commands/host_info.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import std.stdio : writeln;
import std.conv : to;
import std.string : strip, indexOf, isNumeric;
import std.array : split, join, array, replace;
import std.algorithm : map, filter, startsWith, joiner, any, sum;
import std.algorithm : map, filter, startsWith, joiner, any, sum, find;
import std.file : exists, write, readText, readLink, dirEntries, SpanMode;
import std.path : baseName;
import std.json;
Expand All @@ -22,6 +22,7 @@ import mcl.utils.process : execute, isRoot;
import mcl.utils.number : humanReadableSize;
import mcl.utils.array : uniqIfSame;
import mcl.utils.nix : Literal;
import mcl.utils.coda;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use selective imports:

Suggested change
import mcl.utils.coda;
import mcl.utils.coda : CodaApiClient, RowValues, CodaCell;


// enum InfoFormat
// {
Expand All @@ -34,10 +35,12 @@ struct Params
{
// @optional()
// InfoFormat format = InfoFormat.JSON;
@optional() string codaApiToken;
void setup()
{
}
}
Params params;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid global variables, as they make the control flow harder to reason about as the codebase evolves.


string[string] cpuinfo;

Expand All @@ -64,7 +67,7 @@ string[string] getProcInfo(string fileOrData, bool file = true)

export void host_info()
{
const params = parseEnv!Params;
params = parseEnv!Params;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should remain a local const variable. If necessary add parameters to the functions that need to access it.


Info info = getInfo();

Expand All @@ -79,6 +82,8 @@ Info getInfo()
meminfo = getProcInfo("/proc/meminfo");

Info info;
info.softwareInfo.hostid = execute("hostid", false);
info.softwareInfo.hostname = execute("cat /etc/hostname", false);
info.softwareInfo.operatingSystemInfo = getOperatingSystemInfo();
info.softwareInfo.opensshInfo = getOpenSSHInfo();
info.softwareInfo.machineConfigInfo = getMachineConfigInfo();
Expand All @@ -90,6 +95,86 @@ Info getInfo()
info.hardwareInfo.displayInfo = getDisplayInfo();
info.hardwareInfo.graphicsProcessorInfo = getGraphicsProcessorInfo();

if (params.codaApiToken) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Inform the user of this conditional behavior by logging:

  • No Coda API token specified -> not uploading to Coda
  • Coda API token specified -> uploading

(feed free to rephrase the messages)

auto docId = "0rz18jyJ1M";
auto hostTableId = "grid-b3MAjem325";
auto cpuTableId = "grid-mCI3x3nEIE";
auto memoryTableId = "grid-o7o2PeB4rz";
auto motherboardTableId = "grid-270PlzmA8K";
auto gpuTableId = "grid-ho6EPztvni";
auto storageTableId = "grid-JvXFbttMNz";
auto osTableId = "grid-ora7n98-ls";
auto coda = CodaApiClient(params.codaApiToken);

auto hostValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Host ID", info.softwareInfo.hostid),
CodaCell("OpenSSH Public Key", info.softwareInfo.opensshInfo.publicKey),
CodaCell("JSON", info.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes))
]);

coda.updateOrInsertRow(docId, hostTableId, hostValues);

auto cpuValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Vendor", info.hardwareInfo.processorInfo.vendor),
CodaCell("Model", info.hardwareInfo.processorInfo.model),
CodaCell("Architecture", info.hardwareInfo.processorInfo.architectureInfo.architecture),
CodaCell("Flags", info.hardwareInfo.processorInfo.architectureInfo.flags),
]);
coda.updateOrInsertRow(docId, cpuTableId, cpuValues);

auto memoryValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Vendor", info.hardwareInfo.memoryInfo.vendor),
CodaCell("Part Number", info.hardwareInfo.memoryInfo.partNumber),
CodaCell("Serial", info.hardwareInfo.memoryInfo.serial),
CodaCell("Generation", info.hardwareInfo.memoryInfo.type),
CodaCell("Slots", info.hardwareInfo.memoryInfo.slots == 0 ? "Soldered" : info.hardwareInfo.memoryInfo.count.to!string ~ "/" ~ info.hardwareInfo.memoryInfo.slots.to!string),
CodaCell("Total", info.hardwareInfo.memoryInfo.total),
CodaCell("Speed", info.hardwareInfo.memoryInfo.speed),
]);
coda.updateOrInsertRow(docId, memoryTableId, memoryValues);

auto motherboardValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Vendor", info.hardwareInfo.motherboardInfo.vendor),
CodaCell("Model", info.hardwareInfo.motherboardInfo.model),
CodaCell("Revision", info.hardwareInfo.motherboardInfo.version_),
CodaCell("Serial", info.hardwareInfo.motherboardInfo.serial),
CodaCell("BIOS Vendor", info.hardwareInfo.motherboardInfo.biosInfo.vendor),
CodaCell("BIOS Version", info.hardwareInfo.motherboardInfo.biosInfo.version_),
CodaCell("BIOS Release", info.hardwareInfo.motherboardInfo.biosInfo.release),
CodaCell("BIOS Date", info.hardwareInfo.motherboardInfo.biosInfo.date)
]);
coda.updateOrInsertRow(docId, motherboardTableId, motherboardValues);

auto gpuValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Vendor", info.hardwareInfo.graphicsProcessorInfo.vendor),
CodaCell("Model", info.hardwareInfo.graphicsProcessorInfo.model),
CodaCell("VRam", info.hardwareInfo.graphicsProcessorInfo.vram)
]);
coda.updateOrInsertRow(docId, gpuTableId, gpuValues);

auto osValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Distribution", info.softwareInfo.operatingSystemInfo.distribution),
CodaCell("Distribution Version", info.softwareInfo.operatingSystemInfo.distributionVersion),
CodaCell("Kernel", info.softwareInfo.operatingSystemInfo.kernel),
CodaCell("Kernel Version", info.softwareInfo.operatingSystemInfo.kernelVersion)
]);
coda.updateOrInsertRow(docId, osTableId, osValues);

auto storageValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Count", info.hardwareInfo.storageInfo.devices.length.to!string),
CodaCell("Total", info.hardwareInfo.storageInfo.total),
CodaCell("JSON", info.hardwareInfo.storageInfo.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes))
]);
coda.updateOrInsertRow(docId, storageTableId, storageValues);
}

return info;
}

Expand All @@ -101,6 +186,8 @@ struct Info

struct SoftwareInfo
{
string hostname;
string hostid;
OperatingSystemInfo operatingSystemInfo;
OpenSSHInfo opensshInfo;
MachineConfigInfo machineConfigInfo;
Expand Down
12 changes: 11 additions & 1 deletion packages/mcl/src/src/mcl/utils/coda.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import std.traits : isArray;
import mcl.utils.json : toJSON, fromJSON;
import std.process : environment;
import std.stdio : writeln, writefln;
import std.algorithm : map, filter;
import std.algorithm : map, filter, find;
import std.exception : assertThrown;
import std.sumtype : SumType;
import core.thread;
Expand Down Expand Up @@ -527,6 +527,16 @@ struct CodaApiClient
coda.deleteRow("dEJJPwdxcw", tables[0].id, resp[0]);
}

void updateOrInsertRow(string docId, string tableId, RowValues values) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to the Coda Api docs, we should be able to directly create an "Upsert" request, without first fetching the data:

https://coda.io/developers/apis/v1#tag/Rows/operation/upsertRows

Can you look into directly doing an upsert?

auto table = listRows(docId, tableId);
auto rows = find!(row => row.name == values.cells[0].value)(table);
if (rows.length > 0) {
updateRow(docId, tableId, rows[0].id, values);
}
else {
insertRows(docId, tableId, [values]);
}
}
struct PushButtonResponse {
string requestId;
string rowId;
Expand Down
1 change: 1 addition & 0 deletions packages/mcl/src/src/mcl/utils/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ T execute(T = string)(string[] args, bool printCommand = true, bool returnErr =
import std.array : join;
import std.algorithm : map;
import std.conv : to;
import std.stdio : writeln;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this line is unused:

Suggested change
import std.stdio : writeln;


auto cmd = args.map!escapeShellCommand.join(" ");

Expand Down