chore: Disable Copilot in development environment

This commit is contained in:
Simon Larsen 2024-07-10 13:39:35 +01:00
parent e246e3fbcd
commit 6b9e0c8b99
No known key found for this signature in database
GPG key ID: 96C5DCA24769DBCA
10 changed files with 141 additions and 64 deletions

View file

@ -60,12 +60,6 @@ alias nrb="npm run build"
alias nrfb="npm run force-build"
alias nrps="npm run ps-dev"
# OneUptime Copilot
alias nrfbc="npm run force-build-copilot"
alias nrdc="npm run dev-copilot"
alias nrlc="npm run logs-copilot"
alias nrbc="npm run build-copilot"
# OneUptime LLM Server
alias nrfbl="npm run force-build-llm"
alias nrdl="npm run dev-llm"

View file

@ -1,20 +1,86 @@
## Setting up Custom Probes
You can set up custom probes inside your network to monitor resources in your private network or resources that are behind your firewall.
You can set up custom probes inside your network to monitor resources in your private network or resources that are behind your firewall.
To begin with you need to create a custom probe in your Project Settings > Probe. Once you have created the custom probe on your OneUptime Dashboard. You should have the `PROBE_ID` and `PROBE_KEY`
### Deploy Probe
### Run the probe
#### Docker
To run a probe, please make sure you have docker installed. You can run custom probe by:
To run a probe, please make sure you have docker installed. You can run custom probe by:
```
docker run --name oneuptime-probe --network host -e PROBE_KEY=<probe-key> -e PROBE_ID=<probe-id> -e ONEUPTIME_URL=https://oneuptime.com -d oneuptime/probe:release
```
If you are self hosting OneUptime, you can change `INGESTOR_URL` to your custom self hosted instance.
If you are self hosting OneUptime, you can change `ONEUPTIME_URL` to your custom self hosted instance.
### Verify
#### Docker Compose
You can also run the probe using docker-compose. Create a `docker-compose.yml` file with the following content:
```yaml
version: "3"
services:
oneuptime-probe:
image: oneuptime/probe:release
container_name: oneuptime-probe
environment:
- PROBE_KEY=<probe-key>
- PROBE_ID=<probe-id>
- ONEUPTIME_URL=https://oneuptime.com
network_mode: host
restart: always
```
Then run the following command:
```
docker-compose up -d
```
If you are self hosting OneUptime, you can change `ONEUPTIME_URL` to your custom self hosted instance.
#### Kubernetes
You can also run the probe using Kubernetes. Create a `oneuptime-probe.yaml` file with the following content:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: oneuptime-probe
spec:
selector:
matchLabels:
app: oneuptime-probe
template:
metadata:
labels:
app: oneuptime-probe
spec:
containers:
image: oneuptime/probe:release
env:
- name: PROBE_KEY
value: "<probe-key>"
- name: PROBE_ID
value: "<probe-id>"
- name: ONEUPTIME_URL
value: "https://oneuptime.com"
```
Then run the following command:
```bash
kubectl apply -f oneuptime-probe.yaml
```
If you are self hosting OneUptime, you can change `ONEUPTIME_URL` to your custom self hosted instance.
### Verify
If the probe is running successfully. It should show as `Connected` on your OneUptime dashboard. If it does not show as connected. You need to check logs of the container. If you're still having trouble. Please create an issue on [GitHub](https://github.com/oneuptime/oneuptime) or [contact support](https://oneuptime.com/support)

View file

@ -5,6 +5,10 @@ type GetStringFunction = () => string;
type GetStringOrNullFunction = () => string | null;
type GetURLFunction = () => URL;
export const GetIsCopilotDisabled: () => boolean = () => {
return process.env["DISABLE_COPILOT"] === "true";
}
export const GetOneUptimeURL: GetURLFunction = () => {
return URL.fromString(
process.env["ONEUPTIME_URL"] || "https://oneuptime.com",

View file

@ -11,7 +11,7 @@ import logger from "CommonServer/Utils/Logger";
import CopilotActionUtil from "./Utils/CopilotAction";
import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
import CopilotAction from "Model/Models/CopilotAction";
import { FixNumberOfCodeEventsInEachRun } from "./Config";
import { FixNumberOfCodeEventsInEachRun, GetIsCopilotDisabled } from "./Config";
import CopiotActionTypeOrder from "./Types/CopilotActionTypeOrder";
import CopilotActionService, {
CopilotExecutionResult,
@ -25,6 +25,13 @@ import CopilotActionProcessingException from "./Exceptions/CopilotActionProcessi
let currentFixCount: number = 1;
const init: PromiseVoidFunction = async (): Promise<void> => {
// check if copilot is disabled.
if(GetIsCopilotDisabled()) {
logger.info("Copilot is disabled. Exiting.");
haltProcessWithSuccess();
}
await CodeRepositoryUtil.setAuthorIdentity({
email: "copilot@oneuptime.com",
name: "OneUptime Copilot",
@ -170,6 +177,7 @@ const init: PromiseVoidFunction = async (): Promise<void> => {
} catch (e) {
logger.error(e);
currentRetryCount++;
CodeRepositoryUtil.discardAllChangesOnCurrentBranch();
}
}

View file

@ -185,6 +185,11 @@ If you have any feedback or suggestions, please let us know. We would love to h
isActionComplete = await this.isActionComplete(data);
}
data = await this.onAfterExecute(data);
// write to disk.
await this.writeToDisk({ data });
const onAfterExecuteActionScript: string | null =
await CodeRepositoryUtil.getRepoScript({
scriptType: RepoScriptType.OnAfterCopilotAction,
@ -204,7 +209,7 @@ If you have any feedback or suggestions, please let us know. We would love to h
logger.info("on-after-copilot-action script executed successfully");
}
return await this.onAfterExecute(data);
return data;
}
protected async _getPrompt(
@ -240,6 +245,30 @@ If you have any feedback or suggestions, please let us know. We would love to h
return data.input.files[data.input.currentFilePath]?.fileContent as string;
}
public async writeToDisk(data: { data: CopilotProcess }): Promise<void> {
// write all the modified files.
const processResult: CopilotProcess = data.data;
for (const filePath in processResult.result.files) {
const fileCommitHash: string =
processResult.result.files[filePath]!.gitCommitHash;
logger.info(`Writing file: ${filePath} ${fileCommitHash}`);
const code: string = processResult.result.files[filePath]!.fileContent;
await CodeRepositoryUtil.writeToFile({
filePath: filePath,
content: code,
});
}
}
public async discardAllChanges(): Promise<void> {
await CodeRepositoryUtil.discardAllChangesOnCurrentBranch();
}
public async splitInputCode(data: {
copilotProcess: CopilotProcess;
itemSize: number;

View file

@ -94,24 +94,8 @@ export default class CopilotActionService {
});
// write all the modified files.
const filePaths: string[] = Object.keys(processResult.result.files);
for (const filePath in processResult.result.files) {
const fileCommitHash: string =
processResult.result.files[filePath]!.gitCommitHash;
logger.info(`Writing file: ${filePath}`);
logger.info(`Commit Hash: ${fileCommitHash}`);
const code: string = processResult.result.files[filePath]!.fileContent;
await CodeRepositoryUtil.writeToFile({
filePath: filePath,
content: code,
});
}
// run on before commit script. This is the place where we can run tests.
const onBeforeCommitScript: string | null =

View file

@ -375,6 +375,7 @@ services:
CODE_REPOSITORY_PASSWORD: ${COPILOT_CODE_REPOSITORY_PASSWORD}
CODE_REPOSITORY_USERNAME: ${COPILOT_CODE_REPOSITORY_USERNAME}
ONEUPTIME_LLAMA_SERVER_URL: ${COPILOT_ONEUPTIME_LLAMA_SERVER_URL}
DISABLE_COPILOT: ${DISABLE_COPILOT}
logging:
driver: "local"
options:

View file

@ -1,31 +0,0 @@
services:
copilot:
volumes:
- ./Copilot:/usr/src/app
# Use node modules of the container and not host system.
# https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder
- /usr/src/app/node_modules/
- ./Common:/usr/src/Common
- ./Model:/usr/src/Model
- ./CommonServer:/usr/src/CommonServer
- ./CommonUI:/usr/src/CommonUI
- /usr/src/Common/node_modules/
- /usr/src/CommonUI/node_modules/
- /usr/src/CommonServer/node_modules/
- /usr/src/Model/node_modules/
ports:
- '9985:9229' # Debugging port.
extends:
file: ./docker-compose.base.yml
service: copilot
environment:
- LOG_LEVEL=INFO
build:
network: host
context: .
dockerfile: ./Copilot/Dockerfile
networks:
oneuptime:
driver: bridge

View file

@ -337,6 +337,32 @@ services:
context: .
dockerfile: ./E2E/Dockerfile
copilot:
volumes:
- ./Copilot:/usr/src/app
# Use node modules of the container and not host system.
# https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder
- /usr/src/app/node_modules/
- ./Common:/usr/src/Common
- ./Model:/usr/src/Model
- ./CommonServer:/usr/src/CommonServer
- ./CommonUI:/usr/src/CommonUI
- /usr/src/Common/node_modules/
- /usr/src/CommonUI/node_modules/
- /usr/src/CommonServer/node_modules/
- /usr/src/Model/node_modules/
ports:
- '9985:9229' # Debugging port.
extends:
file: ./docker-compose.base.yml
service: copilot
environment:
- LOG_LEVEL=INFO
build:
network: host
context: .
dockerfile: ./Copilot/Dockerfile
volumes:
postgres:
clickhouse:

View file

@ -46,10 +46,6 @@
"start-llm": "npm run prerun && export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.llm.yml up --remove-orphans -d $npm_config_services",
"build-llm": "npm run prerun && export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.llm.yml build $npm_config_services",
"force-build-llm": "npm run prerun && export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.llm.yml build --no-cache $npm_config_services",
"dev-copilot": "npm run prerun && export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.copilot.yml up --remove-orphans -d $npm_config_services",
"start-copilot": "npm run prerun && export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.copilot.yml up --remove-orphans -d $npm_config_services",
"build-copilot": "npm run prerun && export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.copilot.yml build $npm_config_services",
"force-build-copilot": "npm run prerun && export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.copilot.yml build --no-cache $npm_config_services",
"ps": "export $(grep -v '^#' config.env | xargs) && docker compose ps",
"save-logs": "export $(grep -v '^#' config.env | xargs) && docker compose logs --tail=100000 $npm_config_services > logs.txt",
"logs": "export $(grep -v '^#' config.env | xargs) && docker compose logs --tail=100 -f $npm_config_services",