-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of diagnose CLI
- Loading branch information
Adam Yeats
committed
Sep 2, 2020
1 parent
453745f
commit c376bb0
Showing
9 changed files
with
227 additions
and
34 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
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 |
---|---|---|
@@ -1,25 +1,51 @@ | ||
const path = require("path") | ||
|
||
const { AGENT_VERSION } = require("./extension/constants") | ||
const { hasMusl } = require("./extension/helpers") | ||
|
||
function createReport() { | ||
return { | ||
result: { status: "incomplete" }, | ||
language: { | ||
name: "nodejs", | ||
version: process.versions["node"] | ||
}, | ||
build: { | ||
time: new Date().toISOString(), | ||
packagePath: path.join(__dirname, "/../ext/"), | ||
architecture: process.arch, | ||
target: process.platform, | ||
muslOverride: (process.env["APPSIGNAL_BUILD_FOR_MUSL"] === "true") || hasMusl(), | ||
libraryType: "static" | ||
version: process.versions["node"], | ||
implementation: "nodejs" | ||
}, | ||
download: {}, | ||
build: {}, | ||
host: { | ||
rootUser: process.getuid && process.getuid() === 0, | ||
dependencies: {} | ||
} | ||
} | ||
} | ||
|
||
exports.createReport = createReport | ||
function createBuildReport({ isLocalBuild = false }) { | ||
return { | ||
time: new Date().toISOString(), | ||
package_path: path.join(__dirname, "/../ext/"), | ||
architecture: process.arch, | ||
target: process.platform, | ||
musl_override: | ||
process.env["APPSIGNAL_BUILD_FOR_MUSL"] === "true" || hasMusl(), | ||
library_type: "static", | ||
dependencies: {}, | ||
flags: {}, | ||
source: isLocalBuild ? "local" : "remote", | ||
agent_version: AGENT_VERSION | ||
} | ||
} | ||
|
||
function createDownloadReport({ verified = false, downloadUrl: download_url }) { | ||
return { | ||
checksum: verified ? "verified" : "unverified", | ||
http_proxy: null, | ||
download_url | ||
} | ||
} | ||
|
||
module.exports = { | ||
createReport, | ||
createBuildReport, | ||
createDownloadReport | ||
} |
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,52 @@ | ||
#!/usr/bin/env node | ||
|
||
const https = require("https") | ||
const { DiagnoseTool } = require("../dist/diagnose") | ||
|
||
// enable diagnose mode | ||
process.env["_APPSIGNAL_DIAGNOSE"] = "true" | ||
|
||
const tool = new DiagnoseTool() | ||
|
||
console.log(` | ||
🔧 AppSignal Diagnose Tool | ||
Use this information to debug your configuration. | ||
More information is available on the documentation site. | ||
https://docs.appsignal.com/ | ||
Send this output to support@appsignal.com if you need help. | ||
`) | ||
|
||
if (!process.env["APPSIGNAL_PUSH_API_KEY"]) { | ||
throw new Error(`No Push API key found. Set the APPSIGNAL_PUSH_API_KEY environment variable to your Push API key and try again.`) | ||
} | ||
|
||
const data = tool.generate() | ||
const json = JSON.stringify(data) | ||
|
||
const opts = { | ||
port: 443, | ||
method: "POST", | ||
host: "appsignal.com", | ||
path: "/diag", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Content-Length": json.length | ||
} | ||
} | ||
|
||
const req = https.request(opts, res => { | ||
res.setEncoding("utf8") | ||
}) | ||
|
||
req.on("error", e => { | ||
console.error(`Problem with diagnose request: ${e.message}`) | ||
}) | ||
|
||
// Write data to request body | ||
req.write(json) | ||
req.end() | ||
|
||
console.log(data, "\n") | ||
console.log("✅ Done!") |
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
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,75 @@ | ||
import fs from "fs" | ||
|
||
import { Agent } from "./agent" | ||
import { Configuration } from "./config" | ||
import { AGENT_VERSION, VERSION } from "./version" | ||
|
||
export class DiagnoseTool { | ||
#config: Configuration | ||
#agent: Agent | ||
|
||
constructor() { | ||
this.#config = new Configuration({}) | ||
this.#agent = new Agent({ active: true }) | ||
} | ||
|
||
/** | ||
* Reports are serialized to JSON and send to an endpoint that expects | ||
* snake_case keys, thus the keys in the report on this side must be snake cased also. | ||
*/ | ||
public generate() { | ||
return { | ||
library: this.getLibraryData(), | ||
installation: this.getInstallationReport(), | ||
host: this.getHostData(), | ||
app: {}, | ||
agent: this.#agent.diagnose(), | ||
config: { | ||
options: {}, | ||
sources: {} | ||
}, | ||
validation: { push_api_key: "valid" }, | ||
process: { | ||
uid: process.getuid() | ||
}, | ||
paths: this.getPathsData() | ||
} | ||
} | ||
|
||
private getLibraryData() { | ||
return { | ||
language: "nodejs", | ||
package_version: VERSION, | ||
agent_version: AGENT_VERSION, | ||
extension_loaded: this.#agent.isLoaded | ||
} | ||
} | ||
|
||
private getHostData() { | ||
return { | ||
architecture: process.arch, | ||
os: process.platform, | ||
language_version: process.versions.node, | ||
heroku: !!process.env["DYNO"], | ||
root_user: process.getuid() === 0, | ||
running_in_container: false | ||
} | ||
} | ||
|
||
private getInstallationReport() { | ||
try { | ||
const report = fs.readFileSync( | ||
"/tmp/appsignal-install-report.json", | ||
"utf8" | ||
) | ||
|
||
return report ? JSON.parse(report) : {} | ||
} catch (e) { | ||
return {} | ||
} | ||
} | ||
|
||
private getPathsData() { | ||
return {} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Do not touch this file, auto-generated by scripts/create-versionfile | ||
export const VERSION = "0.6.1" | ||
export const AGENT_VERSION = "6251929" |