Skip to content

Commit

Permalink
Chore: added heartbeat for monitoring (#36704)
Browse files Browse the repository at this point in the history
## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._

EE conflist resolve fix -
appsmithorg/appsmith-ee#5291
Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11211380166>
> Commit: 3aea136
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11211380166&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Mon, 07 Oct 2024 09:21:06 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a `Heartbeat` component for periodic monitoring, sending
signals every 30 seconds.
- Enhanced application monitoring capabilities by conditionally
rendering the `Heartbeat` component in production environments.

- **Bug Fixes**
	- Improved New Relic configuration for better telemetry and monitoring.

- **Documentation**
- Updated comments and documentation to reflect the new functionality
and configuration changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
ApekshaBhosale authored Oct 9, 2024
1 parent 71963b5 commit 2cb50e9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 34 additions & 0 deletions app/client/src/Heartbeat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useEffect } from "react";
import log from "loglevel";
const Heartbeat = () => {
const heartbeatUrl =
"https://uptime.betterstack.com/api/v1/heartbeat/71SZmsvAVW73QvEPQzLvxwEL";
const interval = 30 * 1000; // 30 secs in milliseconds

const sendHeartbeat = async () => {
try {
const response = await fetch(heartbeatUrl);

if (response.ok) {
log.info("Heartbeat sent successfully");
} else {
log.error("Failed to send heartbeat", response.status);
}
} catch (error) {
log.error("Error sending heartbeat:", error);
}
};

useEffect(() => {
const heartbeatInterval = setInterval(() => {
sendHeartbeat();
}, interval);

// Cleanup the interval when the component is unmounted
return () => clearInterval(heartbeatInterval);
}, []); // Empty dependency array ensures this runs once on mount

return null; // This component doesn't render anything
};

export default Heartbeat;
7 changes: 6 additions & 1 deletion app/client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { PageViewTiming } from "@newrelic/browser-agent/features/page_view_timin
import { PageViewEvent } from "@newrelic/browser-agent/features/page_view_event";
import { Agent } from "@newrelic/browser-agent/loaders/agent";
import { getCommonTelemetryAttributes } from "UITelemetry/generateTraces";

import Heartbeat from "Heartbeat";
const { newRelic } = getAppsmithConfigs();
const { enableNewRelic } = newRelic;

Expand Down Expand Up @@ -73,8 +73,12 @@ if (enableNewRelic) {
newRelicBrowserAgent.setCustomAttribute("appMode", appMode);
}

const { cloudHosting } = getAppsmithConfigs();

const shouldAutoFreeze = process.env.NODE_ENV === "development";

const isProduction = process.env.NODE_ENV === "production";

setAutoFreeze(shouldAutoFreeze);
runSagaMiddleware();

Expand All @@ -96,6 +100,7 @@ function App() {
<Sentry.ErrorBoundary fallback={"An error has occured"}>
<Provider store={store}>
<LayersContext.Provider value={Layers}>
{cloudHosting && isProduction && <Heartbeat />}
<ThemedAppWithProps />
</LayersContext.Provider>
</Provider>
Expand Down

0 comments on commit 2cb50e9

Please sign in to comment.