<?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 Hung-Tao Hsieh on Medium]]></title>
        <description><![CDATA[Stories by Hung-Tao Hsieh on Medium]]></description>
        <link>https://medium.com/@hungtaohsieh?source=rss-8b53d0c62c3a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rQbmUdG_5iSrN27UWsDGMA@2x.jpeg</url>
            <title>Stories by Hung-Tao Hsieh on Medium</title>
            <link>https://medium.com/@hungtaohsieh?source=rss-8b53d0c62c3a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 17:21:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hungtaohsieh/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[特斯拉15大優缺點]]></title>
            <link>https://medium.com/@hungtaohsieh/%E7%89%B9%E6%96%AF%E6%8B%8913%E5%A4%A7%E5%84%AA%E7%BC%BA%E9%BB%9E-33f3f174bd3c?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/33f3f174bd3c</guid>
            <category><![CDATA[玻璃]]></category>
            <category><![CDATA[特斯拉]]></category>
            <category><![CDATA[model-3]]></category>
            <category><![CDATA[tesla-model-3]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Sat, 31 Jul 2021 09:33:20 GMT</pubDate>
            <atom:updated>2021-07-31T14:19:19.915Z</atom:updated>
            <content:encoded><![CDATA[<p>目前持有特斯拉已經接近兩個月，行駛里程接近4000公里，該遇到的狀況應該也有一大半了，就來做個紀錄和大家分享一下：</p><h4>1. 國道很廢，都快要不會開車了</h4><p>在高速公路上只要排檔桿打兩下，就幫你開到目的地了，中間自己超車、加速、跟車，完全沒問題。轉換交流道和超車時要注意一下，基本上就是解放了黃金右腳。</p><h4>2. 超速罰單變少了</h4><p>以往最常超速的路段都是在高速公路，尤其警察偷拍更是😂 現在排檔桿打兩下，加上拉拉會偵測目前國道限速，基本上就是交給拉拉開即可。</p><h4>3. 安全性極高</h4><p>通過IIHS測試為安全性最高的車，<a href="https://www.iihs.org/ratings/vehicle/tesla/model-3-4-door-sedan/2021">參考</a>。基本上可能比瑞典小坦克還要硬了，<a href="https://news.ebc.net.tw/news/society/187472">特斯拉撞個稀巴爛結果駕駛還可以下車走動？</a> 類似的新聞很多，就請各位自己找了 XD</p><h4>4. 省錢、省錢、省錢</h4><p><strong>電費vs.油錢</strong></p><p>電車是電費計算，一度電基本上可跑5~6公里，以model 3 LR的75電來看，就可以跑 75*5，至少375公里。一度電3塊錢的話，大概是225塊。</p><p>油車一公升可跑10公里，以375公里來計算，一公升的油現在大概30塊，大概要價1125。</p><p>大概落差至少4倍呢！但你可能會說，油車加滿油只要5~10分鐘，以model 3 LR來看，差不多 20分鐘可充滿上路。（超充每小時可充120度電</p><p><strong>稅金</strong></p><p>model 3 LR的馬力為346hp，牌照稅是28200，不過目前法案是到 2025年都是免牌照稅的！</p><h4>5. 怠速開冷氣、遠端遙控</h4><p>疫情期間，餐廳以及開放空間都禁止飲食時情況下，在車內享受美食又可吹冷氣是最棒的，又不會對環境造成廢氣影響。</p><p>遠端遙控開冷氣也是個好物，有時車子停在戶外，可以預先開冷氣讓內部降溫，比起傳統油車上車後狂開冷氣要好很多。</p><p>還有就是寵物模式，帶貓貓狗狗出門放置在車上也不怕他會悶壞。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0llIHiWmcvPPZzGUC-D1Ag@2x.jpeg" /></figure><h4>6. 車內空間寬敞</h4><p>因為少了儀表板和豪奢的內裝，車內空間就空出許多，到處都可藏東西 😂</p><p>而前行李箱空間少了內燃機的關係，也空出來讓使用者使用。</p><p>後行李箱則是夠深， 又配置下置物空間，基本上空間超～～大的。</p><h4>7. 沒有家用充電樁的要慎重考慮</h4><p>特斯拉因為吃電，加上目前超充效率還沒想加油站這麼好，超充站點也還不夠多（儘管現在至少26站），所以家裡沒充電樁或是公司附近沒有的話，比較會有里程焦慮。像我家附近的公園都有慢速充電樁，加上周邊電車不算多，開過去都有得充</p><p>除此之外，公有的慢充還有個問題就是油車很沒品的佔位。不過現在台北市祭出新規，充電每小時$10，充滿不移$20，佔位也是$20。雖然才多收10塊，但相信可以提高車位使用率，又可降低油車佔位問題。</p><p>另外提醒一下，公有慢充收費其實相對家充算很佛了，一小時至少7Kw還只要10塊錢，家裡7kw也要逼近10塊了，但還是得看你家電費級距就是</p><h4>8. 長途旅遊的規劃</h4><p>現在換了電車，代表去山上或海邊的景點都要多看一下電量夠不夠，再來是目的地有沒有充電樁可用，還有數量夠不夠多，或是附近有沒有超充站可以蹭電，聽起來很麻煩，但就真的是這麼麻煩…</p><h4>9. 胎噪很大聲</h4><p>其實我也不知道是不是所有車子都這麼大聲，也許油車是因為引擎聲蓋過了胎噪聲 😂。但至少我之前駕駛 Benz CLA 200都還算安靜，音響不用開很大聲就聽得很清楚，現在都要開得稍微大聲。也許是因為這樣，Tesla的喇叭可以開到超大聲吧 XDD</p><h4>10. 前擋玻璃很爛</h4><p>我以為只是容易沾染灰塵泥土，沒想到硬度也很差。之前在群組有看到其他人說前擋玻璃被小石子坑爆了，一直想說不會發生在我身上，結果才3500公里就遇到了…model 3的前擋大概要3萬多塊左右，出險整個超划不來，於是我就跑去找玻璃修補，最後一千元搞定</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N_Qz8gpnWiiQde4g" /><figcaption>gg的玻璃…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VcofsxLt6EaXDPzR" /><figcaption>修補後的玻璃</figcaption></figure><h4>11. FSD</h4><p>Full self driving是雙面刃，讓你在高速公路的疲勞降低，但他目前也是有極限的，例如有車跟你平行要匯入同車道時，他可能分辨不出來會發生車禍。不過在他靠近時發現旁車過近，他會做一個方向盤拉轉回原車道的動作，還算不錯拉 XD</p><h4>12. 更新常常有彩蛋</h4><p>彩蛋有正面也有負面的，但正面的遠大於負面，例如model3的後照鏡防眩功能，在最新版的更新已經可以透過軟體解決摟！</p><p>還有昨天上路時發現車燈比以前更亮，還以為是我問題，結果太太也說，對！他變亮了😂</p><h4>13. 公差</h4><p>我這版車子的公差已經幾乎沒有了，這種車子組裝工廠出來的車只會越來越好，畢竟科技只會進步，所以也別太擔心拉～</p><h4>14. 烤漆很爛</h4><p>聽說烤漆爛到是被跳石擊中就是一個白點或凹痕，我自己是不敢體驗想像，所以就包了下巴和前引擎蓋，不過網路上很多慘例，烤漆深度好像也只有120，雙Ｂ進口車都有200左右的表現（印象中拉）</p><h4>15. 什麼都要自己搞</h4><p>傳統車廠在拿到車前，業務會幫你搞好很多工作，基本的業務三寶一定有（隔熱紙、腳踏墊、防曬蓋什麼的…）。</p><p>但特斯拉沒有，從腳踏墊、隔熱紙很多有的沒的都要自己來，尤其你發現有個東西很爛，你就會想換掉他…ＸＤＤ 但也因為這樣讓自己更認識了這台車，還有周邊配備，最近新認識的就是雨刷了，才知道雨刷真的有差啊！！！用了 zero sports的矽膠雨刷才發現原來可以這麼滑順、厲害 😂</p><p>希望以上的分享對你有幫助！您可以使用我的推薦連結在購買 Tesla 新車時獲得1,500 公里 的免費超級充電里程：<br><a href="https://ts.la/lalala80648">https://ts.la/lalala80648</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33f3f174bd3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[為什麼錢包地址的備份如此重要？]]></title>
            <link>https://blog.amis.com/%E7%82%BA%E4%BB%80%E9%BA%BC%E9%8C%A2%E5%8C%85%E5%9C%B0%E5%9D%80%E7%9A%84%E5%82%99%E4%BB%BD%E5%A6%82%E6%AD%A4%E9%87%8D%E8%A6%81-2168e727cfdb?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2168e727cfdb</guid>
            <category><![CDATA[中文]]></category>
            <category><![CDATA[ethereum-wallet]]></category>
            <category><![CDATA[crosscloud]]></category>
            <category><![CDATA[backup-software]]></category>
            <category><![CDATA[ethereum-address]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Tue, 16 Jun 2020 09:04:06 GMT</pubDate>
            <atom:updated>2020-06-16T09:09:31.767Z</atom:updated>
            <content:encoded><![CDATA[<h4>使用地址池與跨雲備份</h4><p>傳統的錢包系統上，客戶和錢包系統請求產生一組新地址時，系統會生成一組私鑰及對應的地址，並儲存到資料庫，然後再將地址返回給客戶。看起來再平常不過的行為，卻牽涉到背後雲端服務的穩定性。試想，今天客戶請求了一筆地址，系統也如預期的產生了，接著你馬上將錢存了進去，結果錢包系統背後的雲端服務發生了異常情形，導致無法服務，過了幾分鐘後，全部環境都恢復上線，當你再次到錢包系統查詢餘額，卻得到0，甚至是找不到。</p><p>要確保回給客戶的地址不會遺失，第一個想法就是縮短雲端服務的備份時間即可，但這畢竟是有極限的。看似簡單的任務，實際上是很複雜的。</p><p>AMIS做為錢包系統的開發商，目標就是確保客戶資產不會有安全上的疑慮，除了使用跨雲備份解決上述問題外，還提供機構等級的安全性、反駭客竊盜技術、點對點資料加密等。</p><h3>探討雲端服務</h3><p>縮短雲端系統的備份時間，還是沒辦法解決問題，以AWS為例，RDS snapshot/Point-In-Time支援的最新還原點是5分鐘，但你不可能要求客戶5分鐘後才可使用提款/存款吧？</p><p>也許你會說，可以使用Aurora的資料同步功能，備份到S3，但因為S3不支援加密，所以你的資料將會在網路上裸奔。</p><p>接著，將焦點從單一服務拉到整個雲端服務來看，當你把客戶資產託管在單一雲端系統上更容易承受過大損失而倒閉，例如 AWS在 2017年就因為一位開發人員的失誤而造成了<a href="https://www.datacenterknowledge.com/archives/2017/03/02/aws-outage-that-broke-the-internet-caused-by-mistyped-command">大規模的服務中斷</a>，當時的S&amp;P500損失了近1.5億美元，Azure在2018年則是因為<a href="https://www.geekwire.com/2018/microsoft-releases-details-last-weeks-big-azure-outage-servers-damaged-no-data-lost/">天災而造成硬體裝置損毀</a>，GCP在2019年則是發生了近三年最大規模的<a href="https://status.cloud.google.com/incident/compute/19008">當機</a>。</p><blockquote>你沒辦法預測什麼時候當機，只能做足準備。更重要的是，在數位貨幣這行，你該如何向雲端服務商證明你的損失並且索賠？</blockquote><p>由上述可發現，倚靠單一雲端平台是非常危險的。跨雲備份系統是必要的，設計上還要確保提供給客戶的地址不會在資料庫中遺失、已備份資料如何不外洩、資料的備份又該如何管理，又該如何監控備份資料是否完善等。</p><h3>跨雲備份服務的產生</h3><p>為了確保所有提供給客戶的地址不會遺失，我們使用了地址池的概念，也就是預先生成地址，並將其備份，接著就可確保此地址的使用性。</p><p>備份系統會從資料庫中輸出未備份的資料檔案，將其加密後上傳到第三方雲端儲存服務上（用來加密的私鑰則是存放於Vault中，管理者可以透過開設不同的帳號或 token 來限制不同的存取範圍），並利用檔案驗證碼確保遠端和本地是相同的。另外，檔案加密也可確保檔案在傳輸的過程中被側錄或是資料外洩時，也無從解開，還可避免自家人監守自盜的情況發生。</p><p>備份檔案的設計上，可以用差異備份又或是全部備份。差異備份的優點是速度較快，缺點是檔案過多，需要定期壓縮，且需儲存上次備份的位置。全部備份優點為還原和驗證的邏輯較為簡單，資料保存上可能僅需最後10筆資料即可，缺點就是備份時間較久。</p><h4>跨雲備份檔案管理</h4><p>由於內容極度敏感，所有檔案上傳後即無法被更改和刪除。現在許多雲端服務商都有提供保留原則政策的設定，主要是避免管理員操作失誤、符合法規控管，在時間上可以設定10年甚至更多，來確保資料不會無故消失。</p><h4>在雲端服務商上啟用審計追蹤</h4><p>這是一個非常重要的功能，開啟後我們可以知道雲端上的檔案今天被誰做了什麼操作，舉凡讀取、下載、編輯、增加新權限等都一覽無遺，當發生不可預期錯誤時，可以快速找到問題並解決。</p><h4>監控備份資料檔案</h4><p>監控已備份的地址數量與過去幾秒到幾分鐘的流量是非常重要的，做為錢包系統服務商，我們可以利用過去的數據來調整地址池的水位，以符合客戶的需求。</p><h4>定期驗證在雲端服務上的備份檔案</h4><p>確保檔案是正確可還原的，除了使用檔案驗證碼當作條件外，也將資料實際還原到資料庫中，確保這些檔案都沒有問題。</p><h3>系統架構</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zi9skXvrKzFf9kx37RSY1g.png" /></figure><p>基於前述的討論我們可以將系統設計成如上圖所示。</p><h4>Address pool service</h4><p>會不斷的監看已備份地址水位，如果不足的話則繼續生成地址。</p><h4>Backup service</h4><p>負責備份地址，產生加密備份檔案所需的私鑰，並儲存在Vault。接著將地址檔案加密後，上傳到Storage service。</p><h4>Verification service</h4><p>負責驗證檔案內容是否正確。</p><h3>結語</h3><p>確保客戶錢包地址的安全是非常重要的，現在交易所的錢包被盜，或是自家人偷竊的新聞都仍時有所聞。同時，雲端服務商的穩定性也是考量點之一，這些問題AMIS錢包都幫你想到了，近期也整合HTSS（Hierarchical Threshold Signature）到系統中，讓系統安全再上一層樓。</p><h4>閱讀更多</h4><ol><li><a href="https://www.am.is/wallet-service">AMIS wallet service</a></li><li><a href="https://medium.com/getamis/introduction-to-hierarchical-threshold-signature-revised-version-7446719bf427">Introduction to Hierarchical Threshold Signature(revised version)</a></li><li><a href="https://medium.com/getamis/hierarchical-threshold-signature-demonstration-6b8f95641edc">Hierarchical Threshold Signature demonstration</a></li><li><a href="https://medium.com/getamis/vault-kubernetes-integration-63ce46d47550">Vault與Kubernetes的深度整合</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2168e727cfdb" width="1" height="1" alt=""><hr><p><a href="https://blog.amis.com/%E7%82%BA%E4%BB%80%E9%BA%BC%E9%8C%A2%E5%8C%85%E5%9C%B0%E5%9D%80%E7%9A%84%E5%82%99%E4%BB%BD%E5%A6%82%E6%AD%A4%E9%87%8D%E8%A6%81-2168e727cfdb">為什麼錢包地址的備份如此重要？</a> was originally published in <a href="https://blog.amis.com/">getamis</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying the AWS IAM Authenticator to Elastickube]]></title>
            <link>https://blog.amis.com/deploying-the-aws-iam-authenticator-to-elastickube-52a96f8ee2f8?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/52a96f8ee2f8</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[english]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Tue, 25 Sep 2018 02:01:01 GMT</pubDate>
            <atom:updated>2018-09-25T02:01:01.845Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EC3u6PmP7C5Pcn0cy9HVKQ.png" /></figure><p>Managing authentication is an important task, requiring admins to maintain a list of acceptable users, validate permissions for each user, prune users that don’t need access, and even periodically revoke token and certificate-based access. The more systems need to be managed, the more complicated these tasks become. That is why we need to integrate AWS-IAM-Authenticator into Kubernetes, which allows you to have federated authentication using <a href="https://aws.amazon.com/iam/">AWS IAM</a>.</p><h3>Getting started</h3><p>To get started, we’re going to need a Kubernetes cluster, and the easiest way to get this up and running is to use Elastickube on <a href="https://github.com/getamis/vishwakarma">Vishwakarma</a> repository.</p><blockquote><em>Vishwakarma can be used to create a Kubernetes cluster in AWS by leveraging HashiCorp Terraform and CoreOS. And There are two kinds of Kubernetes Masters within vishwakarma, one leverages AWS EKS, the other one is ElastiKube (Self-Hosted). Elastickube is very robust, the HA is supported on master nodes, etcd, and worker nodes.</em></blockquote><h4>Install Elastickube</h4><p>We need to get the Elastickube repository. The easiest way is using git clone.</p><pre>cd ~/<br>git clone git@github.com:getamis/vishwakarma.git</pre><p>AWS-IAM-Authenticator uses <a href="https://kubernetes.io/docs/reference/access-authn-authz/authentication/#webhook-token-authentication">webhook token authentication</a> to verify a user. So we have to add the webhook flag into api-server(<strong>--authentication-token-webhook-config-file</strong>). It&#39;s very easy to integrate webhook token authentication on Elastickube. More details are provided in<a href="https://github.com/getamis/vishwakarma/pull/18"> PR</a>.<br> <br>Deployment in Elastickube is as simple as the following command.</p><pre>cd ~/vishwakarma/examples/aws-iam-authenticator<br>terraform init<br>terraform apply -target=module.network<br>terraform apply -target=module.kubernetes</pre><h4>Install kubectl on ubuntu/MacOS</h4><p>You will also need the Kubernetes command line tool, kubectl; you can install this using following command. For other platform, please refer to <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl">here</a></p><p><strong>Ubuntu</strong></p><pre>sudo apt-get update &amp;&amp; sudo apt-get install -y apt-transport-https<br>curl -s <a href="https://packages.cloud.google.com/apt/doc/apt-key.gpg">https://packages.cloud.google.com/apt/doc/apt-key.gpg</a> | sudo apt-key add -<br>sudo touch /etc/apt/sources.list.d/kubernetes.list <br>echo &quot;deb <a href="http://apt.kubernetes.io/">http://apt.kubernetes.io/</a> kubernetes-xenial main&quot; | sudo tee -a /etc/apt/sources.list.d/kubernetes.list<br>sudo apt-get update<br>sudo apt-get install -y kubectl</pre><p><strong>MacOS</strong></p><pre>brew install kubernetes-cli</pre><h4>Install AWS-IAM-Authenticator</h4><p>The second dependency we need to install is the AWS-IAM-Authenticator on client side. The easiest way to install this as of this writing is using curl. You can use the following command to do this:</p><p><strong>Linux</strong></p><pre>curl -Lo aws-iam-authenticator <a href="https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.3.0/heptio-authenticator-aws_0.3.0_linux_amd64">https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.3.0/heptio-authenticator-aws_0.3.0_linux_amd64</a><br>chmod +x aws-iam-authenticator<br>sudo mv aws-iam-authenticator /usr/local/bin</pre><p><strong>MacOS</strong></p><pre>curl -Lo aws-iam-authenticator <a href="https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.3.0/heptio-authenticator-aws_0.3.0_darwin_amd64">https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.3.0/heptio-authenticator-aws_0.3.0_darwin_amd64</a><br>chmod +x aws-iam-authenticator<br>sudo mv aws-iam-authenticator /usr/local/bin</pre><h4>Install AWS User Credentials</h4><p>The last dependency is to create user credentials. You must create a user profile on your local computer. The configuration file should be in the following format:</p><pre># ~/.aws/credentials<br>[default]<br>aws_access_key_id = ${YOUR_AWS_ACCESS_KEY_ID}<br>aws_secret_access_key = ${YOUR_AWS_SECRET_ACCESS_KEY}</pre><h3>Create Authentication Policy on Kubernetes</h3><p>Now we can test that our default kubeAdmin user still has access to the cluster by running kubectl get nodes. This should return the nodes that are connected to your cluster. Otherwise, it should receive an unauthorized error.<br> <br>We must create a ConfigMap that defines the AWS IAM users(Bob) who have access to the cluster.</p><pre># authenticator.yaml<br>---<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  namespace: kube-system<br>  name: aws-iam-authenticator<br>  labels:<br>    k8s-app: aws-iam-authenticator<br>data:<br>  config.yaml: |<br>    clusterID: auth-elastikube<br>    server:<br>      mapUsers:<br>      # map user IAM user Bob in 012345678901 to user &quot;Bob&quot; in &quot;system:masters&quot;<br>      - userARN: arn:aws:iam::012345678901:user/Bob<br>        username: Bob<br>        groups:<br>        - system:masters<br>---<br>apiVersion: extensions/v1beta1<br>kind: DaemonSet<br>metadata:<br>  namespace: kube-system<br>  name: aws-iam-authenticator<br>  labels:<br>    k8s-app: aws-iam-authenticator<br>spec:<br>  updateStrategy:<br>    type: RollingUpdate<br>  template:<br>    metadata:<br>      annotations:<br>        scheduler.alpha.kubernetes.io/critical-pod: &quot;&quot;<br>      labels:<br>        k8s-app: aws-iam-authenticator<br>    spec:<br>      # run on the host network (don&#39;t depend on CNI)<br>      hostNetwork: true</pre><pre>      # run on each master node<br>      nodeSelector:<br>        node-role.kubernetes.io/master: &quot;&quot;<br>      tolerations:<br>      - effect: NoSchedule<br>        key: node-role.kubernetes.io/master<br>      - key: CriticalAddonsOnly<br>        operator: Exists</pre><pre>      containers:<br>      - name: aws-iam-authenticator<br>        image: quay.io/edwin/aws-iam-authenticator:latest<br>        imagePullPolicy: Always<br>        args:<br>        - aws-iam-authenticator<br>        - server<br>        - --config=/etc/aws-iam-authenticator/config.yaml<br>        - --state-dir=/var/aws-iam-authenticator<br>        - --kubeconfig-pregenerated=true<br>        - --generate-kubeconfig=/etc/kubernetes/aws-iam-authenticator/kubeconfig<br>        - --reload-enabled<br>        - --reload-period=60</pre><pre>        resources:<br>          requests:<br>            memory: 20Mi<br>            cpu: 10m<br>          limits:<br>            memory: 20Mi<br>            cpu: 100m</pre><pre>        volumeMounts:<br>        - name: config<br>          mountPath: /etc/aws-iam-authenticator/<br>        - name: state<br>          mountPath: /var/aws-iam-authenticator/<br>          readOnly: true<br>        - name: output<br>          mountPath: /etc/kubernetes/aws-iam-authenticator/</pre><pre>      volumes:<br>      - name: config<br>        configMap:<br>          name: aws-iam-authenticator<br>      - name: output<br>        hostPath:<br>          path: /etc/kubernetes/aws-iam-authenticator/<br>      - name: state<br>        hostPath:<br>          path: /var/aws-iam-authenticator/</pre><p>Then, you can use kubectl apply to push your configuration changes to the cluster.</p><pre>$ kubectl apply -f authenticator.yaml</pre><p>After deployed, we need to make a new user in our kubeconfig. Do so by opening kubeconfig with your editor. Remove the kubelet user and add the following.</p><pre># kubeconfig<br>users:<br>- name: kubeAdmin<br>  user:<br>    exec:<br>      apiVersion: client.authentication.k8s.io/v1alpha1<br>      command: aws-iam-authenticator<br>      args:<br>        - &quot;token&quot;<br>        - &quot;-i&quot;<br>        - &quot;my-elastickube.example.com&quot;</pre><p>At the same time, we should replace each context user with kubeAdmin.</p><pre># kubeconfig<br>contexts:<br>- context:<br>    cluster: auth-elastikube<br>    user: kubeAdmin<br>    namespace: default<br>  name: default<br>- context:<br>    cluster: auth-elastikube<br>    user: kubeAdmin<br>    namespace: kube-system<br>  name: kube-system</pre><p>Being of great success, we can test authenticating against our cluster.</p><pre>$ kubectl get nodes<br>NAME                                        STATUS    ROLES     AGE       VERSION<br>ip-10-0-85-179.us-west-2.compute.internal   Ready     master    1d        v1.10.5+coreos.0</pre><p>To verify an invalid user, we can modify the ConfigMap by kubectl edit</p><pre>$ kubectl edit cm aws-iam-authenticator -n kube-system</pre><p>Amend the user ARN with an invalid ARN.</p><pre>      - userARN: arn:aws:iam::999999999999:user/Bob<br>        username: Bob<br>        groups:<br>        - system:masters</pre><p>Run kubectl get nodes again.</p><pre>$ kubectl get nodes<br>No resources found.<br>error: You must be logged in to the server (Unauthorized)</pre><h3>Teardown</h3><p>If you’d like to continue to use this cluster, you can leave it running. If you’d like to shut the cluster down, you can run the following command:</p><pre>$ terraform destroy -target=module.kubernetes<br>$ terraform destroy -target=module.network</pre><h3>Reference</h3><ul><li><a href="https://github.com/getamis/vishwakarma">vishwakarma</a></li><li><a href="https://aws.amazon.com/tw/blogs/opensource/deploying-heptio-authenticator-kops/">Deploying the heptio authenticator to kops</a></li><li><a href="https://kubernetes.io/docs/reference/access-authn-authz/authentication/#webhook-token-authentication">Kubernetes webhook token authentication</a></li><li><a href="https://blog.lola.com/5-things-i-wish-id-known-before-setting-up-heptio-authenticator">5 Things I Wish I’d Known Before Setting Up Heptio-Authenticator</a></li><li><a href="https://medium.com/nuvo-group-tech/manage-kubernetes-authentication-and-authorization-using-heptio-authenticator-and-helm-222df63d805c">Manage Kubernetes authentication and authorization using Heptio Authenticator and Helm</a></li></ul><h3>Future works</h3><h4>command: kubectl get</h4><p>It will return No resource found when invalid user runs kubectl get. Such as:</p><pre>ubuntu@ip-10-0-17-190:~$ kubectl get pod<br>No resources found.<br>error: You must be logged in to the server (Unauthorized)</pre><p>It’s seem like a bug or by design, we can skip it with flag(--ignore-not-found). For example:</p><pre>ubuntu@ip-10-0-17-190:~$ kubectl get pod -n kube-system --ignore-not-found=true<br>error: You must be logged in to the server (Unauthorized)</pre><p>Not sure if it is expected since this situation has not occurred in kubectl create or kubectl delete.</p><p><strong>command: kubectl create</strong></p><pre>ubuntu@ip-10-0-17-190:~$ kubectl create -f authenticator.yaml <br>error: You must be logged in to the server (the server has asked for the client to provide credentials)</pre><p><strong>command: kubectl delete</strong></p><pre>ubuntu@ip-10-0-17-190:~$ kubectl delete -f auth.yaml <br>error: You must be logged in to the server (error when deleting &quot;authenticator.yaml&quot;: Unauthorized)<br>error: You must be logged in to the server (Unauthorized)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52a96f8ee2f8" width="1" height="1" alt=""><hr><p><a href="https://blog.amis.com/deploying-the-aws-iam-authenticator-to-elastickube-52a96f8ee2f8">Deploying the AWS IAM Authenticator to Elastickube</a> was originally published in <a href="https://blog.amis.com/">getamis</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Geth not broadcasting transactions]]></title>
            <link>https://blog.amis.com/geth-not-broadcasting-transactions-1a881c50dafc?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a881c50dafc</guid>
            <category><![CDATA[區塊鏈]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[中文]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 01:31:02 GMT</pubDate>
            <atom:updated>2018-10-18T12:22:03.094Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nl8GkuIfp3-zoo9yeVV0jw@2x.jpeg" /></figure><h3>問題定義</h3><p>Geth短時間收到了龐大的交易（例如30秒收到了3萬筆），卻未能全部廣播給所有的已連上的peers。</p><h4>觀察1</h4><p>使用 <strong>txpool.status</strong>可以觀察到 <strong>pending</strong>的欄位有很多筆交易，過了一段時間（1小時，甚至更久）也不會被消化，要等全部被消化，大概需要一兩天（取決交易量及 <strong>--txpool.accountslots</strong>和 <strong>--txpool.globalslots</strong>大小）。</p><h4>觀察2</h4><p>使用 <strong>eth.getTransaction</strong> API時，看不到該筆交易。使用 <strong>txpool.status</strong> ，<strong>pending</strong>交易數量為0。</p><h3>系統架構</h3><p>目前我們的規劃架構是4台 Validators搭配1台 Transactor。Validators負責產生 Block。Transactor負責接收來自 Application層的交易，然後廣播給 Validators。而 Transactor和 Validators都是採用 Geth#v1.7.3的 <a href="https://quay.io/repository/amis/quorum">quorum</a>版本。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BzWiODGMt2fvUm6QEAkJ7A.png" /><figcaption><strong>Transactor architecture</strong></figcaption></figure><h3>研究問題</h3><h4>如何找到問題</h4><p>透過壓測的方式在短時間內發送3萬筆交易給 Transactor，過一陣子後會發現交易開始卡在 <strong>txpool.content.pending</strong> 。</p><p>大約20分鐘後，隨意拿任一筆 <strong>txhash</strong> 到 Kibana上面查詢，會發現 Transactor真的有廣播交易給4台 Validators，但4台 Validators收到的時間不固定，有的5分鐘，有的10分鐘。每個 Validators收到後也真的都有解開封包並組裝成交易，然後加入自己的 <strong>txpool</strong>，但是 Validators還是找不到該筆交易。</p><h4>兩個明顯的問題</h4><ol><li>交易已加入，但 Validators卻找不到</li><li>收到的時間不固定，跟 p2p connection有關？</li></ol><p>為驗證第一點，我們強制將 <strong>txpool</strong>裡面的 <strong>removeTx</strong>相關的邏輯都移除。再次執行壓測程式碼，發現所有的交易都可被 Valdiators所接受，也可在 Validators中找到，但有新問題，<strong>過久的區塊產生時間</strong>。</p><p>而第二點的問題，從第一點的測試中也沒有發生（p2p connection算蠻穩定的，每個 Validators都有收到交易）。目前推測這問題發生的原因是因為 Validators之間斷線重連，所以才又再次收到交易。</p><h4>其他可能的問題</h4><h4>TxPreEvent</h4><p>一筆交易成功加入到 <strong>txpool.content.pending</strong>後，會發送 TxPreEvent給其他的訂閱者。而 protocol handler會去註冊這個事件，收到後負責<a href="https://github.com/ethereum/go-ethereum/blob/v1.7.3/eth/handler.go#L712">廣播</a>給所有已連上的 peer。此 Event的大小是4096，經由上面的問題一實驗證明，這條路是不會造成阻塞的。</p><h4>Discarding freshly underpriced transaction</h4><p>在 <strong>addTx</strong>的過程中，超過 <strong>txpool</strong>的交易數量上限</p><ol><li>如果這筆交易 underprice，丟棄它並且返回。</li><li>找出所有 underprice的交易，然後丟棄（如果是 remote的，會被丟棄，如果是 local，會被保存）。</li></ol><h4>過久的區塊產生時間</h4><p>假設一個 Block可以處理4500筆交易，差不多要15~90秒的時間，這是由於每個 Transaction都必須經過驗證（包含可否被evm執行…等後才寫入到 Block。</p><h3>解決思路</h3><p>未能完全理解 <strong>txpool</strong>的運作方式前，可以有幾種方式來改善</p><h4>Rebooting validators</h4><p>這是最爛的解法，一但發現卡住，將所有的Validators都重開，但並不能清掉全部，取決於 <strong>--txpool.accountslots</strong>和 <strong>--txpool.globalslots</strong>的大小。主要是 peer A發送交易給 peer B後，就會標注已廣播交易給 peer B，因此當 peer間斷線後，資料清空，就又會再重新廣播一次交易。</p><h4>Rate limit</h4><p>透過 Rate limit的方式來限制要發送到 Transactor的，最理想的狀況是做在 API層，但 geth沒這個設計，不過我們利用 <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/sidecar">Sidecar</a>的方式來實作。然而 geth的 RPC每秒 TPS差不多300（再多就會有顯著延遲），還不能百分百確定你送進去的量沒有超過 Transactor的負載，不會卡住。這方案設計上須考量的點還蠻多的。</p><h4>Transaction window</h4><p>也是透過 <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/sidecar">Sidecar</a>的方式，固定時間詢問 Transactor的交易 pending數量，進而決定是否要再送交易。實作容易，且交易可以放在 persisted queue。如果 <strong>txpool.content.pending</strong>卡太久，也可以發出 alert。</p><h3>TxPool的相關知識</h3><p>TxPool用來存放準備被寫入區塊的交易，包含 <strong>remote</strong>與 <strong>local</strong></p><p>交易又分兩種</p><ul><li><strong>pending</strong>: 經過驗證（gas limit、nonce…等）後確定是可被執行的交易。</li><li><strong>queued</strong>: 已被提交但還不能夠被執行，例如 nonce跳號。</li></ul><p>TxPool支援多個command line設定</p><ul><li><strong>--txpool.pricelimit : </strong>捨棄低於此 gas limit的 Transaction</li><li><strong>--txpool.pricebump</strong>: 替換相同 nonce的交易價格百分比</li><li><strong>--txpool.accountslots</strong>: 每個帳號保證可執行的（<strong>pending</strong>）最少交易數量</li><li><strong>--txpool.globalslots</strong>: 所有帳號可執行的（<strong>pending</strong>）最大交易數量</li><li><strong>--txpool.accountqueue</strong>: 每個帳號無法執行的（<strong>queued</strong>）最大交易數量</li><li><strong>--txpool.globalqueue</strong>: 所有帳號無法執行的（<strong>queued</strong>）最大交易數量</li><li><strong>--txpool.lifetime</strong>: 無法執行的交易在queue裡的存活時間</li></ul><h3>參考資料</h3><ol><li><a href="https://github.com/ethereum/go-ethereum/blob/v1.7.3/core/tx_pool.go">[go-ethereum#1.7.3] core/tx_pool.go</a></li><li><a href="https://github.com/ethereum/go-ethereum/blob/v1.7.3/eth/handler.go">[go-ethereum#1.7.3] eth/handler.go</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a881c50dafc" width="1" height="1" alt=""><hr><p><a href="https://blog.amis.com/geth-not-broadcasting-transactions-1a881c50dafc">Geth not broadcasting transactions</a> was originally published in <a href="https://blog.amis.com/">getamis</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ingress nginx]]></title>
            <link>https://medium.com/@hungtaohsieh/ingress-nginx-e20a8e796996?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e20a8e796996</guid>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[hello-world]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Sun, 08 Apr 2018 11:23:37 GMT</pubDate>
            <atom:updated>2018-04-08T17:11:37.466Z</atom:updated>
            <content:encoded><![CDATA[<h3>介紹</h3><p>Nginx最常被用在反向代理、為伺服器添加SSL、負載平衡，甚至可以做簡單認證服務。今天要來講的是如何在azure的kubernetes上操作。</p><h3>如何使用</h3><p>Ingress的寫法很簡單，把你後端想要接的服務名稱、目標連接埠、路徑等設好，就萬事ＯＫ。</p><p>所以，總共有三件事要做</p><ul><li>架設ingress controller</li><li>架設ingress</li><li>架設service</li></ul><p>以下所有內容在此<a href="https://github.com/bailantaotao/misc">repository</a>裡面都找得到。</p><h4>架設ingress controller</h4><p>這件事很簡單，網路上有很多的範例可以抄，例如可以選擇到kubernetes的<a href="https://github.com/kubernetes/charts/tree/master/stable/nginx-ingress">example</a> repository，以及kuberntets專用的<a href="https://github.com/kubernetes/ingress-nginx/tree/nginx-0.12.0/deploy">ingress-nginx</a> repository，本篇是使用前者。</p><p>一個簡單的ingress controller設定檔如下</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdf7a685027974bc512aa5461409ee85/href">https://medium.com/media/cdf7a685027974bc512aa5461409ee85/href</a></iframe><p>Line 1: 開始設定我們的controller內容<br>Line 5: 因為我們希望外面的流量都通過ingress controller，所以useHostPort設定為true（這將使主機直接暴露80/443的Port）<br>Line 7~9: 設定這個Pod上面綁定的標籤，他會部署在有這個標籤的機器上<br>Line 10~11: 使用rbac。</p><p>接著，只要在根目錄下使用此指令就可以部署成功了</p><pre>helm install -n ingress-controller -f charts/app/hello-ingress-nginx/ingress-controller.yaml charts/generic/ingress-nginx</pre><h4>架設ingress</h4><p>接著，我們要設定每一個endpoint的規則，以及對應的路徑，如果要有basic-auth或者是TLS，也是在這設定。這裡舉例basic-auth的設定流程。</p><p>basic-auth就是基本的使用者帳密認證，在ingress設定方法很簡單。</p><ol><li>設定basic-auth的secret</li></ol><p>打開console，輸入以下指令，然後會要求你輸入密碼，接著就成功了</p><pre>$ htpasswd -c auth &lt;USER_NAME&gt;<br>New password: &lt;USER_PASSWORD&gt;<br>Re-type new password:<br>Adding password for user &lt;USER_NAME&gt;</pre><p>2. 將內容存放至secret</p><pre>$ kubectl create secret generic basic-auth --from-file=auth<br>secret &quot;basic-auth&quot; created</pre><p>3. 為你的ingress添加annotations，以及對應的規則和路徑。可以參考以下：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6c44283a2b4569745d2a6f29ab6e160/href">https://medium.com/media/f6c44283a2b4569745d2a6f29ab6e160/href</a></iframe><p>Line 3~5: 設定ingress的auth型態、對應的secret，auth-realm 其實就是瀏覽器會顯示給用戶的內容。<br>Line 6~17: 每一個ingress只能設定一個endpoint，伊格host底下，可以有許多的path<br>Line 10~13: 設定path為hello，當用戶使用 bailantaotao.example.com/hello時，就會將流量導入到服務名稱為hello-svc，該服務的連接埠為80</p><p>接著，只要在根目錄下使用此指令就可以部署成功了</p><pre>helm install -n ingress -f charts/app/hello-ingress-nginx/ingress.yaml charts/generic/ingress</pre><h4>架設service</h4><p>寫一個http server的handler，然後將執行檔build成一個image，讓pod可以使用，前面在外接一個service，這樣你的ingress才找得到喔！這裡舉例很簡單，就直接回應 Hello, current time: xxx 。來看看需要哪些步驟吧！</p><ol><li>寫一個http server</li></ol><p>我們使用golang快速刻了一個模型出來</p><pre><strong>package </strong>main<br><br><strong>import </strong>(<br>   &quot;fmt&quot;<br>   &quot;net/http&quot;<br>   &quot;time&quot;<br><br>   &quot;github.com/getamis/sirius/log&quot;<br>)<br><br><strong>func </strong>hello(rw http.ResponseWriter, rq *http.Request) {<br>   fmt.Fprintf(rw, &quot;Hello, current time: %s&quot;, time.Now())<br>}<br><br><strong>func </strong>bye(rw http.ResponseWriter, rq *http.Request) {<br>   fmt.Fprint(rw, &quot;Bye, see you next time&quot;)<br>}<br><br><strong>func </strong>main() {<br>   http.HandleFunc(&quot;/hello&quot;, hello)<br>   http.HandleFunc(&quot;/bye&quot;, bye)<br><br><br>   err := http.ListenAndServe(&quot;:8080&quot;, nil)<br>   <strong>if </strong>err != nil {<br>      log.Error(&quot;failed to start server&quot;, &quot;err&quot;, err)<br>   }<br>}</pre><p>2. 刻好Dockerfile，並上傳到某個雲端倉庫，這裡使用quay.io</p><pre>FROM golang:1.9-alpine as builder<br><br>RUN apk add --no-cache make gcc musl-dev linux-headers<br><br>ADD . $GOPATH/src/github.com/bailantaotao/misc<br>RUN cd $GOPATH/src/github.com/bailantaotao/misc/cmd/hello &amp;&amp; go build &amp;&amp; mv hello /hello<br><br># Pull mapi into a second stage deploy alpine container<br>FROM alpine:latest<br><br>RUN apk add --no-cache ca-certificates<br>COPY --from=builder /hello /usr/local/bin/<br><br>ENTRYPOINT [&quot;hello&quot;]</pre><p>3. 刻好pod和service</p><pre><strong>apiVersion: </strong>extensions/v1beta1<br><strong>kind: </strong>Deployment<br><strong>metadata:<br>  name: </strong>hello-deployment<br><strong>spec:<br>  replicas: </strong>1<br>  <strong>template:<br>    metadata:<br>      labels:<br>        app: </strong>helloserver<br>    <strong>spec:<br>      containers:<br>      </strong>- <strong>name: </strong>hello<br>        <strong>image: </strong>quay.io/edwin/hello:latest<br>        <strong>ports:<br>        </strong>- <strong>containerPort: </strong>8080<br>---<br><strong>apiVersion: </strong>v1<br><strong>kind: </strong>Service<br><strong>metadata:<br>  name: </strong>hello-svc<br><strong>spec:<br>  ports:<br>  </strong>- <strong>port: </strong>80<br>    <strong>targetPort: </strong>8080<br>    <strong>protocol: </strong>TCP<br>    <strong>name: </strong>http<br>  <strong>selector:<br>    app: </strong>helloserver</pre><p>最後！！使用以下指令就大功告成拉！</p><pre>kubectl create -f deployment.yaml</pre><h3>驗收結果</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xcVCHelW4wUU8wKAfbAlrQ.png" /><figcaption>檢視 bailantaotao.example.com/hello</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tZfnP9zxIwcTSutwC3k5g.png" /><figcaption>檢視 bailantaotao.example.com/bye</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e20a8e796996" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4種常用Logstash filter]]></title>
            <link>https://medium.com/@hungtaohsieh/3%E7%A8%AE%E5%B8%B8%E7%94%A8logstash-filter-493e94a391b7?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/493e94a391b7</guid>
            <category><![CDATA[logstash]]></category>
            <category><![CDATA[filters]]></category>
            <category><![CDATA[grok]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Sat, 31 Mar 2018 07:43:31 GMT</pubDate>
            <atom:updated>2018-03-31T11:03:51.251Z</atom:updated>
            <content:encoded><![CDATA[<p>最近因為專案需要，跳進了EFLK個坑，才發現同事多麼強大</p><p>這裡的內容比較適合像我這種剛研究的新手 xD</p><h3>1. grok</h3><p>grok是一種最常被使用在logstash的filter plugin，使用它來結構化你的未結構化log。例如我今天有一個字串從filebeat傳過來長這樣：</p><pre>[32mINFO [0m[03-29|16:36:02|print/print.go:20] fire wqwdqw                                    print=testing tickat=2018-03-29T16:36:02+0000</pre><p>接著，我就可以使用grok的表示式來結構化：</p><pre>\[%{DATA:textColor}%{LOGLEVEL:logLevel} %{NOTSPACE:notSpace}\[%{DATA:textColor}\[%{MONTHNUM:month}-%{MONTHDAY:day}\|%{TIME:time}\|%{GREEDYDATA:path}\] %{GREEDYDATA:context}  %{GREEDYDATA:keypairs}</pre><p>所以在logstash我們就可以這樣寫：</p><pre>filter {<br>  grok {<br>    match =&gt; { &quot;log&quot; =&gt; &quot;\[%{DATA:textColor}%{LOGLEVEL:logLevel} %{NOTSPACE:notSpace}\[%{DATA:textColor}\[%{MONTHNUM:month}-%{MONTHDAY:day}\|%{TIME:HHmmss}\|%{GREEDYDATA:logPath}\] %{GREEDYDATA:logContext}  %{GREEDYDATA:keyPairs}&quot; }<br>  }<br>}</pre><p>輸出如下，同時也是符合elasticsearch 的index格式</p><pre>{<br>          &quot;logPath&quot; =&gt; &quot;print/print.go:20&quot;,<br>         &quot;month&quot; =&gt; &quot;03&quot;,<br>           &quot;log&quot; =&gt; &quot;\e[32mINFO \e[0m[03-31|04:28:32|print/print.go:20] fire                                     print=testing tickat=2018-03-29T16:36:02+0000&quot;,<br>           &quot;day&quot; =&gt; &quot;31&quot;,<br>      &quot;notSpace&quot; =&gt; &quot;\e&quot;,<br>      &quot;logLevel&quot; =&gt; &quot;INFO&quot;,<br>      &quot;keyPairs&quot; =&gt; &quot;print=testing tick at=2018-03-31T04:28:32+0000&quot;,<br>       &quot;logContext&quot; =&gt; &quot;fire                                   &quot;,<br>           &quot;HHmmss&quot; =&gt; &quot;04:28:32&quot;,<br>     &quot;textColor&quot; =&gt; [<br>        [0] &quot;32m&quot;,<br>        [1] &quot;0m&quot;<br>    ],<br>}</pre><h4>驗證</h4><p>有一些線上的網頁可以驗證你寫的grok表示式，例如 <a href="https://grokdebug.herokuapp.com/">grok debugger</a>。kibana也有支援(我用的是6.2.3)，點選左邊工具列的 Dev tools ，接著點選 grok debugger 即可。</p><h4>模式</h4><p>grok有基本的patterns，很好用，且是由<a href="https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/grok-patterns">官方</a>提供</p><h3><a href="https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html">2. mutate</a></h3><p>顧名思義，可以對特定欄位做增減，以上面的例子繼續。從上面的輸出看到month, date, HHmmss是可以獨立成一個欄位的，我們可以這樣寫：</p><pre>mutate {<br>  add_field =&gt; {<br>    &quot;logTime&quot; =&gt; &quot;%{month}/%{day} %{HHmmss}&quot;<br>  }<br>}</pre><p>接著，又有一些無用的資料，例如textColor,、notSpace等等，把它們移除</p><pre>mutate {<br>  # format time<br>  add_field =&gt; {<br>    &quot;logTime&quot; =&gt; &quot;%{month}/%{day} %{HHmmss}&quot;<br>  }<br>  # remove dirty data<br>  remove_field =&gt; [ &quot;keyPairs&quot;, &quot;textColor&quot;, &quot;notSpace&quot;, &quot;month&quot;, &quot;day&quot;, &quot;HHmmss&quot;]<br>}</pre><h3><a href="https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html">3. kv</a></h3><p>有時候log會包含很多的key、value，可以使用kv來結構化，更棒的是，不需要寫迴圈，就可以把所有的key、value都填到fileds，這是我覺得最棒最聰明的地方。同樣以上面舉例，可以看到 keypairs 裡的資料長這樣</p><pre>{<br>      ...</pre><pre>      &quot;notSpace&quot; =&gt; &quot;\e&quot;,<br>      &quot;logLevel&quot; =&gt; &quot;INFO&quot;,<br><strong>      &quot;keyPairs&quot; =&gt; &quot;print=testing tick at=2018-03-31T04:28:32+0000&quot;,</strong><br>       &quot;logContext&quot; =&gt; &quot;fire                                   &quot;,</pre><pre>      ...<br>}</pre><p>所以我們可以這樣寫：</p><pre>kv {<br>  source =&gt; &quot;keyPairs&quot;<br>  field_split_pattern =&gt; &#39;((?:&quot;[^&quot;]*&quot;|[^: ])*)=((?:&quot;[^&quot;]*&quot;|[^ ])*)&#39;<br>}</pre><p>輸出長這樣：</p><pre>{<br>     &quot;print&quot; =&gt; &quot;testing&quot;,<br>     &quot;tickat&quot; =&gt; &quot;2018-03-31T07:19:57+000&quot;<br>}</pre><p>大功告成拉！</p><h4>Parsing</h4><p>上面有使用到 field_split_pattern，但其實可以拿掉不用，因為預設的pattern已經很強大了，例如message含有keypairs的資料他也可以parsing，要注意的就是key不能給兩個words，例如：</p><pre>logger.Info(&quot;value not in key, append new kv, key= &quot;, &quot;key1&quot;, &quot;value2&quot;)</pre><pre>--------<br>logstash<br>key : key1=value2</pre><pre>logger.Info(&quot;value not in key, append new kv, key= &quot;)<br>--------<br>logstash<br>key :</pre><pre>logger.Info(&quot;Two words in the key&quot;, &quot;tick at&quot;, t)<br>---------<br>logstash<br>at : yyyMMddHHmmss</pre><h3>4. Output</h3><p>可以在Output下插入一個 key/value，之後logstash就會噴訊息出來嚕！codec也可以使用json!</p><pre>stdout { codec =&gt; rubydebug }</pre><h3>完整的logstash.config</h3><pre>input {<br>  beats {<br>    port =&gt; {{ .Values.logstash.inputs.beat.port }}<br>  }<br>}<br><br>filter {<br>  grok {<br>    match =&gt; { &quot;log&quot; =&gt; &quot;\[%{DATA:textColor}%{LOGLEVEL:logLevel} %{NOTSPACE:notSpace}\[%{DATA:textColor}\[%{MONTHNUM:month}-%{MONTHDAY:day}\|%{TIME:HHmmss}\|%{GREEDYDATA:logPath}\] %{GREEDYDATA:logContext}  %{GREEDYDATA:keyPairs}&quot; }<br>  }<br>  kv {<br>    source =&gt; &quot;keyPairs&quot;<br>    field_split_pattern =&gt; &#39;((?:&quot;[^&quot;]*&quot;|[^: ])*)=((?:&quot;[^&quot;]*&quot;|[^ ])*)&#39;<br>  }<br>  mutate {<br>    # format time<br>    add_field =&gt; {<br>      &quot;logTime&quot; =&gt; &quot;%{month}/%{day} %{HHmmss}&quot;<br>    }<br>    # remove dirty data<br>    remove_field =&gt; [ &quot;keyPairs&quot;, &quot;textColor&quot;, &quot;notSpace&quot;, &quot;month&quot;, &quot;day&quot;, &quot;HHmmss&quot;]<br>  }<br>}<br><br>output {<br>  elasticsearch {<br>    hosts =&gt; [ &quot;elasticsearch.{{ .Values.namespace }}:{{ .Values.logstash.outputs.elasticsearch.port }}&quot; ]<br>    user =&gt; &quot;{{ .Values.logstash.outputs.elasticsearch.user }}&quot;<br>    password =&gt; &quot;{{ .Values.logstash.outputs.elasticsearch.password }}&quot;<br>    manage_template =&gt; false<br>    index =&gt; &quot;%{[@metadata][beat]}-%{+YYYY.MM.dd}&quot;<br>    document_type =&gt; &quot;%{[@metadata][type]}&quot;<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=493e94a391b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Haskell]]></title>
            <link>https://medium.com/@hungtaohsieh/learning-haskell-f4fcde0faaf4?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4fcde0faaf4</guid>
            <category><![CDATA[haskell]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Sat, 31 Mar 2018 05:00:41 GMT</pubDate>
            <atom:updated>2018-03-31T05:00:58.235Z</atom:updated>
            <content:encoded><![CDATA[<h4>forConcurrently</h4><p>多個線程去執行給定的函式，用法如下。需注意的是forCocurrently後面接list，此後再接一個函式，這函式參數代的方法需注意。</p><pre>print&#39; :: String -&gt; Integer -&gt; IO()<br>print&#39; x y= <strong>do<br>  </strong>mkdir $ &quot;gdata&quot; &lt;/&gt; fromText (nName y)<br>  print y</pre><pre>ttt :: IO ()<br>ttt = <strong>do</strong><br>  k &lt;- forConcurrently [1,2,3] (print&#39; &quot;123&quot;)</pre><h4>fromText</h4><p>一個無腦用法，可以把Text轉型成任何型態，什麼時候會用到呢？例如我想要組成filePath時。像上面的例子 &quot;gdata&quot; &lt;/&gt; fromText (nName y) ，其實就是要把 nName y 轉型成filePath，進而可以使用 &lt;/&gt; 去將兩個 FilePath組合。</p><h4>lift</h4><p>給定一個monad m，可以提升(lift)到建構monad變壓器t，只要t是MonadTrans 的instance。</p><h4>liftIO</h4><p>liftIO允許我們去提升一個IO動作到變壓器堆疊中，並且建立在IO之上，而且不管堆疊是如何的深，都可以被執行。</p><h4>(.)</h4><p>將兩個function連結在一起</p><pre>let reverseAndSort = reverse . sort<br>print $ reverseAndSort [3,6,1,8,0]</pre><h4>mconcat</h4><p>將二維陣列的資料打平成一維陣列</p><h3>Map</h3><p>想從Map的elements裡面取出某個attribute時，可以使用&lt;$&gt;來達到，&lt;$&gt;的左邊是functor，用來將右邊的list提升一個functor。需注意的是&lt;$&gt;為fmap的中繼符號。</p><pre><strong>data </strong>KeyPair = KeyPair { nodeKey    :: String<br>                       , enode     :: String<br>                       , address       :: String<br>                       } <strong>deriving </strong>(Show, Eq)</pre><pre>generatePair :: Map Integer KeyPair<br>generatePair = Map.fromList [(0, KeyPair { nodeKey = &quot;123&quot;, enode = &quot;node&quot;, address = &quot;address&quot;}), (1, KeyPair { nodeKey = &quot;1234&quot;, enode = &quot;node&quot;, address = &quot;addresss&quot;})]</pre><pre>print $ enode &lt;$&gt; Map.elems generatePair -- 與下一行等價<br>print $ fmap enode $ Map.elems generatePair</pre><pre>Output:<br>[&quot;node&quot;,&quot;node&quot;]</pre><h3>Data</h3><p>data類似golang的struct型態，可以在裡面定義多個member，也可以定義一個未帶資料型態的member。</p><h3>Deriving Show</h3><p>套用Deriving的data，會自動衍生出實例，而不必自行使用 instance 來定義，也就是說haskell會自動為您產生編碼。當然還是可以自行實作來覆寫。如以下：</p><pre><strong>data </strong>HexPrefix<br>  = WithPrefix<br>  | WithoutPrefix<br><br><strong>instance </strong>Show HexPrefix <strong>where<br>  </strong>show WithPrefix = &quot;prefix&quot;<br>  show WithoutPrefix = &quot;without&quot;</pre><h4>Curried function</h4><p>將一個有Ｎ個參數的function轉換成Ｎ個只有一個參數的function過程。</p><p>每個function其實都只有一個安樹</p><h3>Typeclass</h3><p>具有某個 Typeclass 行為的型態，必須實現該 Typeclass 規範的行為。某種程度上就像是golang的 Interface，我們定義member function。</p><h4>定義自己的typeclass</h4><p>這邊定義了一個 Comp 的 Typeclass，a 是型態參數。有點類似多形的概念，表示任何的datatype都可以吃，但能不能執行就是另一回事，要看該datatype是否有實作 Comp 了。</p><pre><strong>class</strong> Comp a <strong>where</strong><br>    comp :: a -&gt; a -&gt; Integer</pre><h4>實作typeclass</h4><p>讓兩個參數可以互相比較，因此我們必須幫助Integer這個datatype實作Comp，使用instance關鍵字來實作。</p><pre>instance Comp Integer <strong>where</strong><br>    comp x y = x - y</pre><p>緊接著，你就可以自己實作一個只接受Comp的參數作為輸入了的函式了</p><pre>sub :: Comp a =&gt; a -&gt; a -&gt; Integer<br>sub x y = comp x y</pre><pre>print $ sub (2::Integer) (1::Integer)<br>OUTPUT:<br>1</pre><pre>or <br>print $ comp (2::Integer) (1::Integer)<br>OUTPUT:<br>1</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4fcde0faaf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quorum-Tools]]></title>
            <link>https://medium.com/@hungtaohsieh/quorum-tools-f4dd1e41676b?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4dd1e41676b</guid>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 07:01:12 GMT</pubDate>
            <atom:updated>2017-07-11T07:01:28.666Z</atom:updated>
            <content:encoded><![CDATA[<h4>目前官方所列支援下列的測試：</h4><ul><li>Continually adding and removing nodes from a cluster until none of the initial members are left</li><li>Partitioning a node from the rest of the network</li><li>Public and private state consistency</li><li>Stopping, then restarting a node</li><li>Revoking a node’s membership in the cluster, re-registering it, and bringing it back online</li></ul><h3>實際測試內容</h3><h4>CycleTests:</h4><p>執行6個node，執行過程中添加新節點，看起來1, 2, 3是一個set，4,5,6又是另一組。最後還會傳送不合法交易給節點。</p><h4><strong>PartitionTests:</strong></h4><p>執行3個node，將leader隔離10秒，之後再加回。</p><h4><strong>PublicStateTests:</strong></h4><p>建立一個contract，增加他的storage，最後驗證。</p><h4>PrivateStateTests:</h4><p>建立一個contract，只有geth1, geth3參與tx，然後增加storage，最後驗證。</p><h4><strong>RestartNodeTests:</strong></h4><p>執行一個node，然後停止，再重啟。</p><h4>NewcomerRejoinTests:</h4><p>將其中一個node從cluster中移除，之後再重新加入，並且用舊的chain data。</p><h4>LeaveJoinTests:</h4><p>將其中一個node從cluster中移除，之後再加入一個新的，並且用舊的chain data。</p><p>註：<br>leader partition：當raft group發生網路分裂時，如果leader A的任期還沒到，但另一個分區已經選出新的leader，此時客戶再去更新某一個分區裡的值，之後再做讀取時就有機會發生錯誤。</p><h3>Istanbul BFT Integration tests</h3><h4>拜占庭Faulty node soft-behaviors:</h4><ol><li>not broadcast messages</li><li>send wrong messages</li><li>modify signature</li><li>always propose</li><li>always send round change</li></ol><h4>Faulty node hard-behaviors:</h4><ol><li>重新啟動非proposer的validator，必須要可以持續進行共識。</li><li>停止f+1個validators的運作10秒鐘，然後重新啟動，必須要可以持續進行共識。。</li><li>停止proposer 10秒鐘，然後啟動，必須要可以持續進行共識。。</li></ol><h4>Proof of lock</h4><p>TODO</p><h4>Normal case</h4><ol><li>在產生block與共識過程中，持續地增加和移除validators，最後只保留<strong>原始</strong>的validators，最後確認是否可持續產生block。</li><li>在產生block與共識過程中，持續地增加和移除validators，最後只保留<strong>非原始</strong>的validators，最後確認是否可持續產生block。</li><li>Proposer領先其他節點一個block，其他節點必須要可以sync到同一個block。</li><li>新加入的Validator必須可以同步到最新的block。</li><li>透過RPC平均的發送交易（例如一秒3000個）到每個validator，所有Validators要可以持續運作，且產生block，最後驗證某些tx是否存在。</li><li>透過RPC平均的發送交易（例如一秒3000個）到每個nodes（例如light client），所有的Validators必須同步所有的交易，且產生block，最後驗證某些tx是否存在。</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4dd1e41676b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[支撐有效否]]></title>
            <link>https://medium.com/@hungtaohsieh/%E6%94%AF%E6%92%90%E6%9C%89%E6%95%88%E5%90%A6-3cdff1267d55?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cdff1267d55</guid>
            <category><![CDATA[features]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Sun, 25 Jun 2017 08:18:28 GMT</pubDate>
            <atom:updated>2017-06-25T08:19:00.893Z</atom:updated>
            <content:encoded><![CDATA[<h4>如何認定支撐有效否？</h4><ol><li>某一天收盤剛好在那個支撐附近</li><li>盤中破支撐，收盤拉上來。</li></ol><p>什麼時候該進場？如果收盤再次往下，且破了前面的支撐，就代表空方非常強，你必須要關注，因為也代表套了更多人。</p><p>另外，須注意，跌的時候看壓力，跌勢過程中，如果站回壓力，就是不夠弱，所以壓力是看空方弱不弱。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cdff1267d55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[期貨的操作 20170623實戰課]]></title>
            <link>https://medium.com/@hungtaohsieh/%E6%9C%9F%E8%B2%A8%E7%9A%84%E6%93%8D%E4%BD%9C-e314892433df?source=rss-8b53d0c62c3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e314892433df</guid>
            <category><![CDATA[features]]></category>
            <dc:creator><![CDATA[Hung-Tao Hsieh]]></dc:creator>
            <pubDate>Thu, 22 Jun 2017 15:42:15 GMT</pubDate>
            <atom:updated>2017-06-22T16:04:53.677Z</atom:updated>
            <content:encoded><![CDATA[<h4>每次的操作進出場</h4><p>賠要賠的有價值，賺錢也要記得為什麼賺錢</p><p>賠錢要去思考，是大賺小賠裡不可避免的小賠，還是自己少思考了些甚麼，造成賠錢?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/153/1*6rd6QILn6ibAvfOtNUCf4w.png" /><figcaption>範例1</figcaption></figure><p>範例</p><ul><li>前面兩日都無法跌破，留長下引線，代表要下去，非常困難，而在最後一天收最高，沒有上引線存在，那就要非常小心。如果有空單，一定要停損，空單已被盯上。</li><li>相對的，最後一天靠近壓力後留了長上引線，代表過不去，有空方阻力。</li><li>如果要空，在跳空跌的當天收盤就要空了，因為在創新高的黑K，把前面的紅K都包起來，隔天跳空走跌，出了好幾個空方招式。包含空方陰陽反轉確認，前一天還再創新高，隔天跳空往下，跳空反轉的招式，但未確認，而左有缺又有缺，也是個島部反轉，真的弱爆了。</li></ul><p>要不要做空，可以從</p><ol><li>由K線的形態學來觀察有沒有做空的條件(形態學是位階最高的)</li><li>由K線觀察有沒有做空條件。</li><li>壓力能不能持續壓制，或是有非常大的套牢區。</li></ol><blockquote>如果有人有形態，那就是做他。如果兩個都有，那就看誰型態較強較大完整(例如做M頭、頭肩頂)。</blockquote><p>出現形態學的團頭是非常不好的，非常弱，且K線本身的振幅也代表其多/空方的力道。再來是盤整，然後是創新高後的小幅修正。如果創新高後的修正都未能跌破長紅低點，那也能算是弱中透強。如果修正都未能跌破中值，在續強，那這種就是好的修正。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e314892433df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>