<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by TarunTeja on Medium]]></title>
        <description><![CDATA[Stories by TarunTeja on Medium]]></description>
        <link>https://medium.com/@tarunteja417?source=rss-af508bfdafca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yoIOOBFs82n0-CHNtkLdbw@2x.jpeg</url>
            <title>Stories by TarunTeja on Medium</title>
            <link>https://medium.com/@tarunteja417?source=rss-af508bfdafca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:28:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tarunteja417/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Real-Time Slow Query Alerts Across AWS RDS to Slack]]></title>
            <link>https://medium.com/@tarunteja417/real-time-slow-query-alerts-across-aws-rds-to-slack-39dd231d361c?source=rss-af508bfdafca------2</link>
            <guid isPermaLink="false">https://medium.com/p/39dd231d361c</guid>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[slowquery]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[TarunTeja]]></dc:creator>
            <pubDate>Wed, 05 Nov 2025 21:47:49 GMT</pubDate>
            <atom:updated>2025-11-05T21:47:49.811Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RaXcfzIpeV8SIBmpCBwxhw.png" /></figure><p>Managing multiple AWS RDS MySQL instances can quickly become overwhelming, especially when trying to maintain high application performance. Slow queries, high row scans, or killed queries often go unnoticed until they impact your users — but they don’t have to.</p><p>In this post, I’ll show you how to implement an automated system that alerts your team in real-time via Slack whenever a query exceeds your performance thresholds.</p><h3>Why You Need This</h3><p><strong>The problem:</strong></p><p>When you operate multiple RDS instances, keeping track of slow queries manually is impossible. Queries that take too long or scan too many rows can slow down your application, but without automated monitoring, these issues often remain hidden until it’s too late.</p><p><strong>The goal:</strong></p><ul><li>Detect slow queries in real-time</li><li>Centralize alerts in Slack for immediate team visibility</li><li>Scale effortlessly across multiple RDS instances</li><li>Keep costs low using existing AWS services</li><li>Provide actionable details for quick troubleshooting</li></ul><h3>How It Works: Architecture Overview</h3><p>Here’s the high-level flow of our solution:</p><pre>Application -&gt; RDS MySQL -&gt; Slow Query Log -&gt; CloudWatch Logs -&gt; Lambda -&gt; Slack</pre><ol><li><strong>Query execution:</strong> Your app runs SQL queries on MySQL.</li><li><strong>Slow query detection:</strong> MySQL logs queries exceeding long_query_time.</li><li><strong>Log generation:</strong> Slow queries are written to MySQL slow query log.</li><li><strong>CloudWatch Logs export:</strong> RDS exports logs to CloudWatch automatically.</li><li><strong>Trigger:</strong> CloudWatch subscription filters send new log events to Lambda.</li><li><strong>Processing:</strong> Lambda parses logs and extracts query details.</li><li><strong>Notification:</strong> Lambda posts a formatted message to your Slack channel.</li></ol><p>The result: your team gets real-time notifications of slow queries with execution time, rows examined, and query text — all without lifting a finger.</p><h3>Step 1: Configure RDS for Slow Query Logging</h3><p>Set these parameters in your RDS <strong>parameter group</strong>:</p><p>slow_query_log =1 (Enables slow query logging)</p><p>long_query_time=5 Log queries longer than 5 seconds</p><p>log_output=FILE Required for CloudWatch export</p><p>max_execution_time=60000 Kill queries that take more than 60 seconds</p><p>min_examined_row_limit=100000 After how many scan rows it should be considered for slow query</p><p>The long_query_time <strong>and</strong> min_examined_row_limit conditions must both be met for a query to be classified as a slow query - it’s an <strong>AND</strong>, not an OR, condition.To slow only based on long_query_time and without worry about row sacn , we can also set min_examined_row_limit to zero and we can just handle the row scanned in our lambda code.</p><p>MySQL’s log_queries_not_using_indexes logs every query that doesn’t use an index, even fast ones, which can quickly clutter your logs. To reduce noise, you can use log_throttle_queries_not_using_indexes, which limits how often such queries are logged. If you want to track queries based on how frequently they occur rather than just logging every instance, you’ll need to implement custom logic using log_queries_not_using_indexes. This approach lets you focus on recurring performance issues without being overwhelmed by one-off fast queries.</p><p>Enable <strong>CloudWatch Logs export</strong> via the RDS console or AWS CLI. Each database gets its own log group, e.g.:</p><pre>/aws/rds/instance/prod-db-1/slowquery<br>/aws/rds/instance/prod-db-2/slowquery</pre><h3>Step 2: Create a Lambda Function to Parse Logs</h3><p>We use a Lambda function to read CloudWatch logs and send alerts to Slack.</p><p>Lambda steps:</p><ol><li>Decode log events from CloudWatch</li><li>Parse slow query details (execution time, rows scanned, SQL text)</li><li>Format message</li><li>Send to Slack</li></ol><p><strong>IAM Permissions</strong> needed for Lambda:</p><pre>{<br>  &quot;Effect&quot;: &quot;Allow&quot;,<br>  &quot;Action&quot;: [<br>    &quot;logs:CreateLogGroup&quot;,<br>    &quot;logs:CreateLogStream&quot;,<br>    &quot;logs:PutLogEvents&quot;<br>  ],<br>  &quot;Resource&quot;: &quot;*&quot;<br>}</pre><p><strong>Lambda invocation from CloudWatch Logs:</strong> add a resource-based policy allowing the log group to invoke your function.</p><h3>Step 3: Connect CloudWatch Logs to Lambda</h3><p>For each database:</p><ol><li>Add Lambda permission:</li></ol><pre>aws lambda add-permission \<br>  --function-name slow-query-slack-alert \<br>  --statement-id AllowCloudWatchLogs-prod-db-1 \<br>  --action &quot;lambda:InvokeFunction&quot; \<br>  --principal logs.amazonaws.com \<br>  --source-arn &quot;arn:aws:logs:region:account-id:log-group:/aws/rds/instance/prod-db-1/slowquery:*&quot;</pre><ol><li>Create a subscription filter:</li></ol><pre>aws logs put-subscription-filter \<br>  --log-group-name &quot;/aws/rds/instance/prod-db-1/slowquery&quot; \<br>  --filter-name &quot;slow-query-to-slack-prod-db-1&quot; \<br>  --filter-pattern &quot;&quot; \<br>  --destination-arn &quot;arn:aws:lambda:region:account-id:function:slow-query-slack-alert&quot;</pre><p>Now, any slow query log entry triggers a Lambda function that alerts your team in Slack.</p><h3>Step 4: Tuning and Cost Optimization</h3><p><strong>Adjustable Parameters:</strong></p><ul><li>long_query_time: Increase to reduce alert volume</li><li>log retention: Set retention to 3 days for cost control</li></ul><p><strong>Estimated cost for 10 RDS instances:</strong></p><p>ServiceEstimated Monthly CostCloudWatch Logs~$0.05Lambda Invocations~$0.20Total~$0.25</p><p>This approach is extremely cost-effective while giving you centralized, real-time monitoring.</p><h3>Benefits</h3><ul><li><strong>Immediate visibility:</strong> Alerts delivered within seconds</li><li><strong>Scalable:</strong> Works for any number of RDS instances</li><li><strong>Actionable info:</strong> Execution time, rows scanned, and SQL query</li><li><strong>Minimal setup:</strong> One-time Lambda and CloudWatch configuration</li></ul><h3>Sample screenshots</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*tNQiMi4Qis8rsy7mF-jS2Q.png" /><figcaption>Slow query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*ZmfklAs51VStMTN-O8nh5g.png" /><figcaption>Killed query alert</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*Z4JiAYpTc7z51x4cN4fWYw.png" /><figcaption>High row scan alert</figcaption></figure><h3>Conclusion</h3><p>Monitoring slow queries doesn’t need to be complicated or expensive. By leveraging RDS slow query logs, CloudWatch Logs, and Lambda, you can create a real-time alerting system that not only improves your database visibility but also ensures your team can respond to performance issues before they impact users.</p><p>This approach is scalable, cost-efficient, and centralized — everything a modern DevOps or SRE team needs to keep applications running smoothly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39dd231d361c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Alert Dispatcher — Intelligent Cloud Alert Routing to Slack for AWS & Grafana]]></title>
            <link>https://medium.com/@tarunteja417/introducing-alert-dispatcher-intelligent-cloud-alert-routing-to-slack-for-aws-grafana-4208cbd08a37?source=rss-af508bfdafca------2</link>
            <guid isPermaLink="false">https://medium.com/p/4208cbd08a37</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[slack]]></category>
            <dc:creator><![CDATA[TarunTeja]]></dc:creator>
            <pubDate>Sun, 02 Nov 2025 11:15:42 GMT</pubDate>
            <atom:updated>2025-11-02T11:15:42.723Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introducing Alert Dispatcher — Intelligent Cloud Alert Routing to Slack for AWS &amp; Grafana</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*RXZNJi_ICrsXhsoIk1KDmQ.png" /><figcaption>Alert Dispatcher Overview</figcaption></figure><p><strong>Tired of noisy alerts and missed incidents?</strong><br>Meet <strong>Alert Dispatcher</strong>, a Go-based microservice that intelligently processes alerts from <strong>AWS CloudWatch</strong> and <strong>Grafana</strong>, and routes them to the right <strong>Slack channels</strong> based on priority — so your team can focus on what truly matters.</p><p>👉 <strong>GitHub:</strong> <a href="https://github.com/LiciousTech/alert-dispatcher">LiciousTech/alert-dispatcher</a></p><h3>What is Alert Dispatcher?</h3><p><strong>Alert Dispatcher</strong> acts as the bridge between your <strong>monitoring systems</strong> (like AWS CloudWatch and Grafana) and your <strong>incident communication hub</strong> (Slack).<br> It continuously polls <strong>AWS SQS queues</strong> and listens to <strong>Grafana webhooks</strong>, intelligently classifying each alert, and sending <strong>interactive Slack notifications</strong> to the right channels — with <strong>acknowledge/dismiss buttons</strong> for real-time collaboration.</p><h3>Architecture Overview</h3><p>Here’s how it fits into your infrastructure:</p><pre>CloudWatch → SNS → SQS → Alert Dispatcher → Slack<br>Grafana  → Webhook → Alert Dispatcher → Slack</pre><p>And inside the service:</p><pre>SQS Poller + Webhook Server + Priority Router + Slack Notifier</pre><p>Each component works together to ensure your team gets timely, relevant, and actionable alerts — <strong>without being overwhelmed</strong>.</p><h3>Key Features</h3><ul><li><strong>AWS CloudWatch Integration:</strong><br>Processes SNS-wrapped CloudWatch alarms from SQS queues in real-time.</li><li><strong>Priority-Based Routing:</strong><br>Automatically classifies alerts into <strong>P0, P1, or P2</strong>, sending them to different Slack channels.<br> For example:</li></ul><p><strong>P0 (Critical):</strong> Critical alerts which can bring down production systems.</p><p><strong>P1 (Important):</strong> CPU/memory/traffic related issues which can be severe if not addressed.</p><p><strong>P2 (Normal):</strong> All other alarms</p><ul><li><strong>Interactive Slack Notifications:</strong><br> Each Slack message includes buttons like <strong>✅ Acknowledge</strong> and <strong>❌ Dismiss</strong>, making collaboration effortless.</li><li><strong>Grafana Support Out of the Box:</strong><br> Simply configure your Grafana webhook — no extra setup needed.</li><li><strong>Concurrent Processing:</strong><br> Runs the SQS poller and HTTP server concurrently for maximum efficiency.</li><li><strong>Secure by Design:</strong><br>Verifies request signatures for Slack interactivity, keeping your workflows safe.</li></ul><h3>Message Flow</h3><ol><li><strong>CloudWatch Alarm</strong> triggers → sends to SNS Topic</li><li><strong>SNS</strong> forwards message to <strong>SQS Queue</strong></li><li><strong>Alert Dispatcher</strong> polls SQS, processes the alert</li><li><strong>Priority Router</strong> determines its level (P0/P1/P2)</li><li><strong>Slack Notifier</strong> sends a formatted message to the correct channel</li><li><strong>Team</strong> acknowledges or dismisses directly in Slack</li></ol><p>Simple. Fast. Reliable.</p><h3>Components</h3><p><strong>SQS Poller: </strong>Continuously polls AWS SQS for messages</p><p><strong>Message Adapter: </strong>Parses CloudWatch or Grafana JSON alerts</p><p><strong>Priority Router: </strong>Determines alert severity</p><p><strong>Slack Notifier: </strong>Sends rich, interactive messages</p><p><strong>Webhook Server: </strong>Handles Grafana POST requests</p><p><strong>HTTP Server: </strong>Listens for Slack interactive responses</p><h3>Quick Start</h3><h3>Prerequisites</h3><ul><li>Go <strong>1.21+</strong></li><li>AWS account with <strong>SQS</strong> access</li><li>Slack Bot with proper permissions</li></ul><h3>Local Setup</h3><pre>git clone https://github.com/LiciousTech/alert-dispatcher.git<br>cd alert-dispatcher<br>go mod download</pre><p>Set your environment variables:</p><pre>export SQS_QUEUE_URL=&quot;https://sqs.&lt;region&gt;.amazonaws.com/123456789012/your-queue&quot;<br>export SLACK_BOT_TOKEN=&quot;xoxb-your-bot-token&quot;<br>export SLACK_SIGNING_SECRET=&quot;your-signing-secret&quot;<br>export SLACK_CHANNEL_P0=&quot;#p0-channel&quot;<br>export SLACK_CHANNEL_P1=&quot;#p1-channel&quot;<br>export SLACK_CHANNEL_P2=&quot;#p2-channel&quot;<br>export SERVER_PORT=&quot;8088&quot;</pre><p>Run it:</p><pre>go run main.go</pre><p>Check health:</p><pre>curl http://localhost:8088/health<br># OK</pre><h3>Example Slack Message</h3><pre>🚨 [ALARM] CloudWatch Alarm: ECR-PULL-COUNT-TESTING<br>• From: OK → ALARM<br>• Metric: AWS/ECR/RepositoryPullCount<br>• Threshold: &gt; 1.0<br>• Region: Asia Pacific (Mumbai)<br>• Reason: Threshold Crossed...<br>• Time: 2025-07-24 13:00:00 UTC</pre><pre>[✅ Acknowledge] [❌ Dismiss]</pre><p>Alerts are <strong>beautifully formatted</strong>, interactive, and easy to act upon.</p><p>Logs are structured, concise, and perfect for observability.</p><h3>Why Teams Love Alert Dispatcher</h3><p><strong>Cuts noise</strong> — Only critical alerts reach your P0 channel<br> <strong>Speeds response time</strong> — One-click acknowledge directly in Slack<br> <strong>Easy to deploy</strong> — Works seamlessly in any cloud-native setup<br> <strong>Flexible</strong> — Handles alerts from both AWS <strong>and Grafana</strong> via webhook support<br> <strong>Secure</strong> — Verifies Slack signatures for safe interactivity<br> <strong>Open Source</strong> — Fully transparent and community-driven<br> <strong>Grafana-ready</strong> — Just update your Grafana contact point to point to the Alert Dispatcher service, and your alerts will flow instantly — no extra configuration needed</p><h3>Get Started Today</h3><p>Bring clarity to your cloud alerts.<br>Make your Slack a command center, not a noise feed.</p><p>👉 <strong>Try it now:</strong> <a href="https://github.com/LiciousTech/alert-dispatcher">github.com/LiciousTech/alert-dispatcher</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4208cbd08a37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Endpoint-Monitoring Operator: Custom operator for Observability That Actually Understands Your…]]></title>
            <link>https://medium.com/@tarunteja417/endpoint-monitoring-operator-custom-operator-for-observability-that-actually-understands-your-5bfe53f85376?source=rss-af508bfdafca------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bfe53f85376</guid>
            <category><![CDATA[kubernetes-operator]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[kubernetes-open-source]]></category>
            <dc:creator><![CDATA[TarunTeja]]></dc:creator>
            <pubDate>Sun, 02 Nov 2025 09:00:02 GMT</pubDate>
            <atom:updated>2025-11-02T09:00:02.132Z</atom:updated>
            <content:encoded><![CDATA[<h3>Endpoint-Monitoring Operator: Custom operator for Observability That Actually Understands Your Systems</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUPtCS6EVxdIG9L26USP4Q.png" /><figcaption>Endpoint Monitoring Operator</figcaption></figure><p><strong>GitHub Repo:</strong> <a href="https://github.com/LiciousTech/endpoint-monitoring-operator">LiciousTech/endpoint-monitoring-operator</a></p><h3>TL;DR</h3><p>Forget black-box uptime checkers.<br><strong>Endpoint-Monitoring Operator</strong> is a lightweight, extensible Kubernetes Operator that runs <em>inside your cluster</em> to probe endpoints, validate JSON, ping databases, and send alerts directly to Slack, Email, or Discord all powered by a clean, pluggable design.</p><h3>The Problem With Traditional Monitoring</h3><p>Most uptime checkers only care if a port is open or an endpoint responds with 200 OK.</p><p>That’s fine for a basic website — but modern Kubernetes environments aren’t basic.<br> You have:</p><ul><li>Microservices with internal /v1/status health endpoints</li><li>APIs that return structured JSON health info</li><li>Distributed systems like <strong>Trino</strong>, <strong>OpenSearch</strong>, and <strong>Kafka</strong></li><li>Private services that are not publicly reachable</li></ul><p>External tools can’t see or understand these.<br><strong>Endpoint-Monitoring Operator</strong> fixes that by living <em>where your workloads live — </em><strong>inside the cluster.</strong></p><h3>What It Does</h3><p><strong>Endpoint-Monitoring Operator</strong> continuously probes any endpoint you define from HTTP to TCP to DNS using a Kubernetes Custom Resource Definition (CRD).</p><p>It can:</p><ul><li>Validate <strong>JSON payloads</strong> and specific fields</li><li>Monitor <strong>TCP ports</strong>, <strong>DNS resolution</strong>, or <strong>ICMP reachability</strong></li><li>Check <strong>Trino coordinator readiness</strong> and <strong>OpenSearch cluster health</strong></li><li>Send rich alerts via <strong>Slack</strong>, <strong>Email</strong>, or <strong>Discord</strong></li></ul><p>In essence: it’s an in-cluster, declarative, multi-protocol health checker.</p><h3>Supported Drivers</h3><p>DriverWhat It CheckshttpBasic HTTP status codes (200/302/…)http-jsonStatus codes + JSON field validationtcpService listening on portdnsDomain resolves to expected IP(s)pingICMP reachabilitytrinoTrino coordinator is READYopensearchOpenSearch cluster health (green/yellow)</p><p>Want to add Redis or MySQL next? It’s just a few lines of Go — thanks to a factory-based driver system.</p><h3>Example: Deep JSON Health Check</h3><pre>apiVersion: monitoring.licious.app/v1alpha1<br>kind: EndpointMonitor<br>metadata:<br>  name: api-health-check<br>spec:<br>  driver: http-json<br>  endpoint: https://api.example.com/v1/status<br>  checkInterval: 30<br>  httpJsonCheck:<br>    expectedStatusCode: 200<br>    jsonAssertions:<br>      status: &quot;UP&quot;<br>      version: &quot;v1.2.3&quot;<br>  notify:<br>    slack:<br>      enabled: true<br>      webhookUrl: https://hooks.slack.com/services/XXX/YYY/ZZZ<br>      alertOn:<br>        - failure</pre><p>You can target private endpoints that external tools can’t reach, validate real data, and get alerts where your team actually works.</p><h3>Under the Hood: Factory-Driven Architecture</h3><p>The magic lies in two clean abstractions:</p><h3>1. DriverFactory</h3><p>Creates the right driver (HTTP, TCP, DNS, etc.) dynamically.</p><pre>switch driverType {<br>case &quot;http&quot;:<br>    return driver.NewHTTPDriver(endpoint)<br>case &quot;http-json&quot;:<br>    return driver.NewHTTPJSONDriver(endpoint, monitor.Spec.HttpJsonCheck)<br>case &quot;tcp&quot;:<br>    return driver.NewTCPDriver(endpoint)<br>case &quot;dns&quot;:<br>    return driver.NewDNSDriver(endpoint)<br>case &quot;ping&quot;:<br>    return driver.NewPingDriver(endpoint)<br>case &quot;trino&quot;:<br>    return driver.NewTrinoDriver(endpoint)<br>case &quot;opensearch&quot;:<br>    return driver.NewOpenSearchDriver(endpoint)<br>default:<br>    return nil, fmt.Errorf(&quot;unsupported driver type: %s&quot;, driverType)<br>}</pre><p>Adding a new driver is as simple as implementing the Driver interface and registering it here.</p><h3>2. NotifierFactory</h3><p>Creates notifiers (Slack, Email, Discord) and combines them into a <strong>CompositeNotifier</strong> — so one failure alert can fan out to multiple channels at once.</p><pre>if config.Slack != nil &amp;&amp; config.Slack.Enabled {<br>    slackNotifier, _ := slack.New(config.Slack)<br>    notifiers = append(notifiers, slackNotifier)<br>}<br>if config.Email != nil &amp;&amp; config.Email.Enabled {<br>    emailNotifier, _ := email.New(config.Email)<br>    notifiers = append(notifiers, emailNotifier)<br>}<br>if config.Discord != nil &amp;&amp; config.Discord.Enabled {<br>    discordNotifier, _ := discord.New(config.Discord)<br>    notifiers = append(notifiers, discordNotifier)<br>}<br>return &amp;CompositeNotifier{notifiers: notifiers}, nil</pre><h3>Supported Notifiers (as of today)</h3><p><strong>Slack: </strong>Sends rich message alerts with probe results</p><p><strong>Discord: </strong>Sends structured alert messages to Discord channels</p><p>All notifiers live under internal/notifier/:</p><pre>notifier/<br> ├─ slack/<br> ├─ email/<br> ├─ discord/<br> └─ notifier.go</pre><p>Each follows a simple contract — SendAlert(status, message string) error — so they’re interchangeable and composable.</p><h3>Quick Start</h3><p>Install the operator into any cluster:</p><pre>kubectl apply -f https://raw.githubusercontent.com/LiciousTech/endpoint-monitoring-operator/main/dist/install.yaml</pre><h3>Example 1: Monitor DNS resolution</h3><pre>kubectl apply -f examples/dns.yaml</pre><h3>Example 2: Validate JSON health of a service</h3><pre>kubectl apply -f examples/http-json.yaml</pre><p>Alerts will start appearing in Slack (or Discord) based on your configuration.</p><h3>Roadmap</h3><p>Here’s what’s coming next:</p><ul><li><strong>New Notifiers:</strong> Email, PagerDuty, OpsGenie, Webhook</li><li><strong>Prometheus Metrics Export:</strong> expose probe metrics</li><li><strong>Synthetic Transactions:</strong> multi-step checks (login → query → checkout)</li><li><strong>New Drivers:</strong> Redis, MySQL, Kafka</li></ul><p><strong>If it speaks TCP or HTTP, it can (and will) be monitored.</strong></p><h3>Contributing</h3><p>We love clean Go code and contributors.<br> To start:</p><pre>git clone https://github.com/LiciousTech/endpoint-monitoring-operator.git</pre><p>Then open a PR! See <a href="https://github.com/LiciousTech/endpoint-monitoring-operator/blob/main/CONTRIBUTING.md">CONTRIBUTING.md</a> for details.</p><h3>Why It Matters</h3><p>Kubernetes operators are great at managing workloads — <br><strong>Endpoint-Monitoring Operator</strong> takes that same declarative model and applies it to <em>observability</em>.</p><p>By defining monitoring as YAML (not dashboards or scripts), teams can:</p><ul><li>Version control their health checks</li><li>Use GitOps to deploy monitors</li><li>Test locally before production rollout</li><li>Keep monitoring logic <em>close to the workload</em></li></ul><p>This isn’t just uptime — it’s <strong>context-aware, in-cluster observability</strong>.</p><h3>Try It Now</h3><p>👉 <strong>GitHub:</strong> <a href="https://github.com/LiciousTech/endpoint-monitoring-operator">LiciousTech/endpoint-monitoring-operator</a><br>👉 <strong>Install in one command:</strong></p><pre>kubectl apply -f https://raw.githubusercontent.com/LiciousTech/endpoint-monitoring-operator/main/dist/install.yaml</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bfe53f85376" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Intelligent Trino Gateway: Automatic Load Balancing, External Routing, and Smart Query…]]></title>
            <link>https://medium.com/@tarunteja417/building-an-intelligent-trino-gateway-automatic-load-balancing-external-routing-and-smart-query-c60821703036?source=rss-af508bfdafca------2</link>
            <guid isPermaLink="false">https://medium.com/p/c60821703036</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[gateway]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[TarunTeja]]></dc:creator>
            <pubDate>Sun, 02 Nov 2025 08:21:28 GMT</pubDate>
            <atom:updated>2025-11-02T08:21:28.362Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an Intelligent Trino Gateway: Automatic Load Balancing, External Routing, and Smart Query Distribution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*c-ScFxhH0czQCG73eVrXVA.png" /><figcaption>Trino gateway high level architecture</figcaption></figure><p>Modern analytics infrastructures rarely rely on a single Trino cluster.<br>As teams scale, they deploy <strong>multiple Trino clusters </strong>for high availability, resource isolation, and workload segmentation. But managing these clusters efficiently requires something more than manual routing.</p><p>That’s where the <strong>Trino Gateway</strong> comes in — an intelligent control plane that can <strong>load balance, route, and monitor</strong> multiple clusters seamlessly.</p><p>In this post, we’ll explore how to:</p><ul><li>Automatically <strong>load balance queries</strong> across multiple clusters</li><li>Integrate an <strong>external routing API</strong> for dynamic decisions</li><li>Configure <strong>routing rules</strong> and <strong>groups</strong></li><li>Register new clusters and groups in the Gateway</li></ul><p>Let’s get started.</p><h3>What Is Trino Gateway?</h3><p>Trino Gateway acts as a <strong>traffic manager</strong> sitting between your clients and multiple Trino clusters.</p><pre>Client → Trino Gateway → Cluster A<br>                     ↳ Cluster B<br>                     ↳ Cluster C</pre><p>It decides which cluster should handle each query based on configuration, routing logic, or external signals. This helps you achieve:</p><ul><li>Automatic <strong>query distribution</strong> (load balancing)</li><li><strong>Failover</strong> when clusters go down</li><li><strong>Routing control</strong> based on user, query type, or workload</li></ul><h3>Setting Up Automatic Load Balancing</h3><p>The simplest and most effective way to load balance Trino queries is by using Trino Gateway’s built-in <strong>QueryCountBasedRouterProvider</strong> module.<br>It automatically routes new queries to the <strong>least loaded cluster</strong> — based on active query counts.</p><p>Here’s an example config.yaml setup:</p><pre>clusterStatsConfiguration:<br>  monitorType: INFO_API   # Collect cluster stats using /v1/info endpoint</pre><pre>dataStore:<br>  driver: org.postgresql.Driver<br>  jdbcUrl: jdbc:postgresql://postgres-host:5432/trino_gateway<br>  user: root<br>  password: samplepassword</pre><pre>managedApps:<br>  - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor</pre><pre>modules:<br>  - io.trino.gateway.ha.module.HaGatewayProviderModule<br>  - io.trino.gateway.ha.module.ClusterStateListenerModule<br>  - io.trino.gateway.ha.module.ClusterStatsMonitorModule<br>  <strong>- io.trino.gateway.ha.module.QueryCountBasedRouterProvider</strong></pre><pre>monitor:<br>  taskDelaySeconds: 60   # Check cluster stats every 60 seconds</pre><pre>serverConfig:<br>  http-server.http.port: 8888<br>  http-server.process-forwarded: true<br>  node.environment: production</pre><pre>requestAnalyzerConfig:<br>  analyzeRequest: true<br>  maxBodySize: 1000000</pre><h3>How It Works</h3><ol><li><strong>Cluster monitoring: </strong>the Gateway polls each Trino cluster’s /v1/info API.</li><li><strong>Metrics storage: </strong>all cluster info (active queries, state) is stored in PostgreSQL.</li><li><strong>Smart routing:</strong>QueryCountBasedRouterProvider picks the cluster with the fewest active queries.</li><li><strong>Health awareness</strong> — unhealthy clusters are automatically excluded until recovery.</li></ol><h3>Registering Clusters in the Gateway</h3><p>Once the Gateway is running, register each Trino cluster under a <strong>routing group</strong>.</p><pre>curl -X POST http://&lt;gateway-host&gt;:8080/gateway/cluster/add \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{<br>        &quot;name&quot;: &quot;trino-prod-1&quot;,<br>        &quot;proxyTo&quot;: &quot;http://trino-prod-1:8080&quot;,<br>        &quot;active&quot;: true,<br>        &quot;routingGroup&quot;: &quot;adhoc&quot;<br>      }&#39;</pre><p>You can register multiple clusters under the same group for automatic balancing.</p><p>To verify:</p><pre>curl http://&lt;gateway-host&gt;:8080/gateway/cluster</pre><p>You’ll see each cluster’s <strong>active query count</strong>, <strong>health</strong>, and <strong>group</strong>.</p><h3>Smart Routing Rules</h3><p>Beyond simple balancing, Trino Gateway supports <strong>routing rules</strong> — logic that determines which routing group a query should go to.</p><p>You can:</p><ul><li>Route based on <strong>headers</strong> (e.g., X-Trino-Source)</li><li>Use <strong>custom MVEL conditions</strong></li><li>Or integrate an <strong>external routing service</strong> via API</li></ul><h3>Example Routing Config</h3><pre>routing:<br>  defaultRoutingGroup: &quot;adhoc&quot;</pre><pre>routingRules:<br>  rulesEngineEnabled: true<br>  <strong>rulesType: EXTERNAL </strong>  # or FILE for static rules<br>  rulesExternalConfiguration:<br>    urlPath: <a href="https://router.example.com/gateway-rules">https://router.example.com/gateway-rules</a><br>    excludeHeaders:<br>      - &#39;Authorization&#39;<br>    propagateErrors: false</pre><h3>Using an External Service for Routing</h3><p>When rulesType: EXTERNAL is enabled, the Gateway sends a <strong>POST request</strong> to your external routing service for every new query.</p><p><strong>Example request (from Gateway):</strong></p><pre>{<br>  &quot;X-Trino-User&quot;: &quot;analyst1&quot;,<br>  &quot;X-Trino-Source&quot;: &quot;airflow&quot;,<br>  &quot;trinoQueryProperties&quot;: {<br>    &quot;queryType&quot;: &quot;SELECT&quot;,<br>    &quot;catalogs&quot;: [&quot;hive&quot;]<br>  }<br>}</pre><p>Your external service analyzes metadata (user, tags, query type) and responds:</p><p><strong>Example response (from external router):</strong></p><pre>{<br>  &quot;routingGroup&quot;: &quot;etl&quot;,<br>  &quot;externalHeaders&quot;: {<br>    &quot;x-trino-session&quot;: &quot;query_max_memory=20GB&quot;<br>  }<br>}</pre><p>The Gateway now forwards the query to a cluster in the etl routing group.<br>If multiple clusters exist, it picks the least loaded one automatically.</p><p>This approach allows you to plug in <strong>real-time business logic </strong>for example, route queries <strong>based on user tiers, query type</strong>, or external load metrics.</p><h3>File-Based Rules (Alternative)</h3><p>You can also define routing rules in a local YAML file instead of an API.</p><p>Example: routing_rules.yml</p><pre>---<br>name: &quot;airflow&quot;<br>description: &quot;If query from Airflow, route to ETL group&quot;<br>condition: &#39;request.getHeader(&quot;X-Trino-Source&quot;) == &quot;airflow&quot;&#39;<br>actions:<br>  - &#39;result.put(&quot;routingGroup&quot;, &quot;etl&quot;)&#39;<br>---<br>name: &quot;special-label&quot;<br>description: &quot;If Airflow query has label=special, route to ETL-Special group&quot;<br>condition: &#39;request.getHeader(&quot;X-Trino-Client-Tags&quot;) contains &quot;label=special&quot;&#39;<br>actions:<br>  - &#39;result.put(&quot;routingGroup&quot;, &quot;etl-special&quot;)&#39;</pre><p>Use this config:</p><pre>routingRules:<br>  rulesEngineEnabled: true<br>  rulesType: FILE<br>  rulesConfigPath: &quot;app/config/routing_rules.yml&quot;</pre><p>The Gateway re-reads this file every minute by default.</p><h3>Bringing It All Together</h3><p>Here’s the full routing flow:</p><pre>Client<br>  ↓<br>Trino Gateway<br>  ↓<br>External Routing Service (returns routingGroup)<br>  ↓<br>Cluster Group (adhoc / etl / special)<br>  ↓<br>Least loaded Trino cluster</pre><p><strong>Workflow Summary:</strong></p><ol><li>Client sends query → Gateway receives request.</li><li>Gateway calls external service (or checks file) to determine routing group.</li><li>Group mapped to registered clusters.</li><li>QueryCountBasedRouterProvider picks least loaded cluster.</li><li>Query is executed on selected cluster.</li></ol><h3>Key Takeaways</h3><p><strong>Automatic Load Balancing: </strong>QueryCountBasedRouterProvider routes queries to the least loaded cluster.</p><p><strong>Dynamic Routing: </strong>External service can decide routing group via POST API</p><p><strong>Custom Rules: </strong>Use MVEL expressions to route based on headers or query info</p><p><strong>Persistence: </strong>PostgreSQL stores cluster state and query metrics</p><p><strong>Failover: </strong>Unhealthy clusters automatically excluded</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c60821703036" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Your Own Ingredients Checker with OpenAI’s GPT-4 Vision Preview in 10 minutes and 3 easy…]]></title>
            <link>https://medium.com/@tarunteja417/building-your-own-ingredients-checker-with-openais-gpt-4-vision-preview-in-10-minutes-and-3-easy-266faab18463?source=rss-af508bfdafca------2</link>
            <guid isPermaLink="false">https://medium.com/p/266faab18463</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[beauty]]></category>
            <category><![CDATA[food]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[TarunTeja]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 20:32:47 GMT</pubDate>
            <atom:updated>2025-04-29T20:00:33.288Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Your Own Ingredients Checker with OpenAI’s GPT-4 Vision Preview in 10 minutes and 3 easy steps!</h3><p>Recently, OpenAI unveiled a groundbreaking model called gpt-4-vision-preview, a cutting-edge tool that enables us to process images and ask questions about them. Leveraging this technology, let&#39;s dive into how you can build your own ingredients checker, a handy tool for anyone interested in understanding more about the foods they consume or cosmetics they use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Isp9hUUu1cssv0SphXahsQ.png" /></figure><h3><strong>1.Setting Up the FastAPI Endpoint</strong></h3><p>We begin by creating an endpoint in a FastAPI application. FastAPI is a modern, fast web framework for building APIs with Python. Our endpoint, /reviewIngredientsV2/, is designed to handle POST requests, where users can upload an image of food ingredients.</p><pre>@app.post(&quot;/reviewIngredientsV2/&quot;)<br>async def analyze(file: UploadFile = File(...)):</pre><h3><strong>2.Processing the Uploaded Image</strong></h3><p>Once an image is uploaded, the next step is to encode this image into a format suitable for analysis. Here, we use Base64 encoding, a method of converting binary data into a text string, making it easier to transmit over networks.</p><pre>def encode_image(image_file):<br>    return base64.b64encode(image_file.read()).decode(&#39;utf-8&#39;)</pre><h3><strong>3.Construct prompt and execute</strong></h3><p>The payload for the API request is constructed carefully. It includes the model name (gpt-4-vision-preview) and a structured message. This message instructs the model to analyze the ingredients in the image and provide information, including alternatives for any questionable ingredients.</p><pre>headers = {<br>        &quot;Content-Type&quot;: &quot;application/json&quot;,<br>        &quot;Authorization&quot;: f&quot;Bearer {api_key}&quot;<br>    }<br><br><br>    # Construct the payload<br>    payload = {<br>        &quot;model&quot;: &quot;gpt-4-vision-preview&quot;,<br>        &quot;messages&quot;: [<br>            {<br>                &quot;role&quot;: &quot;user&quot;,<br>                &quot;content&quot;: [<br>                    {&quot;type&quot;: &quot;text&quot;, &quot;text&quot;: &quot;You are Ingredient checker who helps consumer to understand ingredients used.Dont reveal that you are chatGPT.From the image go through all the ingredient and provide the information on ingredients.Provide alternatives if you find any questionable ingredients.Give me json response.The JSON structre is 1)GoodIngredients is array of objects, each object containing 1.a)Ingredient 1.b)Reason.  2)NeutralIngredients is array of objects, each object containing 2.a)Ingredient 2.b)Reason.  3)ControversialIngredients is array of objects, each object containing 3.a)Ingredient 3.b)Reason.  4)AlternativeIngredients is array of objects, each object containing 4.a)Ingredient 4.b)Reason.  5)Summary&quot;},<br>                    {&quot;type&quot;: &quot;image_url&quot;, &quot;image_url&quot;: {&quot;url&quot;: f&quot;data:image/jpeg;base64,{base64_image}&quot;}}<br>                ]<br>            }<br>        ],<br>        &quot;max_tokens&quot;: 4096<br>    }<br><br>    # Make the API request<br>    try:<br>        response = requests.post(&quot;https://api.openai.com/v1/chat/completions&quot;, headers=headers, json=payload)</pre><h3><strong>Sample responses for face wash:</strong></h3><pre>{<br>    &quot;GoodIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Purified Water&quot;,<br>            &quot;Reason&quot;: &quot;Safe solvent used in cosmetics.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Glycerin (Vegetable Derived)&quot;,<br>            &quot;Reason&quot;: &quot;Effective humectant and moisturizer derived from plants.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Aloe Vera Extract&quot;,<br>            &quot;Reason&quot;: &quot;Soothing agent with skin healing properties.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Panthenol (Pro-Vitamin B5)&quot;,<br>            &quot;Reason&quot;: &quot;Moisturizer that improves skin elasticity.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Sodium Ascorbyl Glucoside (Vitamin C)&quot;,<br>            &quot;Reason&quot;: &quot;Antioxidant that helps in skin brightening.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Lemon Essential Oil&quot;,<br>            &quot;Reason&quot;: &quot;Provides a natural fragrance and has antibacterial properties.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Orange Essential Oil&quot;,<br>            &quot;Reason&quot;: &quot;Has anti-inflammatory qualities and provides fragrance.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Licorice Extract&quot;,<br>            &quot;Reason&quot;: &quot;Known for skin brightening and anti-inflammatory properties.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Mulberry Extract&quot;,<br>            &quot;Reason&quot;: &quot;Rich in antioxidants and known to lighten skin pigmentation.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Tocopheryl Acetate (Vitamin E)&quot;,<br>            &quot;Reason&quot;: &quot;Antioxidant that protects skin from free radicals.&quot;<br>        }<br>    ],<br>    &quot;NeutralIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Cocamidopropyl Betaine&quot;,<br>            &quot;Reason&quot;: &quot;Gentle surfactant that helps with foam formation.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Sodium Lauroyl Sarcosinate&quot;,<br>            &quot;Reason&quot;: &quot;Mild surfactant and conditioning agent.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Disodium Cocoamphodiacetate&quot;,<br>            &quot;Reason&quot;: &quot;Mild surfactant with good cleansing properties.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Sodium PCA&quot;,<br>            &quot;Reason&quot;: &quot;Natural moisturizing factor that is hydrating.&quot;<br>        }<br>    ],<br>    &quot;ControversialIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Phenoxyethanol&quot;,<br>            &quot;Reason&quot;: &quot;Preservative which can be irritating at high concentrations, usually safe at low percentages.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Ethylhexylglycerin&quot;,<br>            &quot;Reason&quot;: &quot;Conditioning agent often used as an alternative to parabens, but safety data is less robust.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Disodium EDTA&quot;,<br>            &quot;Reason&quot;: &quot;Chelating agent that can be considered safe in small amounts but has environmental concerns.&quot;<br>        }<br>    ],<br>    &quot;AlternativeIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Ethylhexylglycerin&quot;,<br>            &quot;Reason&quot;: &quot;Can be replaced with less controversial alternatives like Caprylyl Glycol as a conditioning agent.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Disodium EDTA&quot;,<br>            &quot;Reason&quot;: &quot;Ingredients like Sodium Gluconate can be used as an alternative chelating agent.&quot;<br>        }<br>    ],<br>    &quot;Summary&quot;: &quot;The product contains a variety of ingredients ranging from beneficial plant extracts and vitamins to gentle surfactants and moisturizing agents. Although there are some controversial preservatives and additives present, they are commonly used in cosmetic products and generally regarded as safe at the concentrations used. Consumers with sensitivities should patch test before use, due to some potential irritants.&quot;<br>}</pre><h3><strong>Sample response for food product:</strong></h3><pre>{<br>    &quot;GoodIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Wheat flour&quot;,<br>            &quot;Reason&quot;: &quot;A common and basic ingredient used in noodles, providing carbohydrates and some dietary fiber.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Edible vegetable oil&quot;,<br>            &quot;Reason&quot;: &quot;Used as a cooking medium and source of fats, although the type of vegetable oil used can vary in healthfulness.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Whole spices&quot;,<br>            &quot;Reason&quot;: &quot;Spices like clove, cinnamon, and green cardamom are natural flavor enhancers and offer potential health benefits.&quot;<br>        }<br>    ],<br>    &quot;NeutralIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Mineral (170)&quot;,<br>            &quot;Reason&quot;: &quot;Also known as calcium carbonate, used as an anti-caking agent or to enrich the product with calcium.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Salt&quot;,<br>            &quot;Reason&quot;: &quot;Essential for taste, but high intake can be a health concern for some individuals.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Sugar&quot;,<br>            &quot;Reason&quot;: &quot;Used as a sweetener, it&#39;s neutral in small amounts but high consumption can lead to health issues.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Milk solids&quot;,<br>            &quot;Reason&quot;: &quot;Provide creaminess and flavor, but can be an issue for those with lactose intolerance.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Garlic&quot;,<br>            &quot;Reason&quot;: &quot;Common flavoring agent with some health benefits.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Ginger&quot;,<br>            &quot;Reason&quot;: &quot;Common flavoring agent with antioxidative and anti-inflammatory properties.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Coriander&quot;,<br>            &quot;Reason&quot;: &quot;Common herb used for flavor with potential health benefits.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Black pepper&quot;,<br>            &quot;Reason&quot;: &quot;Used for flavor, has potential health benefits but can be an allergen for some people.&quot;<br>        }<br>    ],<br>    &quot;ControversialIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Gum (Guar gum)&quot;,<br>            &quot;Reason&quot;: &quot;A thickener and stabilizer, generally recognized as safe but can cause digestive issues in some people.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Flavour enhancer (635)&quot;,<br>            &quot;Reason&quot;: &quot;Also known as Disodium 5&#39;-ribonucleotides, commonly used in processed foods but can cause sensitivity reactions in some individuals.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Artificial flavoring substances&quot;,<br>            &quot;Reason&quot;: &quot;Often used to enhance taste, but their production and effects on health can be controversial.&quot;<br>        }<br>    ],<br>    &quot;AlternativeIngredients&quot;: [<br>        {<br>            &quot;Ingredient&quot;: &quot;Whole grain flour&quot;,<br>            &quot;Reason&quot;: &quot;A healthier alternative to white wheat flour, providing more fiber and nutrients.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Natural sweeteners (like stevia)&quot;,<br>            &quot;Reason&quot;: &quot;Can be used instead of sugar, especially helpful for those monitoring their sugar intake.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Unrefined sea salt&quot;,<br>            &quot;Reason&quot;: &quot;Contains trace minerals not found in regular table salt and is less processed.&quot;<br>        },<br>        {<br>            &quot;Ingredient&quot;: &quot;Fresh herbs and spices&quot;,<br>            &quot;Reason&quot;: &quot;Can be used instead of artificial flavoring substances to add natural flavors.&quot;<br>        }<br>    ],<br>    &quot;Summary&quot;: &quot;The product contains a mix of good, neutral, and controversial ingredients. While staples like wheat flour and vegetable oil are standard, the use of guar gum, flavor enhancer 635, and artificial flavors can be concerning to some consumers. Offering alternatives such as whole grain flour, natural sweeteners, and fresh spices could appeal to health-conscious individuals.&quot;<br>}</pre><p>Try and let me know how it went :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=266faab18463" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flask Meets Serverless: Deploying on Vercel Simplified]]></title>
            <link>https://medium.com/@tarunteja417/flask-meets-serverless-deploying-on-vercel-simplified-184fc7bc77d1?source=rss-af508bfdafca------2</link>
            <guid isPermaLink="false">https://medium.com/p/184fc7bc77d1</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[TarunTeja]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 19:59:50 GMT</pubDate>
            <atom:updated>2025-04-29T19:55:45.839Z</atom:updated>
            <content:encoded><![CDATA[<p>Deploying Flask apps can be complex, but Vercel’s serverless platform simplifies the process. This post guides you through deploying a Flask application on Vercel, making it straightforward and efficient.End Goal is to display a HTML page rendered by flaskIntegrating Frontend with Flask, where we can upload a PDF and see out flask APIs in action.</p><h4>Preparing Your Flask App</h4><p>Ensure your Flask app runs locally. Organize your files with app.py and requirements.txt. Remember, Vercel expects a specific structure, typically with your application entry point in an api directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*Q6YRSN_9mjLGRxzmmuaimQ.png" /><figcaption>Folder structure</figcaption></figure><h4>Configuring for Vercel</h4><p>Create a vercel.json file to instruct Vercel. It should define build settings and routes, directing requests to your Flask app. Example:</p><pre>{<br>  &quot;rewrites&quot;: [{ &quot;source&quot;: &quot;/(.*)&quot;, &quot;destination&quot;: &quot;/api/app.py&quot; }]<br>}</pre><h4>Deploying</h4><ol><li>Push your code to a Git repository.</li><li>Connect this repo to Vercel.</li><li>Set environment variables if needed.</li><li>Trigger deployment through Vercel’s dashboard or push to your repo for automatic deployment.</li></ol><h4><strong>Conclusion</strong></h4><p>Getting your Flask app up and running on Vercel comes down to a few key steps: correctly configuring your <strong>vercel.json</strong> and ensuring your <strong>folder structure</strong> is properly organized. With these elements in place, deployment becomes a straightforward process. Simply follow the intuitive Vercel UI for setup; once done, any changes you push to your repository are automatically detected and deployed by Vercel. Keep an eye on the deployment logs to stay informed of your app&#39;s status. In short, with the right setup, deploying your Flask application on Vercel is hassle-free and efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qS25zYJp2sc-rRiP8o00EQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=184fc7bc77d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chat with your SQL database — The Easy Guide with Code.]]></title>
            <link>https://medium.com/@tarunteja417/chat-with-your-sql-database-the-easy-guide-with-code-009ebdb3203c?source=rss-af508bfdafca------2</link>
            <guid isPermaLink="false">https://medium.com/p/009ebdb3203c</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[openai]]></category>
            <dc:creator><![CDATA[TarunTeja]]></dc:creator>
            <pubDate>Sun, 14 Jan 2024 14:48:13 GMT</pubDate>
            <atom:updated>2025-04-29T20:03:38.717Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chat with your SQL database — The Easy Guide with Code.</h3><p>Ever wished you could just talk to your SQL database like a friend? Well, you’re in luck! In this guide, I’ll walk through four super simple steps to make that happen. Let’s turn those silent tables into chatty buddies!</p><p><strong>Step 1: Grab the Blueprint — Get the SQL Schema</strong></p><p>First things first, let’s understand the layout of your database. Think of it like getting the blueprint of a house before you start decorating. We’ll show you how to easily fetch the SQL schema, a sneak peek into the structure of your data.</p><pre>def reflect_db_schema(db_url):<br>    &quot;&quot;&quot;<br>    Reflects the database schema of the given database URL.<br><br>    Args:<br>        db_url (str): Database URL in the format &#39;dialect+driver://username:password@host:port/dbname&#39;<br><br>    Returns:<br>        dict: A dictionary containing detailed information about tables, columns, primary keys, indexes, foreign keys, and constraints.<br>    &quot;&quot;&quot;<br>    engine = create_engine(db_url)<br>    inspector = inspect(engine)<br><br>    db_schema = {}<br><br>    for table_name in inspector.get_table_names():<br>        columns = inspector.get_columns(table_name)<br>        indexes = inspector.get_indexes(table_name)<br>        foreign_keys = inspector.get_foreign_keys(table_name)<br>        pk_constraint = inspector.get_pk_constraint(table_name)<br>        primary_key_columns = pk_constraint.get(&quot;constrained_columns&quot;, [])<br>        unique_constraints = inspector.get_unique_constraints(table_name)<br><br>        # Collect all unique columns from unique constraints and unique indexes<br>        unique_columns = set()<br>        for uc in unique_constraints:<br>            unique_columns.update(uc[&quot;column_names&quot;])<br>        for index in indexes:<br>            if index[&quot;unique&quot;]:<br>                unique_columns.update(index[&quot;column_names&quot;])<br><br>        # Construct column details<br>        column_details = [<br>            {<br>                &quot;name&quot;: col[&quot;name&quot;],<br>                &quot;type&quot;: str(col[&quot;type&quot;]),<br>                &quot;primary_key&quot;: col[&quot;name&quot;] in primary_key_columns,<br>                &quot;nullable&quot;: col[&quot;nullable&quot;],<br>                &quot;unique&quot;: col[&quot;name&quot;] in unique_columns,<br>            }<br>            for col in columns<br>        ]<br><br>        # Construct foreign key details<br>        foreign_key_details = [<br>            {<br>                &quot;name&quot;: fk[&quot;name&quot;],<br>                &quot;constrained_columns&quot;: fk[&quot;constrained_columns&quot;],<br>                &quot;referred_schema&quot;: fk.get(&quot;referred_schema&quot;),<br>                &quot;referred_table&quot;: fk[&quot;referred_table&quot;],<br>                &quot;referred_columns&quot;: fk[&quot;referred_columns&quot;],<br>            }<br>            for fk in foreign_keys<br>        ]<br><br>        db_schema[table_name] = {<br>            &quot;columns&quot;: column_details,<br>            &quot;indexes&quot;: [index[&quot;name&quot;] for index in indexes],<br>            &quot;foreign_keys&quot;: foreign_key_details,<br>            &quot;unique_constraints&quot;: [uc[&quot;name&quot;] for uc in unique_constraints],<br>        }<br><br>    return db_schema</pre><p><strong>Step 2: Set the Stage — Build a Simple Prompt to achieve the user query.</strong></p><p>Now that you know your database’s blueprint, let’s create a basic script to talk to it. Don’t worry; we’ll keep it as easy as ordering your favorite coffee. This prompt will be your magic wand for generating the code that we want to execute later.</p><pre>finalPrompt = f&quot;You are a python programmer.You will be give db context and user query.You need to give me python code to achieve it.You will be given a database engine in a variable called &#39;engine&#39;.You need to use this engine , excute the query and store the result strictly in variable called &#39;output&#39;.Db context : \n{db_context}\n\nUser query : {connection.user_query}.output should have this JSON structure : 1.textualResponse&quot;</pre><p>In the first step, we’ve got the full picture of your SQL database structure, or as I like to call it, the <strong><em>db_context</em></strong>. It’s a detailed snapshot of all information related to your SQL database.The <strong><em>db_context</em></strong> after including only necessary info and cutting it short should look like :</p><pre>Database: postgres<br>Tables:<br>  - T: reviews<br>    - C: review_id, Type: INTEGER<br>    - C: movie_id, Type: INTEGER<br>    - C: user_id, Type: INTEGER<br>    - C: rating, Type: INTEGER<br>    - C: comment, Type: TEXT<br>    - PKS: review_id<br>    - UCS: None<br>    - NNC: review_id, user_id, rating<br>    - UQC: None<br>  - T: movies<br>    - C: movie_id, Type: INTEGER<br>    - C: title, Type: VARCHAR(100)<br>    - C: genre, Type: VARCHAR(50)<br>    - C: release_year, Type: INTEGER<br>    - PKS: movie_id<br>    - UCS: None<br>    - NNC: movie_id, title, genre, release_year<br>    - UQC: None<br>  - T: actors<br>    - C: actor_id, Type: INTEGER<br>    - C: movie_id, Type: INTEGER<br>    - C: name, Type: VARCHAR(100)<br>    - C: role, Type: VARCHAR(100)<br>    - PKS: actor_id<br>    - UCS: None<br>    - NNC: actor_id, name, role<br>    - UQC: None<br><br>Legend:<br>  - T: Table<br>  - C: Column<br>  - Type: Column Type<br>  - A: Column Alias<br>  - PKS: Primary Key Columns<br>  - UCS: Unique Constraint Columns<br>  - NNC: Not Null Columns<br>  - UQC: Unique Columns</pre><p>The <strong><em>user_query</em></strong> means the question that you want information on like “What are the top 4 movies?”, “Which is the least rated movie?” and so on.</p><p><strong>Bonus Tip:</strong></p><p>In the above prompt, the JSON response we are expecting is a simple string (<em>textualResponse</em>), you can customize this if you need a custom JSON response.For example for plotting a line graph you might want some extra JSON fields which includes all the data points to plot a graph.I have posted a example below, where if the API request has a mode which says “<em>linegraph</em>” then I would ask OpenAI to send a custom JSON response.</p><p><strong>Step 3: Call in the AI — Generate Code with OpenAI</strong></p><p>Time to add a touch of magic! We’ll leverage OpenAI to generate code for the user’s queries. It’s like having a code-writing assistant. Just tell OpenAI what you need, and it’ll whip up the code for you.</p><pre>def get_python_code(prompt):<br>    response = openai.ChatCompletion.create(<br>        model=&quot;gpt-4&quot;,<br>        temperature=0,<br>        messages=[<br>            {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You are a helpful assistant.&quot;},<br>            {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: prompt},<br>        ],<br>    )<br><br>    return response[&quot;choices&quot;][0][&quot;message&quot;][&quot;content&quot;].strip()</pre><p><strong>Step 4: Make It Happen — Execute the Code in Python</strong></p><p>No more talking, let’s make things happen! We’ll guide you through executing the code in Python using your database engine. It’s like hitting the play button on your favorite song; only this time, you’re playing the data.</p><pre>    globals = {<br>        &quot;engine&quot;: create_engine(db_url),<br>        &quot;output&quot;: None,<br>    }<br><br>    exec(code, globals)<br>    output = globals[&quot;output&quot;]<br>    return output</pre><p>Here the <strong><em>db_url </em></strong>is the end user database url with which we want to chat.Whatever code/SQL query is generated by the OpenAI using the db_context and user_query will be executed on the same database by which we get the response we needed.</p><p><strong>Sample Response from postman</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5zgKylnbQMpWnoEZAFbxg.png" /><figcaption>Sending OpenAI custom JSON requirement.</figcaption></figure><p><strong>Conclusion:</strong></p><p>You’ve just navigated the pathway to turn your SQL database into a conversational companion. Let’s recap the journey:</p><ol><li><strong>Blueprint in Hand:</strong> In the first step, you effortlessly acquired the db_context, offering a concise yet comprehensive snapshot of your SQL database’s structure.</li><li><strong>Simple Prompting:</strong> Armed with the database blueprint, you crafted a straightforward script using Python that not only understands but also executes the user’s queries seamlessly.</li><li><strong>OpenAI Magic:</strong> The magic touch was added in the third step, where OpenAI came into play. By simply describing your needs, you generated Python code effortlessly, thanks to our code-writing assistant.</li><li><strong>Code into Action:</strong> The final act involved executing the generated code on the user’s specific database using the provided db_url. It’s like hitting play on a song, but this time, you’re playing with your data.</li></ol><p>By following these four simple steps, you’ve not only opened up a channel for meaningful conversations with your SQL database but also empowered yourself to effortlessly interact with your data. So, go ahead, ask those burning questions, and let the dialogue with your database begin! Happy coding!</p><p>Note: If you have come here from my LinkedIn, this code is not the finalised version that the customers use. I have only shown the working POC code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=009ebdb3203c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>