From 6b9e0c8b997b4a19d752b0bd4806c43facb47385 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Wed, 10 Jul 2024 13:39:35 +0100 Subject: [PATCH] chore: Disable Copilot in development environment --- .bash_profile | 6 -- .../Docs/Content/probe/custom-probe.md | 76 +++++++++++++++++-- Copilot/Config.ts | 4 + Copilot/Init.ts | 10 ++- .../CopilotActions/CopilotActionsBase.ts | 31 +++++++- Copilot/Service/CopilotActions/Index.ts | 16 ---- docker-compose.base.yml | 1 + docker-compose.copilot.yml | 31 -------- docker-compose.dev.yml | 26 +++++++ package.json | 4 - 10 files changed, 141 insertions(+), 64 deletions(-) delete mode 100644 docker-compose.copilot.yml diff --git a/.bash_profile b/.bash_profile index e490375960..b6362ca32a 100644 --- a/.bash_profile +++ b/.bash_profile @@ -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" diff --git a/App/FeatureSet/Docs/Content/probe/custom-probe.md b/App/FeatureSet/Docs/Content/probe/custom-probe.md index 6000f04c84..d84518a6f4 100644 --- a/App/FeatureSet/Docs/Content/probe/custom-probe.md +++ b/App/FeatureSet/Docs/Content/probe/custom-probe.md @@ -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= -e 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_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: "" + - name: PROBE_ID + value: "" + - 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) \ No newline at end of file diff --git a/Copilot/Config.ts b/Copilot/Config.ts index 9422b778c6..080b2719b9 100644 --- a/Copilot/Config.ts +++ b/Copilot/Config.ts @@ -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", diff --git a/Copilot/Init.ts b/Copilot/Init.ts index 12145cd213..df6d0bee47 100644 --- a/Copilot/Init.ts +++ b/Copilot/Init.ts @@ -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 => { + + // 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 => { } catch (e) { logger.error(e); currentRetryCount++; + CodeRepositoryUtil.discardAllChangesOnCurrentBranch(); } } diff --git a/Copilot/Service/CopilotActions/CopilotActionsBase.ts b/Copilot/Service/CopilotActions/CopilotActionsBase.ts index d7e703414d..df9fefc5aa 100644 --- a/Copilot/Service/CopilotActions/CopilotActionsBase.ts +++ b/Copilot/Service/CopilotActions/CopilotActionsBase.ts @@ -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 { + // 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 { + await CodeRepositoryUtil.discardAllChangesOnCurrentBranch(); + } + public async splitInputCode(data: { copilotProcess: CopilotProcess; itemSize: number; diff --git a/Copilot/Service/CopilotActions/Index.ts b/Copilot/Service/CopilotActions/Index.ts index aa8cc79f3a..c55accd09d 100644 --- a/Copilot/Service/CopilotActions/Index.ts +++ b/Copilot/Service/CopilotActions/Index.ts @@ -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 = diff --git a/docker-compose.base.yml b/docker-compose.base.yml index 882e7b01b1..0c0cf4fbb1 100644 --- a/docker-compose.base.yml +++ b/docker-compose.base.yml @@ -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: diff --git a/docker-compose.copilot.yml b/docker-compose.copilot.yml deleted file mode 100644 index c3269efeca..0000000000 --- a/docker-compose.copilot.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 883410dcd1..ea3d8560e1 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -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: diff --git a/package.json b/package.json index ca34ec63ed..6422ada740 100644 --- a/package.json +++ b/package.json @@ -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",