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

chore: ignore warning in prod #1152

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions docs/030_user-guide/120_customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

This document outlines how to customize the build output through Helm overrides and `package.json` configurations.

## Display Node Warnings

You can display warnings in the logs by setting the `PEPR_NODE_WARNINGS` environment variable to `true` in the `package.json` file or directly on the Watcher or Admission `Deployment`. The default value is `undefined`.

```json
{
"env": {
"PEPR_NODE_WARNINGS": "true"
}
}
```

## Customizing Log Format

The log format can be customized by setting the `PINO_TIME_STAMP` environment variable in the `package.json` file or directly on the Watcher or Admission `Deployment`. The default value is a partial JSON timestamp string representation of the time. If set to `iso`, the timestamp is displayed in an ISO format.
Expand Down
9 changes: 9 additions & 0 deletions docs/080_faq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

## How do I remove the punycode warning?

By default, warnings are removed. You can allow warnings by setting the `PEPR_NODE_WARNINGS` environment variable.

```bash
PEPR_NODE_WARNINGS="true"
```

If you allow warnings, you can disable the specific punycode warning by:

```bash
export NODE_OPTIONS="--disable-warning=DEP0040"
```
Expand All @@ -13,6 +21,7 @@ or
npx --node-options="--disable-warning=DEP0040" pepr [command]
```


## How does Pepr compare to Operator SDK?

Pepr and Operator SDK are both frameworks used for building Kubernetes operators and admission controllers. While they share a common goal of simplifying the creation of Kubernetes operators and enhancing Kubernetes functionality, they have different approaches and features.
Expand Down
6 changes: 4 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import update from "./cli/update";
import kfc from "./cli/kfc";

if (process.env.npm_lifecycle_event !== "npx") {
console.warn("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
console.info("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
}

const program = new RootCmd();

if (!process.env.PEPR_NODE_WARNINGS) {
process.removeAllListeners("warning");
}
program
.version(version)
.description(`Pepr (v${version}) - Type safe K8s middleware for humans`)
Expand Down
6 changes: 3 additions & 3 deletions src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default function (program: RootCmd) {

// If registry is set to Iron Bank, use Iron Bank image
if (opts?.registry == "Iron Bank") {
console.warn(
console.info(
`\n\tThis command assumes the latest release. Pepr's Iron Bank image release cycle is dictated by renovate and is typically released a few days after the GitHub release.\n\tAs an alternative you may consider custom --custom-image to target a specific image and version.`,
);
image = `registry1.dso.mil/ironbank/opensource/defenseunicorns/pepr/controller:v${cfg.pepr.peprVersion}`;
Expand Down Expand Up @@ -348,15 +348,15 @@ export async function buildModule(reloader?: Reloader, entryPoint = peprTS, embe

// If the regex didn't match, leave a generic error
if (conflicts.length < 1) {
console.warn(
console.info(
`\n\tOne or more imported Pepr Capabilities seem to be using an incompatible version of Pepr.\n\tTry updating your Pepr Capabilities to their latest versions.`,
"Version Conflict",
);
}

// Otherwise, loop through each conflicting package and print an error
conflicts.forEach(match => {
console.warn(
console.info(
`\n\tPackage '${match[1]}' seems to be incompatible with your current version of Pepr.\n\tTry updating to the latest version.`,
"Version Conflict",
);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function (program: RootCmd) {
}
}
} catch {
console.warn(`\nIGNORED - Unable to parse line: ${line}.`);
// Do nothing
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/assets/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function loadCapabilities(path: string): Promise<CapabilityExport[]> {
...process.env,
LOG_LEVEL: "warn",
PEPR_MODE: "build",
NODE_OPTIONS: "--disable-warning=DEP0040",
},
});

Expand Down
9 changes: 6 additions & 3 deletions src/lib/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { validateProcessor } from "../validate-processor";
import { PeprControllerStore } from "./store";
import { ResponseItem } from "../types";

if (!process.env.PEPR_NODE_WARNINGS) {
process.removeAllListeners("warning");
}
export class Controller {
// Track whether the server is running
#running = false;
Expand Down Expand Up @@ -108,7 +111,7 @@ export class Controller {
// Handle EADDRINUSE errors
server.on("error", (e: { code: string }) => {
if (e.code === "EADDRINUSE") {
Log.warn(
Log.info(
`Address in use, retrying in 2 seconds. If this persists, ensure ${port} is not in use, e.g. "lsof -i :${port}"`,
);
setTimeout(() => {
Expand Down Expand Up @@ -162,7 +165,7 @@ export class Controller {
const { token } = req.params;
if (token !== this.#token) {
const err = `Unauthorized: invalid token '${token.replace(/[^\w]/g, "_")}'`;
Log.warn(err);
Log.info(err);
res.status(401).send(err);
this.#metricsCollector.alert();
return;
Expand Down Expand Up @@ -304,7 +307,7 @@ export class Controller {
duration: `${elapsedTime} ms`,
};

res.statusCode >= 300 ? Log.warn(message) : Log.info(message);
Log.info(message);
});

next();
Expand Down
Loading