software

Declarative vs imperative language Declarative programming (宣告式) What 代表為 functional programming (function 之間不會互相共用狀態) 程式碼通常是可以直接看到在做什麼 (重視 what) Imperative programming (命令式) how to do 代表為 OOP (狀態互相依賴) 看得見邏輯運算過程 (how to do) Repository Pattern Repository Pattern 是在 domain 和 data mapping 的中間層 透過 collection-like 的 interface 來存取 domain object 換句話說可以是 application 和 data access logic 的中間層 好處: 修改邏輯的時候只要改一個地方 測試 controller 變簡單了,不用真實存取資料庫資料 舉例: EmployeeController -> Employee Repository -> SQL server Database

fundamental1

in memory 程式的用法在記憶體上會切成很多小區塊,每一塊我們稱為 word 32 bits CPU: 1 word = 32bits = 4 bytes 64 bits CPU: 1 word = 64bits = 8 bytes 如何在 go get 的時候可以拉到 private repo 概念: 因為是 private repo 的關係, 所以要讓 go 有權限去拉 拉的時候是透過 git,所以要設定具有權限的 token 給 git 在個人的 github settings 建立一個可以拉取 private repo 的 token 把 token 記下以後,在本機操作 git cli 用 copy 下來的 token 取代下列的 GITHUB_TOKEN $ git config --global url."https://${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" Type Assertion vs Type Conversion Type Assertion (斷言)

basic for beginner

從 AWS EKS 下載 k8s config 範例: aws eks --region ap-southeast-1 update-kubeconfig --name <cluster-name> --kubeconfig <the name that we download to local> 載下來的 kube config 如何載入 載下來的 config 可以放到 ~/.kube 內 然後在 bash profile 設定環境變數 KUBECONFIG # k8s config setting export KUBECONFIG=~/.kube/service-prod-config:\ ~/.kube/service-staging-config 使用 context # 取得 context list kubectl config get-contexts # 使用特定 context kubectl config use-context <context name> # 詢問當前 context kubectl config current-context 使用 kubectx 可快速切換 k8s context 的工具

mapping and analysis

Introduction to analysis _source object 是做 index document 但卻不是用來作為搜尋的內容欄位 分析字串: analyzer character filter tokenizer token filter 舉例 (filter 和 tokenizer 種類繁多,僅舉例簡單情境): 分析 I REALLY like beer! character filter 做成 I REALLY Like beer! Tokenizer 做成 ["I", "REALLY", "Like", "beer"] Token Filter 做成 ["i", "really", "like", "beer"] 儲存的字串會被切成較小的字串儲存 (Tokenizer) Using the Analyze API POST /_analyze { "text": "2 guys walk into a bar, but the third.

managing documents

Creating & deleting indices 新增 index 範例: 新增 products index PUT /products # 結果 { "acknowledged" : true, "shards_acknowledged" : true, "index" : "products" } acknowledged: 表示是否有執行成功 shards_acknowledged: 表示 required shards 是否有在 timeout 前 start up default 是指 primary shard 刪除 index 範例: 刪除 products index DELETE /products Indexing documents 插入資料: index a document POST /products/_doc { "name": "Coffee Maker", "price": 64, "in_stock": 10 } # result { "_index" : "products", "_type" : "_doc", "_id" : "ek25vn0BLyjHJvg3PVzk", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1 } _shards: 表示有多少 shards 成功/失敗 儲存這筆資料 _id: 表示這筆資料的 identifier (系統自動產生,或者也可以自己指定)

getting started

Installation 安裝 Elasticsearch 安裝後可以用 http://localhost:9200 確認服務是否正常 Elasticsearch 的檔案目錄 bin 放置執行檔 (Elasticsearch 以外的還有如 plugin 安裝檔 或 cli) config 放置 configuration file elasticsearch.yml 檔案內容是 comment 標起來的,如果不另外把 comment 拿掉的話,系統會使用預設值 best practice 是要註明 cluster.name 和 node.name data / log 的路徑最好也自行指定 (特別指在 production 上) 這樣即使砍了 Elasticsearch 也不會有資料遺失 jvm.options 用來調整系統的記憶體配置 log4j2.properties 寫 log 的 framework data jdk 包含 OpenJDK lib 包含 Elasticsearch 會用到的 dependency logs modules 包含很多內建的 module plugins Basic architecture 基礎單元是 node,是 Elasticsearch 的 instance,用來儲存 data node 可以執行複數個,各自儲存部分的資料 node 不是機器,所以可以用幾台機器運行更多個 node 每個 node 都隸屬在 cluster 下 cluster 包含 nodes 通常不同的 cluster 會用來做不同的搜尋情境,彼此獨立 資料單位稱為 document,是一筆 json 格式的資料 index a document,意思是送一筆 json object 給 Elasticsearch 該筆 json object 到 Elasticsearch 後會在 "_source" 的節點下,並賦予其他 meta data index 包含多個 document query 的時候,是對指定的 index 做搜尋 document Kibana console 進入 Kibana 介面,並點擊 Dev Tools query HTTP method + request path 範例: 取得 cluster 狀態

introduction

Introduction to Elasticsearch 儲存一筆資料的單位是 document (類似 RDB 的 row) Document 的欄位叫做 fields (類似 RDB 的 column) 儲存的格式像 json client 透過 REST API 和 Elasticsearch 溝通 Overview of the Elastic Stack Kibana 分析 / 視覺畫的平台 透過 Elasticsearch 的資料來做視覺化 (發 http request) Logstash 處理 log (或其他資料,如訂單) 後把資料送給 Elasticsearch (也可以傳給不同的對象,如 Kafka) 資料處理的 pipeline pipeline 三步驟: input filter output pipeline configuration 的格式像 json X-Pack 提供額外功能給 Elasticsearch 和 Kibana Security authentication authorization Monitoring 視覺化 Elastic Stack 如何運作 (如顯示 CPU / memory usage / disk space) Alerting 設定告警 (如透過 email 通知) Reporting 輸出 Kibana 的資料 Machine Learning enable machine learning for Elasticsearch & Kibana Graph 分析資料的關聯 Elasticsearch SQL 可以傳送 SQL query 給 Elasticsearch Beats 蒐集資料並運送 Walkthrough of common architectures 同時儲存資料在 DB 和 Elasticsearch,後端收到 request 的時候兩邊都做 query

Makefile

範例 GREENLIGHT_DB_DSN='postgres://greenlight:@localhost/greenlight?sslmode=disable' ## help: print this help message .PHONY: help help: @echo 'Usage:' @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' .PHONY: confirm confirm: @echo 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ] ## run/api: run the cmd/api application .PHONY: run/api run/api: go run ./cmd/api ## db/psql: connect to the database using psql .PHONY: db/psql db/psql: psql ${GREENLIGHT_DB_DSN} ## db/migrations/new name=$1: create a new database migration .

script

範例 script.sh $ touch script.sh $ chmod +x script.sh 檔案內容 #!/bin/zsh GREENLIGHT_DB_DSN='postgres://greenlight:@localhost/greenlight?sslmode=disable' echo ${GREENLIGHT_DB_DSN} 運行 script.sh $ ./script.sh Reference 簡明 Linux Shell Script 入門教學