Skip to main content

Posts

Showing posts from September, 2024

[go] Viết test code prometheus xem delta và rate tính thế nào

Bài trước đã dùng mắt để chạy code funcDelta và funcRate của Prometheus để xem code chạy qua những dòng nào, những phép tính nào được tính trong extrapolatedRate . Bài này sẽ sử dụng go test coverage để xem code nào được chạy. Viết test Prometheus Code của funcDelta và funcRate đều nằm trong file promql/functions.go , theo quy ước chung của Go, test sẽ nằm trong promql/functions_test.go , nhưng file này chỉ chứa có 2 test: $ grep ^func -c functions*_test.go functions_internal_test.go:1 functions_test.go:2 Lý do là PromQL tự tạo ra 1 kiểu/ngôn ngữ test riêng cho ngôn ngữ PromQL, nằm trong thư mục promqltest/ chứ không phải Golang test thông thường. file promqltest/README.md viết: The PromQL test scripting language This package contains two things: an implementation of a test scripting language for PromQL engines a predefined set of tests written in that scripting language $ find promql/promqltest promql/promqltest promql/promqltest/README.md promql/promqltest/test...

[go] Đọc code prometheus xem vì sao delta tính sai kết quả

Prometheus là gì The Prometheus monitoring system and time series /ˈsɪr.iːz/ database. Prometheus, a Cloud Native Computing Foundation project, is a systems and service monitoring system. It collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts when specified conditions are observed. Prometheus là tên phần mềm metric monitoring tiêu chuẩn ngày nay. 10 năm trước là graphite. Stack phổ biến thời cloud: Prometheus lưu trữ time series, hiển thị biểu đồ dùng grafana, gửi cảnh báo alert dùng alertmanager. Prometheus viết bằng Go, bắt nguồn từ SoundCloud, code xem tại https://github.com/prometheus/prometheus Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and main...

Đọc code bash xem vì sao echo * không hiện tên file ẩn

glob là gì $ whatis glob glob (7) - globbing pathnames Gõ man 7 glob có viết: NAME glob - globbing pathnames DESCRIPTION Long ago, in UNIX V6, there was a program /etc/glob that would expand wildcard patterns. Soon afterward this became a shell built-in. glob là khái niệm để "match" (chọn) filename sử dụng "pattern", gần giống với Regular Expression. Ví dụ trên shell gõ ls *.py sẽ hiện tên các file có đuôi .py . Điểm khác biệt so với Regular Expression: glob chỉ dùng để match filename, và các ký tự đặc biệt trong glob có ý nghĩa khác so với Regular Expression (ví dụ * có nghĩa khác). Wildcard pattern là gì Một string là 1 wildcard pattern nếu chứa ? * hoặc [ , glob là việc biến wildcard pattern thành list các filename "match" pattern. A '?' (not between brackets) matches any single character. A '*' (not between brackets) matches any string, including the empty string. Ví dụ $ touch error.c ...

bash chậm tới mức nào?

trên những môi trường không có ngôn ngữ nào khác, bash vẫn là lựa chọn duy nhất: docker entrypoint (script chạy 1 chương trình phức tạp trong docker) bash không dùng để viết chương trình cần hiệu năng cao, nhưng liệu bash chậm tới mức nào? Tính tổng từ 1 đến 1 triệu #1 x=0 for i in {1..1000000} ; do x=$((x+i)) done echo "$x" #2 x=0 for i in $(seq 1 1000000) ; do x=$((x+i)) done echo "$x" #3 x=0 for ((i=1;i<=1000000;i++)); do x=$((x+i)) done echo "$x" #4 x=0 i=1 while [ $i -le 1000000 ]; do x=$((x+i)) i=$((i+1)) done echo "$x" Trong 4 cách trên, cách 1 với {1..1000000} tạo 1 triệu phần tử trong RAM (như Python dùng list(range(1,1_000_001)) ), dùng hết 284MB RAM. cách 2 với seq 1 1000000 chỉ dùng 3.7MB RAM, nhưng phụ thuộc vào chương trình seq bên ngoài cách 3 và 4 tương tự nhau nhưng cách 4 chạy trên tất cả cách loại (POSIX) shell. Dùng shellcheck để biết cách 3 không chạy trên sh : $ sudo apt install -...

Popular posts from this blog

Tài liệu và hướng dẫn học Python

Để tiết kiệm thời gian, tốt nhất là đi học PyMI Updated: 130617 Sau đây là các tài liệu khuyên dùng: Vì nhiều lý do, nên học python2.7 tại thời điểm hiện tại (giờ là tháng 6/2013 - muốn biết tại sao thì tự tìm hiểu) python 3.5+ (giờ là tháng 2/2017) Chuẩn bị: 1. biết bật tắt máy 2. biết cài python 3. tập gõ 10 ngón - gõ 2 ngón hay 1 ngón cũng không sao, nhưng 10 ngón là cách dễ nhất để gõ nhanh nhất. Tài liệu - Nên dùng tài liệu tại trang chủ của Python làm chính, tham khảo thêm các tài liệu khác tại http://www.familug.org/2016/12/free-ebook.html Căn bản, mới học 1.1 Python PyMI.vn https://pymi.vn/tutorial/ 1.2. Python offical tutorial kết hợp làm bài tập trên HackerRank  (đề bài bằng tiếng Anh, nhưng Google translate 1 lúc cũng ra vì có nhiều ví dụ mẫu đi kèm). Học viên của Pymi.vn có rất nhiều học viên đã tự học với Learn Python the hard way nhưng chưa thấy ai thành công cả. Hai link dưới nên đọc sau khi đã nắm được những phần cơ bản của ngôn ngữ pytho...

The PyMiers

New FAMILUG