{"id":27443915,"url":"https://github.com/josephmachado/data_engineering_best_practices_log","last_synced_at":"2025-04-15T02:58:13.442Z","repository":{"id":227339622,"uuid":"771133945","full_name":"josephmachado/data_engineering_best_practices_log","owner":"josephmachado","description":"Code to demonstrate data engineering metadata \u0026 logging best practices","archived":false,"fork":false,"pushed_at":"2024-03-12T19:21:20.000Z","size":985,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T02:58:08.693Z","etag":null,"topics":["grafana","great-expectations","logging","metadata","minio","postgresql","prometheus","spark"],"latest_commit_sha":null,"homepage":"https://www.startdataengineering.com/post/de_best_practices_log/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josephmachado.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-12T18:41:48.000Z","updated_at":"2025-02-03T15:38:24.000Z","dependencies_parsed_at":"2024-03-12T20:45:48.453Z","dependency_job_id":null,"html_url":"https://github.com/josephmachado/data_engineering_best_practices_log","commit_stats":null,"previous_names":["josephmachado/data_engineering_best_practices_log"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fdata_engineering_best_practices_log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fdata_engineering_best_practices_log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fdata_engineering_best_practices_log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fdata_engineering_best_practices_log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josephmachado","download_url":"https://codeload.github.com/josephmachado/data_engineering_best_practices_log/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997095,"owners_count":21195797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grafana","great-expectations","logging","metadata","minio","postgresql","prometheus","spark"],"created_at":"2025-04-15T02:58:12.914Z","updated_at":"2025-04-15T02:58:13.432Z","avatar_url":"https://github.com/josephmachado.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Engineering Best Practices - #2. Metadata \u0026 Logging\n\nCode for blog at [Data Engineering Best Practices - #2. Metadata \u0026 Logging](https://www.startdataengineering.com/post/de_best_practices_log/)\n\nThis is part of a series of posts about data engineering best practices:\n\n1. [Data Engineering Best Practices - #1. Data flow \u0026 Code](https://www.startdataengineering.com/post/de_best_practices/)\n2. [Data Engineering Best Practices - #2. Metadata \u0026 Logging](https://www.startdataengineering.com/post/de_best_practices_log/)\n\n# Project\n\nFor project overview and architecture refer to [this Data flow \u0026 code repo](https://github.com/josephmachado/data_engineering_best_practices).\n\n# Logging architecture\n\n![logging architecture](assets/images/logging.png)\n\n# Setup\n\nIf you'd like to code along, you'll need \n\n**Prerequisite:**\n\n1. [git version \u003e= 2.37.1](https://github.com/git-guides/install-git)\n2. [Docker version \u003e= 20.10.17](https://docs.docker.com/engine/install/) and [Docker compose v2 version \u003e= v2.10.2](https://docs.docker.com/compose/#compose-v2-and-the-new-docker-compose-command). Make sure that docker is running using `docker ps`\n3. [pgcli](https://www.pgcli.com/install)\n\nRun the following commands via the terminal. If you are using Windows, use [WSL](https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-10#1-overview) to set up Ubuntu and run the following commands via that terminal.\n\n```bash\ngit clone https://github.com/josephmachado/data_engineering_best_practices_log.git\ncd data_engineering_best_practices_log\nmake up # Spin up containers\nmake ddl # Create tables \u0026 views\nmake ci # Run checks \u0026 tests\nmake etl # Run etl\nmake spark-sh # Spark shell to check created tables\n```\n\n```scala\nspark.sql(\"select partition from adventureworks.sales_mart group by 1\").show() // should be the number of times you ran `make etl`\nspark.sql(\"select count(*) from businessintelligence.sales_mart\").show() // 59\nspark.sql(\"select count(*) from adventureworks.dim_customer\").show() // 1000 * num of etl runs\nspark.sql(\"select count(*) from adventureworks.fct_orders\").show() // 10000 * num of etl runs\n:q // Quit scala shell\n```\n\nYou can see the results of DQ checks and metadata as shown below. Open the metadata cli using `make meta`\n\n```sql\nselect * from ge_validations_store limit 1;\nselect * from run_metadata limit 2;\nexit\n```\n\nUse `make down` to spin down containers.\n\n# Infrastructure components\n\n1. **Spark applications**: We have spark standalone cluster. When we submit a spark job a new spark application will be created and its UI will be available at [localhost:4040](http://localhost:4040/)\n2. **Metadata DB**: We have a postgres container that is used to store results of data quality checks (run by Great Expectations) and we store run information (table: run_metadata) in this database as well. You can access the metadata db using the `make meta` command.\n3. **Prometheus**: We have a Prometheus server running, and we have a Prometheus job that runs ever 5s ([configured here](monitoring/prometheus/prometheus.yml)) to pull spark metrics (via [Spark PrometheusServlet](https://spark.apache.org/docs/3.0.0/monitoring.html#executor-metrics)). Prometheus is available at [localhost:9090](http://localhost:9090/).\n4. **Grafana**: We have a Grafana service running as the UI for prometheus data. Grafana is available at [localhost:3000](http://localhost:3000/login), with username admin and password spark.\n\n# Future Work\n\n1. Setup Dashboard configuration for Grafana to display Spark metrics.\n2. Move log storage from local filesystem to a service like [Grafana Loki](https://grafana.com/docs/loki/latest/).\n3. Display metadata and Data quality results in Grafana UI.\n4. Add type information or make the metadata into a JSON. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephmachado%2Fdata_engineering_best_practices_log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosephmachado%2Fdata_engineering_best_practices_log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephmachado%2Fdata_engineering_best_practices_log/lists"}