Skip to content

Instantly share code, notes, and snippets.

View rajathithan's full-sized avatar

Rajathithan Rajasekar rajathithan

View GitHub Profile
@rajathithan
rajathithan / extract-cloud-run-details.py
Created April 22, 2024 09:49
This code snippet will help in extracting cloud run details across all projects under a GCP Org
"""
Purpose : To retrieve details on cloud run services across all projects under an org
Author : Rajathithan Rajasekar
Date : Jan 23, 2024
"""
from googleapiclient.discovery import build
import google.auth
import csv
@rajathithan
rajathithan / dataflow-wordcount.py
Created October 28, 2023 06:55
Count the words in a sentence
import apache_beam as beam
from log_elements import LogElements
lines = [
"apple orange grape banana apple banana",
"banana orange banana papaya"
]
with beam.Pipeline() as p:
@rajathithan
rajathithan / dataflow-event-trigger-2.py
Last active October 28, 2023 06:40
Dataflow event trigger with accumulation mode ( streaming )
import apache_beam as beam
from generate_event import GenerateEvent
from apache_beam.transforms.window import FixedWindows
from apache_beam.transforms.trigger import AfterWatermark
from apache_beam.transforms.trigger import AfterCount
from apache_beam.transforms.trigger import AccumulationMode
from apache_beam.utils.timestamp import Duration
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import StandardOptions
from log_elements import LogElements
@rajathithan
rajathithan / dataflow-generate-events.py
Last active October 28, 2023 06:27
Manual generation of events
import apache_beam as beam
from apache_beam.testing.test_stream import TestStream
from datetime import datetime
import pytz
class GenerateEvent(beam.PTransform):
@staticmethod
def sample_data():
@rajathithan
rajathithan / dataflow-event-trigger.py
Last active October 28, 2023 06:31
Trigger results on the count of element before watermark arrival on window time
from apache_beam.transforms.trigger import AccumulationMode
from apache_beam.utils.timestamp import Duration
from log_elements import LogElements
class CountEventsWithEarlyTrigger(beam.PTransform):
def expand(self, events):
return (events
| beam.WindowInto(FixedWindows(1 * 24 * 60 * 60), # 1 Day Window
trigger=AfterWatermark(early=AfterCount(1)),
@rajathithan
rajathithan / cloud-sql-proxy-dataproc.sh
Created October 24, 2023 17:08
Cloud-SQL-Proxy installation and configuration for Dataproc clusters
#!/bin/bash
# Installation of Cloud-sql-proxy in DataProc clusters
# Script Re-Modified by - Rajathithan Rajasekar
# Date - October 12, 2023
# projectname:region-name:instance-name
# Reference taken from - https://github.com/GoogleCloudDataproc/initialization-actions/blob/master/cloud-sql-proxy/cloud-sql-proxy.sh
# Readonly Variables
readonly PROXY_DIR='/var/run/cloud_sql_proxy'
readonly PROXY_BIN='/usr/local/bin/cloud_sql_proxy'
@rajathithan
rajathithan / main.py
Created August 13, 2023 11:39
Cloud Function code to trigger dataflow flex template
# Cloud Function code to trigger dataflow flex template
# Author: Rajathithan Rajasekar
# Version : 1.0
# Date: 08/05/2023
from __future__ import annotations
from typing import Any
import google.auth
from google.auth.transport.requests import AuthorizedSession
import requests
@rajathithan
rajathithan / pipeline-run-flex.py
Created August 13, 2023 11:03
Dataflow Flex template job to upload xml data from GCS to BQ
# Dataflow Flex template job to upload xml data from GCS to BQ
# Author: Rajathithan Rajasekar
# Version : 1.0
# Date: 08/05/2023
import sys
import json
import logging
import argparse
import xmltodict
@rajathithan
rajathithan / dataflow-job-gcs-to-bq.py
Last active August 6, 2023 02:50
Dataflow Job to create custom dataflow template from upload of xml data from GCS to BQ
# Dataflow Job to create custom dataflow template for upload of xml data from GCS to BQ
# Author: Rajathithan Rajasekar
# Version : 1.0
# Date: 08/05/2023
import sys
import json
import logging
import argparse
@rajathithan
rajathithan / main.py
Last active July 30, 2023 06:07
Python script to send email from cloud function using customized html template
#!/usr/bin/env python
# Python script to send email from cloud function using customized html template
# Author: Rajathithan Rajasekar
# Version : 1.0
# Date: 07/30/2023
import os
import pytz
import smtplib
from datetime import datetime