<?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 mofcloud on Medium]]></title>
        <description><![CDATA[Stories by mofcloud on Medium]]></description>
        <link>https://medium.com/@mofcloud?source=rss-97d2c3c4f086------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EWndEsom0HnnkVR5eZRJrQ.png</url>
            <title>Stories by mofcloud on Medium</title>
            <link>https://medium.com/@mofcloud?source=rss-97d2c3c4f086------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:51:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mofcloud/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[Alibaba Model Studio (Bailian) token cost analysis: by app & model]]></title>
            <link>https://medium.com/@mofcloud/alibaba-model-studio-bailian-token-cost-analysis-by-app-model-e14a09f67ee7?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/e14a09f67ee7</guid>
            <category><![CDATA[mofcloud]]></category>
            <category><![CDATA[alibabacloud]]></category>
            <category><![CDATA[finops]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Mon, 31 Aug 2026 11:12:49 GMT</pubDate>
            <atom:updated>2026-08-31T11:12:49.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*WGmkTKmjHnjKU3dFTv6QIA.png" /></figure><p>You’re running LLMs on Alibaba Cloud Model Studio (Bailian), and at month-end the bill is one number. Which app is burning the most? Which model costs the most? Why is it up 30% this month? Good luck breaking that apart.</p><p>This post shows how to break Bailian’s token cost apart — by model, by app, down to the token type — attribute it to a team, and (as a bonus) see your other Chinese AI platforms in the same place (using MOF as the example).</p><h3>The short answer</h3><ul><li>Bailian token cost can be broken down <strong>by model, by application, and by input / cached / output</strong>, and attributed <strong>by cost unit</strong> to a team or project.</li><li><strong>Not just Bailian:</strong> Volcengine (Doubao), Huawei, Tencent, and Baidu Qianfan work the same way — and you can see them <strong>across accounts and platforms in one view</strong>.</li><li><strong>Not just AI:</strong> tokens are one line on your bill — seen inside your <strong>whole cloud bill</strong>, you finally know how much AI actually costs.</li><li>Below, Bailian as the worked example.</li></ul><h3>What the native console shows, and where it falls short</h3><p>Bailian’s console and the Alibaba Cloud billing center show basic usage and spend. But when you actually sit down to do cost analysis, a few things get painful (check against your own console):</p><ul><li>Figuring out <strong>which app / agent</strong> costs the most usually means manually decoding instance IDs;</li><li>Seeing how much <strong>cache</strong> saved you, or whether <strong>output tokens</strong> are the real driver, means splitting tokens by type;</li><li>Attributing an app’s spend to a <strong>team / project</strong> for showback takes manual work;</li><li>Having <strong>multiple Bailian accounts</strong>, or also running Volcengine / Qianfan, and wanting it all <strong>in one place</strong>.</li></ul><p>That’s exactly what the rest of this post covers.</p><h3>How to break Bailian’s tokens apart (with MOF)</h3><p>MOF reads your Alibaba Cloud bill, recognizes Bailian’s AI services, and parses each line by <strong>model / application / token type</strong>. At the top, you get four numbers at a glance — Payment, Token, Model count, and <strong>Cache Hit Rate</strong> — and from there you drill:</p><ul><li><strong>By Model:</strong> which model burns the most (qwen3-max? qwen3-coder-flash?) — so you know what to route to a cheaper tier.</li><li><strong>By Application:</strong> which app or agent spends the most, mapped to a real workload.</li><li><strong>Input / cached / output split:</strong> how good your cache hit rate is (cached tokens are much cheaper) and whether output tokens are the real cost driver — that tells you where to optimize.</li><li><strong>By Cost Unit:</strong> give each team or cost center a clean number for their AI spend.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-Z5svLmGvE6AMynf.png" /></figure><p>What each cut answers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*pa59FS1lubOM96RYn95oiQ.png" /></figure><h3>Not just Bailian: same for the others, unified across platforms</h3><p>If Bailian isn’t the only thing you run:</p><ul><li><strong>Volcengine (Doubao), Huawei, Tencent, and Baidu Qianfan</strong> AI token usage connects and breaks down the same way;</li><li>Multiple Bailian accounts — or Bailian + Volcengine + Qianfan together — roll up <strong>across accounts and platforms into one view</strong>, so you’re not hopping between consoles;</li><li>Expanding overseas and also on OpenAI / Claude? Those come into the same picture too.</li></ul><h3>Not just AI: tokens are one line on the bill</h3><p>As hot as AI tokens are, they’re still just one item on your cloud bill. MOF is a <strong>cloud cost platform</strong> first: Alibaba, Tencent, Huawei, Volcengine, Baidu, plus AWS / Azure / GCP in one view — compute, storage, network, databases, and yes, AI tokens. So you see AI spend <strong>in the context of the whole bill</strong>, not as an isolated token count.</p><h3>How to connect Bailian</h3><p>Add your Alibaba Cloud account in MOF (access key with billing read permission). Once the bill syncs, Bailian usage shows up under <strong>AI Usage</strong>, ready to slice by any of the dimensions above.</p><h3>One practical tip</h3><ul><li>Watch two numbers: <strong>output-token share</strong> and <strong>cache hit rate</strong> — they move unit cost the most;</li><li>Cache the high-frequency, cacheable prompts; route simple tasks to a cheaper model;</li><li>Set <strong>cost alerts by app / team</strong> so a spike reaches you early — not at month-end.</li></ul><h3>FAQ</h3><p><strong>Bailian’s bill is one number — can it really be broken down?</strong> Yes. MOF splits it by model / application / token type, and attributes it by cost unit to a team.</p><p><strong>Is Bailian the only platform supported?</strong> No. Volcengine (Doubao), Huawei, Tencent, and Baidu Qianfan are supported too, unified across accounts and platforms.</p><p><strong>Is it only AI tokens?</strong> No. MOF is a cloud cost platform — AI tokens are one item, seen alongside your whole cloud bill.</p><p><strong>Can multiple Bailian accounts be combined?</strong> Yes, rolled up across accounts.</p><p><em>Current as of August 2026. Each cloud’s AI billing fields and console features may change over time — check against your own environment.</em></p><p><em>Originally published at </em><a href="https://mofcloud.com/blog/2026-08-31-bailian-token-usage"><em>https://mofcloud.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e14a09f67ee7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reseller-provided Azure (CSP): cost analysis with a service principal]]></title>
            <link>https://medium.com/@mofcloud/reseller-provided-azure-csp-cost-analysis-with-a-service-principal-195bde8a708c?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/195bde8a708c</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[finops]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Tue, 25 Aug 2026 22:34:58 GMT</pubDate>
            <atom:updated>2026-08-25T22:34:58.428Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*5Qz6b5mt7PAOkW1-rao44w.png" /></figure><p>Your Azure is through a reseller (CSP)? Then cost analysis comes down to two questions: how to get the billing data, and whether the numbers you see match your actual bill.</p><p>Good news: both are easy — and of the three big clouds, <strong>Azure is the simplest to set up</strong>. This post covers how to connect reseller-billed Azure to a cost tool, and how to turn it into what you actually pay (using MOF as the example).</p><h3>The short answer</h3><ul><li><strong>Two steps, both built in:</strong></li></ul><blockquote><strong>① Get the data:</strong> the reseller gives you a <strong>service principal</strong> with read access to your subscription or billing account — MOF generates the report itself (<strong>no exports, no storage container, no view to build</strong> — less setup than AWS or GCP).</blockquote><blockquote><strong>② Get the number right:</strong> use a <strong>custom discount</strong> to apply the reseller’s discount per period (e.g. 90%).</blockquote><ul><li><strong>Why the discount?</strong> As a CSP customer you see the <strong>pay-as-you-go (PAYG) retail rate</strong>, but what you pay the reseller is <strong>PAYG × the reseller discount</strong> — not the retail rate itself.</li></ul><h3>Why reseller (CSP) Azure is different</h3><p>Your Azure sits under the reseller’s <strong>CSP</strong> (Cloud Solution Provider). The reseller can turn on cost visibility for you (an Azure Resource Manager policy), and then you see your subscription’s usage at <strong>PAYG retail rates</strong> ( <a href="https://learn.microsoft.com/en-us/azure/cost-management-billing/costs/get-started-partners">Cost Management for partners</a>).</p><p>But <strong>retail isn’t what you pay</strong>: your deal with the reseller is usually PAYG with a discount (or at par). So when the PAYG number in a tool doesn’t match the reseller’s invoice, that’s expected — the difference is that discount.</p><h3>Step 1: get the data (one service principal is enough)</h3><p>Azure is less work here than the others: <strong>no</strong> CUR/S3 to set up like AWS, and <strong>no</strong> BigQuery view to build like GCP. All you need is a <strong>service principal (app registration)</strong>:</p><ol><li>The reseller (or you) creates a <a href="https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal">service principal</a> in the tenant;</li><li>Grant it <strong>Cost Management Reader</strong> on the <strong>subscription</strong> or <strong>billing account</strong> scope (read-only cost, <a href="https://learn.microsoft.com/en-us/azure/cost-management-billing/costs/assign-access-acm-data">how to assign access</a>);</li><li>Gives you the <strong>tenant ID, application (client) ID, and client secret</strong>, plus the <strong>subscription or billing account</strong>.</li></ol><p>With those, MOF calls Azure’s <a href="https://learn.microsoft.com/en-us/rest/api/cost-management/generate-cost-details-report">Generate Cost Details Report API</a> so Azure <strong>builds the report on demand</strong>, then downloads and parses it — you don’t pre-configure any scheduled export.</p><p><strong>In MOF:</strong> add an Azure account → fill in <strong>Application (client) ID, Directory (tenant) ID, and Password</strong>, then under <strong>Extension</strong> set <strong>Type = Subscription ID</strong> (or Billing Account) with its value, and save to sync. (Leave the billing account empty and MOF lists all the billing accounts you can access — handy when you don’t have billing-account-level permission.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/0*FY_-1Sci0ZgGW_5W.png" /></figure><p><em>Fill the service principal’s three values (client ID / tenant ID / password) and pick a subscription or billing account under Extension; leave the billing account blank to list all you can access.</em></p><h3>Step 2: get the number right (with a custom discount)</h3><p>Azure doesn’t need GCP’s “reseller mode,” because what you get is already the <strong>PAYG retail rate</strong> — so multiplying by your reseller discount gives what you owe. MOF’s built-in <strong>custom discount</strong> does exactly that.</p><p><strong>In MOF:</strong> pick the Azure account → <strong>Data Management → Custom Discount → Add discount</strong>:</p><ul><li><strong>Type:</strong> Standard Discount (applies to all of the account’s billing data);</li><li><strong>Discount:</strong> the rate your reseller gives you, e.g. 90%;</li><li><strong>Period:</strong> a start / end time. If the discount differs by month, add one row per period.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DZmLWWa6QqOJlEka.png" /></figure><p><em>Pick “Standard Discount,” set the reseller’s rate and an effective period; add more rows if it differs by month.</em></p><p>Once it’s applied, Bill Explorer and the other views show the account’s amounts as <strong>PAYG × discount</strong> — what you actually pay.</p><h3>Reconciling against the reseller’s bill</h3><ul><li><strong>Check the discount against the reseller’s invoice:</strong> PAYG × rate should land close to the invoice; if it lines up, the rate is right.</li><li><strong>Don’t chase a penny-perfect match:</strong> small gaps are usually rounding, not a miscalculation.</li><li><strong>One assumption:</strong> this holds when your Azure cost is on PAYG rates (typical for Azure Plan CSP). If the reseller gives <strong>different discounts per service</strong>, a single Standard Discount can’t capture that — approximate it with per-period rates, or handle that case separately.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cyx_iVfS0SKFfljxaR0X_Q.png" /></figure><h3>FAQ</h3><p><strong>Why doesn’t the Azure cost in my tool match the reseller’s invoice?</strong> What you see is the PAYG retail rate; what you pay is PAYG × the reseller discount — the gap is exactly that discount. Add the custom discount and they line up.</p><p><strong>What does the reseller need to give me?</strong> A service principal (tenant ID + application/client ID + client secret), with Cost Management Reader granted on your subscription or billing account. That’s it.</p><p><strong>Do I need to set up an export or a storage container?</strong> No. MOF calls Azure’s API to generate the cost details report on demand and pulls it — which makes Azure lighter to connect than AWS (needs a CUR) or GCP (needs a BigQuery view).</p><p><strong>My reseller gives a different discount each month.</strong> Add one row per effective period under Custom Discount.</p><p><strong>Does Azure have GCP’s “reseller mode” auto-recompute?</strong> It doesn’t need one. GCP gives you an already-discounted cost, so it has to be recomputed from list price — that’s what reseller mode is for. Azure gives you the PAYG retail rate, so a custom discount multiplied on top is all it takes.</p><p><em>Current as of August 2026. Azure Cost Management permissions and CSP billing may change over time — check Microsoft’s official docs and your own environment, and confirm the discount rate against your reseller’s invoice.</em></p><p><em>Originally published at </em><a href="https://mofcloud.com/blog/2026-08-24-azure-reseller-cost"><em>https://mofcloud.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=195bde8a708c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reseller-provided GCP: cost analysis with a BigQuery view]]></title>
            <link>https://medium.com/@mofcloud/reseller-provided-gcp-cost-analysis-with-a-bigquery-view-98c0c963d429?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/98c0c963d429</guid>
            <category><![CDATA[cloud-cost-optimization]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[finops]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Mon, 24 Aug 2026 12:18:17 GMT</pubDate>
            <atom:updated>2026-08-24T12:18:17.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*Sn6XlPZc1mUGFTGv4ib9hw.png" /></figure><p>Your GCP is through a reseller? Open a cost tool and the number comes out lower than the invoice the reseller sends you — it never matches.</p><p>Don’t assume the tool is wrong. <strong>What it shows just isn’t what you pay.</strong> This post walks through how the bill actually works for resold GCP, and how to get to the number you really owe (using MOF as the example).</p><h3>The short answer</h3><ul><li><strong>Two steps:</strong> have the reseller give you a <strong>BigQuery view</strong> (just your data), then use MOF to turn it into <strong>what you actually owe</strong>.</li><li><strong>Why does MOF need to recompute?</strong> A resold bill isn’t calculated like a normal GCP bill: you pay <strong>GCP’s list price times the discount your reseller gives you</strong> — not the raw cost number on the bill (that one is GCP’s cost to the reseller).</li><li><strong>Which credits are yours:</strong> usage-based ones (contract discounts, free tier) are yours; account-level perks (promotions, reseller margin) belong to the reseller and shouldn’t land on your bill.</li><li><strong>The discount changes month to month</strong> — higher usage can mean a lower rate next month. MOF lets you set it per month.</li></ul><h3>Why is reseller cost data so hard to get?</h3><p>All of GCP’s cost detail lives in <strong>BigQuery</strong> ( <a href="https://docs.cloud.google.com/billing/docs/how-to/export-data-bigquery-setup">billing export</a>). The catch: the reseller’s table has <strong>every customer’s billing mixed together</strong>. Hand you the whole table and you’d see everyone else’s data — so the reseller <strong>won’t</strong> give you direct BigQuery access.</p><p>In practice, most resellers just <strong>email you a spreadsheet each month</strong>. You can read it, but it’s limiting: static, high-level, limited to the columns they choose to share, and you wait for them to send it — never mind self-serve drill-down, anomaly alerts, or tag-based showback.</p><p>There’s a better way: <strong>the reseller can expose just your slice of BigQuery as a filtered “view” and grant it to you</strong> — only your data, nothing from other customers. Then you can analyze it like your own bill, live and down to the line item, and pipe it into MOF to compute what you actually owe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*JTAobS2BNdWEUibRt1Vezg.png" /></figure><p><em>(Exactly how to build the view and connect MOF is in “Step 1” below.)</em></p><h3>Why you can’t just read it off the bill</h3><p>A normal cost tool shows the cost number straight from the bill — but that’s <strong>GCP’s cost to the reseller</strong>, meant for the reseller, not what you pay.</p><p>As a resold customer, you pay something else: <strong>GCP’s list price, minus the credits owed to you, times the discount your reseller gives you.</strong> So reading the raw number, or just multiplying it by some ratio, won’t give you what you actually owe — you have to recompute from list price. <strong>That’s exactly what MOF does.</strong></p><h3>How the resold bill is actually calculated</h3><p>Three parts:</p><p><strong>① List price</strong> — GCP’s undiscounted price. The starting point.</p><p><strong>② Which credits are yours</strong> — the easiest thing to get wrong:</p><ul><li><strong>Yours:</strong> the ones tied to your usage — <strong>contract discounts</strong>, <strong>free tier</strong>.</li><li><strong>The reseller’s:</strong> account-level perks like <strong>promotions</strong> and <strong>reseller margin</strong>. Those go to the reseller and shouldn’t offset your bill.</li></ul><p><strong>③ Reseller discount</strong> — the rate your reseller gives you on list price, e.g. 0.95 (5% off list). <strong>Can differ month to month.</strong></p><p>Putting it together, here’s what a resold customer should actually see (example: one month at $1,000 list, $50 of credits that are yours, 0.95 discount):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*972casPHQgwEXT39PbzHTg.png" /></figure><p><em>(Example is illustrative, not measured.)</em></p><h3>Step 1: get your slice of the bill (a BigQuery view)</h3><p>The reseller’s GCP billing export sits in <strong>their</strong> BigQuery, with <strong>every customer in one table</strong> — they can’t hand you the whole thing. The standard move: the reseller creates an <a href="https://docs.cloud.google.com/bigquery/docs/authorized-views"><strong>authorized view</strong></a> filtered to just your data and grants that view to you. You can query your own bill without ever seeing the source table or anyone else’s data.</p><p>Have the reseller set it up (GCP’s built-in authorized-view mechanism):</p><ul><li><a href="https://docs.cloud.google.com/bigquery/docs/views"><strong>Create the view</strong></a>: in the reseller’s project, add a new dataset (separate from the source billing dataset) and a view filtered to your billing account:</li></ul><pre>SELECT * FROM `source_project.source_dataset.gcp_billing_export_v1_XXXX` <br>WHERE billing_account_id = &#39;&lt;your billing account ID&gt;&#39;</pre><blockquote>⚠️ <strong>Keep </strong><strong>SELECT * so the full schema comes through</strong> - MOF needs the list-price and credit-detail columns to recompute; cherry-picking columns drops data. (Google itself recommends views over billing export; see the <a href="https://docs.cloud.google.com/billing/docs/how-to/bq-examples">official query examples</a>.)</blockquote><ul><li><strong>Authorize the view on the source dataset</strong>: add this view to the source billing dataset’s “Authorized views.” Now the view can read the source table while you still <strong>can’t see the source itself</strong></li><li><strong>Grant you (or your service account) two roles</strong>: roles/bigquery.dataViewer on the view&#39;s dataset + roles/bigquery.jobUser on the project that runs the queries. (The reseller can also create a service account in their project, grant it these two roles, and just send you the JSON key - a simpler, one-sided grant.)</li><li>Send you these values: <strong>project ID (where the view lives), dataset name, view name, and the service account key.</strong></li></ul><blockquote><em>Constraints: the source and view datasets must be in the </em><strong><em>same region</em></strong><em>; cross-project is supported. A view’s SQL is hard to change once it’s set, so get the </em><em>billing_account_id right the first time.</em></blockquote><p><strong>Connect it in MOF:</strong> when you add the GCP account, fill in the <strong>service account key, Data Project (where the view lives), Dataset, and Table</strong> — put the <strong>view name in Table</strong> (a view queries just like a table).</p><blockquote><em>If your reseller uses the official </em><strong><em>Channel Services / rebilling export</em></strong><em> (Partner Sales Console, which carries their repriced data), it’s the same idea: that table also aggregates all customers, so filter it to your </em><em>billing_account_id in a view and grant that to you.</em></blockquote><h3>Step 2: turn on Reseller mode in MOF</h3><p>Once the bill is connected, pick your GCP account in MOF Enterprise → <strong>Data Management → Reseller</strong>:</p><ol><li><strong>Turn on “Billed through a reseller.”</strong> With it on, the account computes your payable as list price × reseller discount; with it off, it shows GCP’s raw cost. (GCP accounts only.)</li><li><strong>① Monthly reseller discounts:</strong> add a discount per effective period, e.g. 2026-07-01 ~ 2027-08-24 at 0.95. <strong>Months with no period fall back to list price (discount 1.0)</strong> - they don&#39;t drop back to the raw cost.</li><li><strong>② Credit pass-through:</strong> check the credits that are <strong>yours</strong> (<strong>Contract discount / Free tier</strong>); it applies to every month of the account and saves instantly. Leave the account-level benefits (Promotion, Reseller margin) unchecked.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FTPSK08D7Y0rfh4I.png" /></figure><p><em>① Maintain the reseller discount per month (0.95 in the example); ② check the usage-based credits that are yours (Contract discount, Free tier) — account-level benefits on the right stay unchecked.</em></p><p>Once it’s on, the account gets a <strong>“Reseller”</strong> badge across Bill Explorer, Anomaly, and Dashboards, and every amount is recomputed on that basis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Os9X969lLbHMvGUx.png" /></figure><p><em>With it on, the account is flagged “Reseller,” and Invoice, Payment, and the discount rate (95% here) are all recomputed on your basis.</em></p><h3>Reconciling against the reseller’s bill</h3><p>A few field-tested notes to judge whether it lines up:</p><ul><li><strong>Both numbers are right — just different bases.</strong> MOF’s raw “cost” matches GCP’s original bill exactly; the reseller-mode payable comes close to the reseller’s invoice (their spreadsheet). The gap between them is simply <strong>list price with your discount vs. GCP’s raw cost</strong> — not a miscalculation.</li><li><strong>It lines up at the line-item level,</strong> usually within rounding noise (±0.01).</li><li><strong>Don’t chase a penny-perfect match.</strong> Per-row monthly rounding gets closest to the reseller’s bill; a small residual is line-item granularity, not a logic error. If projects and months reconcile to within a few cents, you’re good.</li></ul><h3>FAQ</h3><p><strong>Why is the GCP cost in my tool lower than my invoice?</strong> Because the tool shows GCP’s raw cost to the reseller, while you pay “list price × reseller discount” — different starting points. To match your invoice, you have to recompute from list price.</p><p><strong>Which credits are mine, and which are the reseller’s?</strong> The usage-based ones (contract discounts, free tier) are yours; account-level perks (promotions, reseller margin) belong to the reseller and shouldn’t offset your bill. Tick the ones that are yours under MOF’s <strong>Credit pass-through</strong>.</p><p><strong>My reseller gives a different discount each month.</strong> Set it per month. Under <strong>Monthly reseller discounts</strong>, keep one discount per effective period; months with no period fall back to list price.</p><p><strong>My reseller won’t give me access to their BigQuery.</strong> Normal, and you don’t need it. Have them build a <strong>BigQuery authorized view</strong> filtered to your billing_account_id and grant the view to you (you only need dataViewer on the view&#39;s dataset and jobUser on the project). You can query your own bill without seeing the source table or anyone else&#39;s data. In MOF, just put the view name in the Table field.</p><p><strong>Can MOF auto-detect that I’m resold?</strong> Not always. Bills through an official reseller channel leave traces (a useful hint), but a <strong>direct, off-channel resale</strong> isn’t detectable — you turn on “Billed through a reseller” yourself.</p><p><strong>Does this work for other clouds?</strong> GCP for now. The same “recompute from list price” approach can extend to other clouds that expose list price and itemized credits; more will follow.</p><p><em>Current as of August 2026. The example figures are illustrative, not measured; GCP’s billing fields and a reseller’s pricing may differ, so check against your own bill and your reseller agreement.</em></p><p><em>Originally published at </em><a href="https://mofcloud.com/blog/2026-08-24-gcp-reseller-cost"><em>https://mofcloud.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98c0c963d429" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your AWS is through a reseller? How to still get your cost data]]></title>
            <link>https://medium.com/@mofcloud/your-aws-is-through-a-reseller-how-to-still-get-your-cost-data-26fb6a71b316?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/26fb6a71b316</guid>
            <category><![CDATA[cost-analytics]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[finops]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Sat, 22 Aug 2026 18:27:02 GMT</pubDate>
            <atom:updated>2026-08-22T18:27:02.333Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*Q4IF2PS2kO47MVlIqRg52g.png" /></figure><p>Plenty of companies don’t open AWS directly — they go through a <strong>reseller</strong> for billing, invoicing, and support in their own language. Then you want to do cost analysis, and the first worry is: the bill sits with the reseller, can I even read it?</p><p>Good news: <strong>in most cases you can handle it yourself</strong>, no reseller needed. This post shows how to tell which situation you’re in, and for each one, how to connect your bill to a cost tool (using MOF as the example) with the smallest possible permissions.</p><h3>The short answer</h3><ul><li><strong>In most cases, you can connect it yourself:</strong> create a CUR export in your own account, and MOF reads it automatically — no reseller involved (<strong>Situation A</strong>).</li><li><strong>Only if the reseller has restricted you</strong> (blocked you from creating exports) do you need their help: have them deliver the export to your bucket, hand you a read-only key, or open up an S3 bucket (<strong>Situation B</strong>).</li><li>Which one is you? <strong>Spend a minute on the self-test</strong> below — can you create your own export?</li></ul><h3>First: how did the reseller set up your account?</h3><p>Your own AWS account is both payer and management, so you export the bill with a click. Under a reseller you’re a <strong>member account</strong> — and whether you can do it yourself comes down to how the reseller attached you. It’s all AWS Organizations today, but in two flavors, and the difference is exactly whether they can use an <a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html"><strong>SCP</strong> (service control policy)</a>. Per the <a href="https://docs.aws.amazon.com/cur/latest/userguide/cur-consolidated-billing.html">AWS docs</a>, <strong>a member account can create its own CUR export by default</strong> (its own usage only):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*qp8EhChHsOi9tnpV249rcw.png" /></figure><p>How do you know which one you’re in? Ask the reseller — or just skip the question and run the self-test below. If you can create an export, you can; no need to categorize.</p><p>So what actually gates you isn’t “being on a reseller” — it’s whether that reseller has specifically restricted you.</p><h3>Three AWS rules to keep in mind</h3><p>Before the how-to, three rules (confirmed against the official docs):</p><ul><li><strong>You can self-create an export, but only into a bucket you own.</strong> A member account can create a CUR / Data Export by default; AWS requires the destination S3 bucket to be <strong>owned by the account that creates the export</strong> (<a href="https://docs.aws.amazon.com/cur/latest/userguide/cur-s3.html">AWS docs</a>).</li><li><strong>Export definitions can’t be read across accounts.</strong> You can’t ListExports / GetExport an export definition that lives in <strong>another</strong> account (there&#39;s no resource policy for it, and it isn&#39;t in AWS RAM). So you can&#39;t read the export definition sitting in the reseller&#39;s account.</li><li><strong>CUR 2.0 Data Exports can deliver output across accounts</strong> (<a href="https://aws.amazon.com/about-aws/whats-new/2026/03/aws-data-exports-cross-account-delivery-cost/">since 2026–03</a>). The reseller can write a CUR 2.0 export’s <strong>output files</strong> straight into your bucket — note that’s “delivering output,” not “sharing the definition.” <strong>Legacy CUR doesn’t support</strong> cross-account delivery.</li></ul><h3>Quick self-test: can you create your own export?</h3><p>In <strong>your own account</strong>, go to <strong>Billing and Cost Management → Data Exports</strong> and click <strong>Create</strong>.</p><ul><li><strong>You get into the create flow → Situation A</strong> (next section) — just build it yourself.</li><li><strong>You’re denied by an SCP / lack permission → Situation B</strong> — jump down to “Situation B.”</li></ul><h3>Situation A: create your own export (easiest)</h3><p>No reseller involved, all inside your own account:</p><ol><li>Open <strong>Billing and Cost Management → Data Exports → Create</strong> (<a href="https://docs.aws.amazon.com/cur/latest/userguide/creating-data-exports.html">AWS: creating data exports</a>);</li><li>Pick <strong>Standard data export (CUR 2.0)</strong> or <strong>FOCUS 1.0</strong>;</li><li>Set the destination to an <strong>S3 bucket in your own account</strong> (create one if needed — AWS adds the write policy for you);</li><li>Done — AWS writes the bill into that bucket daily.</li></ol><p><strong>In MOF:</strong> Add an AWS account → keep <strong>Data source method</strong> on the default <strong>Pick from list</strong> → enter your own account’s accessKey / secretKey → MOF lists the exports in your account, tick one and save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/0*LUuUWRcrcUJ-VZ2A.png" /></figure><p><em>“Data source method” has three options: Pick from list, Enter Export ARN, S3 bucket. Situation A uses the default, Pick from list.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PdeszjGhGvE3QbRQ.png" /></figure><p><em>MOF lists the CUR exports in your account (CUR 2.0 / FOCUS / Legacy) — tick one and save.</em></p><blockquote><em>This covers </em><strong><em>most people</em></strong><em>. Only if the self-test blocked you do you need Situation B below.</em></blockquote><h3>Situation B: blocked by an SCP — get the reseller to help</h3><p>If you can’t self-create, the reseller has to step in. Ordered best to fallback by “how much they’ll give you,” there are three:</p><h3>B-1: have the reseller deliver the export to your bucket (best, since 2026–03)</h3><p>The reseller creates a <strong>CUR 2.0</strong> export in their account and sets the <strong>destination S3 to your bucket</strong>. The files land in <strong>your own bucket</strong>, so you just read your own bucket — no cross-account reads at all.</p><ul><li><strong>Reseller side:</strong> when creating the export, set the destination to your bucket (your account ID as the owner + your bucket name);</li><li><strong>Your side:</strong> add the bucket policy below to <strong>your</strong> bucket to <strong>let the AWS Data Exports service write into it</strong>. ⚠️ Note the SourceArn / SourceAccount are the account that <strong>creates the export</strong> - i.e., the <strong>reseller&#39;s account ID</strong>, not yours:</li></ul><blockquote><em>This is the </em><a href="https://docs.aws.amazon.com/cur/latest/userguide/cur-s3.html"><em>official AWS policy template</em></a><em> — it grants </em><em>s3:PutObject only (write, not read or delete). Once set up, </em><strong><em>don&#39;t change this bucket policy or the bucket owner</em></strong><em>, or delivery breaks. In AWS China, swap </em><em>aws for </em><em>aws-cn and </em><em>us-east-1 for </em><em>cn-northwest-1.</em></blockquote><p><strong>In MOF:</strong> connect the same way as B-3 below — <strong>S3 bucket</strong> direct read — just point it at your own bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/0*WH3SBjRn_J2z7ymb.png" /></figure><p><em>Same as B-3: pick “S3 bucket” and fill the six values — just put your own bucket as the “S3 bucket.”</em></p><h3>B-2: the reseller hands you a scoped key (Enter Export ARN)</h3><p>For when the reseller is willing to issue a <strong>tightly scoped</strong> key in their account: it can read one specific export definition, plus the matching S3 prefix.</p><blockquote><em>Note: B-2 only works for a </em><strong><em>Standard data export (CUR 2.0 / FOCUS)</em></strong><em> — those have an ARN. Old-style </em><strong><em>Legacy CUR has no ARN</em></strong><em> (it’s identified by report name), so use B-3.</em></blockquote><p><strong>Ask the reseller to configure this</strong> (create an IAM user/role in their account with this policy):</p><p>The reseller gives you the <strong>key, Export ARN, and region</strong>. This key has GetExport but no ListExports - exactly enough, and it can&#39;t list anyone else&#39;s exports; the s3:ListBucket is also pinned to your prefix by the s3:prefix condition.</p><p><strong>In MOF:</strong> Add an AWS account → <strong>Data source method</strong> → <strong>Enter Export ARN</strong> → paste the Export ARN, click <strong>Verify &amp; use</strong>, and MOF echoes back the parsed bucket, table type, and format — check them, then save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/0*-GmxPvap3TS4_07g.png" /></figure><p><em>Pick “Enter Export ARN,” paste the ARN, click “Verify &amp; use,” and MOF echoes the parsed Name / type / table.</em></p><h3>B-3: the reseller grants S3 only (direct read)</h3><p>The reseller won’t give any CUR/Export API permission at all — only opens up the <strong>S3 where the bill files live</strong>. When several member accounts’ bills land in one bucket and only bucket access is granted, this is also the answer. B-1 (delivered to your own bucket) connects through this same path in MOF, just with your own bucket.</p><p>The reseller has two ways to open S3, pick one:</p><p><strong>① Add a bucket policy that allows your account</strong> (you read with your own key):</p><blockquote><em>⚠️ With a bucket policy (option ①), </em><strong><em>both sides</em></strong><em> must allow it: the bucket policy above (resource side) </em><strong><em>and</em></strong><em> the IAM on your own key must also allow </em><em>s3:GetObject / </em><em>s3:ListBucket on that external bucket. An admin-level key is usually fine; with a scoped key, remember to add those two S3 permissions, or it&#39;ll silently fail to read.</em></blockquote><p><strong>② Or the reseller issues a read-only S3 key in their account</strong> (same policy as ListCurFiles + GetCurFiles from B-2, minus GetExport). This is a <strong>one-sided</strong> grant - no need to touch your own IAM, so it&#39;s simpler if option ① is a hassle.</p><p>Either way, the reseller also has to <strong>tell you these values</strong> (you can’t see the export definition, so ask — or read them off your own bucket per the next section):</p><p><strong>In MOF:</strong> Add an AWS account → <strong>Data source method</strong> → <strong>S3 bucket</strong> → fill in those values (S3 bucket / Prefix / Export name / Region / Table type / File format). CUR 2.0 and FOCUS are supported today, in Parquet or CSV (gzip).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/0*ud2lFLGkUIo4hjXH.png" /></figure><p><em>Pick “S3 bucket” and fill: S3 bucket / Prefix / Export name / Region / Table type / File format.</em></p><h3>How to get these values in AWS</h3><p>For the B-2 Export ARN and the B-3 six values, the simplest way is to <strong>have the reseller run a CLI command in their account and send you the result</strong> (the console’s Data Export page doesn’t actually show the ARN). For B-1 (delivered to your own bucket), you run these yourself in your own account.</p><p><strong>① Get the Export ARN (for B-2):</strong> <strong>② Get all six S3 values at once (for B-3):</strong></p><p>The output fields map straight to the form: Bucket→S3 bucket, Prefix→Prefix, Name→Export name, Region→Region, Table ( COST_AND_USAGE_REPORT→CUR 2.0, FOCUS_1_0_AWS→FOCUS), Format ( PARQUET→Parquet, TEXT_OR_CSV→CSV).</p><blockquote><em>No CLI? You can still check by hand: find this path in the bucket, and if the Manifest is there, your values are right — </em><em>&lt;prefix&gt;/&lt;name&gt;/metadata/BILLING_PERIOD=YYYY-MM/&lt;name&gt;-Manifest.json (for FOCUS, lowercase it to </em><em>billing_period).</em></blockquote><h3>A message you can forward to your reseller (Situation B only)</h3><blockquote><em>I’m connecting a cost-analysis tool and need it to read my account’s AWS bill. Any of these three works (simplest first):</em></blockquote><blockquote><strong>Simplest:</strong> deliver my account’s CUR 2.0 export <strong>to my S3 bucket</strong> (cross-account delivery, supported since 2026–03), and I’ll read it myself;</blockquote><blockquote>Or, in your account, give me an IAM key scoped to bcm-data-exports:GetExport (my export) plus read-only on the matching S3 prefix, and send me the key, Export ARN, and region;</blockquote><blockquote>Or open up the S3 where the bill lives (add a bucket policy for my account, or issue a read-only S3 key), and tell me: bucket, my prefix, export name, region, table type (CUR 2.0 / FOCUS), and format (Parquet / CSV).</blockquote><blockquote><em>For options 2 and 3, a single </em><em>aws bcm-data-exports get-export --export-arn &lt;ARN&gt; in CloudShell dumps those values for you to send over.</em></blockquote><h3>After it’s connected</h3><p>Once the bill is in MOF, it’s <strong>split by </strong><strong>line_item_usage_account_id into each sub-account</strong> - so even if a dozen member accounts&#39; bills land in one bucket, you get a single view broken down by account and by service. That&#39;s exactly what a multi-sub-account reseller setup wants: no fiddling with accounts one by one, everything in one place.</p><blockquote><em>One heads-up: make sure the export / prefix you’re given </em><strong><em>contains only your own account</em></strong><em>. If you get the reseller’s full CUR (mixed with other customers), that data comes in too — so it’s best to export a separate copy, or use a prefix that holds only your account.</em></blockquote><h3>FAQ</h3><p><strong>I’m not the payer — can I create my own export?</strong> Usually yes. A member account can create its own CUR / Data Export by default (its own usage only), unless the reseller specifically blocks it with an SCP. Just try creating one under Billing and Cost Management → Data Exports to find out.</p><p><strong>I got a permission error creating the export — now what?</strong> That means the reseller used an SCP to restrict member accounts. Go to Situation B: have them deliver to your bucket, or give you a scoped key / open S3.</p><p><strong>The reseller will only grant S3 — does that work?</strong> Yes, use B-3 (S3 direct read). As long as you can read the bill files in the bucket, no CUR/Export API permission is needed.</p><p><strong>Which bill formats are supported?</strong> CUR 2.0 and FOCUS today, in Parquet or CSV (gzip). Go with CUR 2.0 or FOCUS; cross-account delivery to your bucket also only works for CUR 2.0.</p><p><strong>Anything different in AWS China (Ningxia / Beijing)?</strong> Same mechanics — just swap the ARN partition and region: aws → aws-cn, us-east-1 → cn-northwest-1 (and the CLI --region likewise).</p><p><em>Current as of August 2026. AWS Data Exports / CUR setup and permissions may change over time — check the official AWS docs and your own environment.</em></p><p><em>Originally published at </em><a href="https://mofcloud.com/blog/2026-08-22-aws-reseller-cost-analysis"><em>https://mofcloud.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26fb6a71b316" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is AI cheaper than hiring people? The real cost in China (2026)]]></title>
            <link>https://medium.com/@mofcloud/is-ai-cheaper-than-hiring-people-the-real-cost-in-china-2026-521eac64d858?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/521eac64d858</guid>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Sat, 22 Aug 2026 14:19:43 GMT</pubDate>
            <atom:updated>2026-08-22T14:19:43.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*Tq4Dft8dYuQJuwzAJQ-F0w.png" /></figure><p>A founder with ¥10M in annual revenue does the math: payroll is the big line item, AI is clearly where things are headed, so cut a few roles, hand the work to AI, and the savings should follow. Right?</p><p>That’s almost everyone’s default assumption — replace people with AI, spend less. Token prices really are low. But that’s the smallest cell on the bill. What actually decides whether you save is five costs you can’t see. This post runs the numbers with <strong>Chinese salaries and Chinese model prices</strong>, using one engineering team as the example.</p><h3>The short answer</h3><ul><li><strong>Token prices really are low.</strong> The cheap Chinese models cost roughly 1–3% of GPT-4o’s per-token output price, and even the domestic flagships undercut GPT-4o and Claude several times over.</li><li><strong>Whether you actually save depends on five hidden costs:</strong> someone has to watch the AI, your team has to be good at using it, the switch itself is painful, the smartest models keep getting pricier, and the people who make AI work well are scarce and expensive.</li><li><strong>The answer is different in China than in the US.</strong> The American “AI is cheaper” pieces stack it up against reviewers who cost tens of dollars an hour. In China, that review labor is far cheaper — and the models are cheaper too. Both sides of the equation change, so the conclusion changes.</li><li><strong>Bottom line:</strong> where labor is cheap, the right <em>mix</em> usually beats outright <em>replacement</em> — especially for small companies. Replacing people with AI rarely erases the human cost; more often it just moves it to a pricier, harder-to-hire role.</li></ul><h3>How cheap are the tokens, really?</h3><p>Let’s settle this first, because it’s true. Prices below are from each vendor’s official page, <strong>as of August 2026</strong> (¥ per 1M tokens; these move fast, so check the source):</p><ul><li><strong>Cheap workhorses</strong> — Qwen flash, Doubao flash, GLM Air, Ernie Turbo: input ¥0.15–0.8, output ¥0.8–3.2, with several offering a free tier.</li><li><strong>Domestic flagships</strong> — DeepSeek, GLM, Doubao top models: output around ¥13–30.</li><li><strong>Overseas benchmark</strong> — GPT-4o output ~¥72, Claude Sonnet ~¥108.</li></ul><p>Run a batch of routine tasks and the model line might cost you a few cups of coffee. So yes, tokens are cheap. The catch: it’s the smallest line on the bill. The next five are where the money actually goes.</p><p>AI works fast and cheap, but it also gets things wrong — a lot. Any task where a mistake is expensive and hard to undo needs a human watching.</p><ul><li><strong>The rule:</strong> let a human watch only when the cost of watching is less than the cost of a mistake.</li><li><strong>Safe to automate:</strong> high-volume, low-risk work (internal drafts, tagging) — hand it fully to AI.</li><li><strong>Can’t drop the human:</strong> anything customer-facing, financial, compliance-related, or that changes a live system.</li><li><strong>Don’t forget:</strong> reviewers, annotators, and support staff in China run about ¥25–65/hour — cheap, but not zero. The more AI does, the more there is to review, so this bill grows with usage.</li></ul><p>Buying AI isn’t the same as using it well.</p><ul><li><strong>Used ≠ got value:</strong> over 90% of white-collar workers have used AI (<a href="http://m.cyol.com/gb/articles/2025-05/17/content_ajYw2OiBVx.html">Maimai 2025</a>), but among the ~46% of Chinese companies scaling generative AI, only about 9% capture real value (<a href="https://www.accenture.cn/cn-zh/insights/china-digital-transformation-index-2025-release">Accenture 2025</a>).</li><li><strong>Closing that gap costs money:</strong> the skills gap is the top barrier (McKinsey); training one person runs roughly ¥3,500–20,000 (estimated from course list prices — no reliable national average exists).</li><li><strong>The payoff goes to the skilled:</strong> one case reports ~+11% R&amp;D efficiency (<a href="https://www.cnblogs.com/alisystemsoftware/p/18597663">Alibaba Cloud</a>, vendor figure) — but only for teams that know how to use it.</li></ul><p>Cut staff, switch to AI, and payroll looks great immediately. Then the next six months tend to hurt — people leave, knowledge walks out the door, production breaks, shipping slows. Economists call this the <strong>productivity J-curve</strong> (Brynjolfsson et al., NBER 2018): output usually dips before it rises, and you have to cross the trough first.</p><p>Illustrative math on the ¥10M-revenue company (scenario estimate, not measured):</p><ul><li><strong>Lost knowledge:</strong> replacing one person costs about 0.5–2× their annual salary (<a href="https://www.gallup.com/workplace/247391/fixable-problem-costs-businesses-trillion.aspx">Gallup 2019</a>).</li><li><strong>Churn during the rough patch:</strong> slower shipping plus a few incidents. Lose even 5–15% of half a year’s revenue and that’s <strong>¥250k-750k</strong>.</li><li><strong>For comparison:</strong> a year of token savings might be a few tens of thousands.</li></ul><blockquote><em>One painful transition can eat ten times what you saved on tokens.</em></blockquote><p>Worth noting: transformations don’t win just by starting. Only about 16% improve performance and keep the gains ( <a href="https://www.mckinsey.com/capabilities/people-and-organizational-performance/our-insights/unlocking-success-in-digital-transformations">McKinsey</a>). The popular “70% of transformations fail” line has no solid source — ignore it — but “success is the exception” holds up.</p><h3>Hidden cost 4: the smarter the model, the more it costs — and the more tokens it burns</h3><p>“AI just keeps getting cheaper” is half right.</p><ul><li><strong>The true half:</strong> for a fixed capability, prices are falling hard (Zhipu’s GLM flagship went from ¥50 to ¥5 per million in half a year).</li><li><strong>The other half — your bill still climbs, for two reasons:</strong></li><li>people default to the strongest model for everything, paying a premium on every task;</li><li>smarter models burn far more tokens (they reason at length, or take multi-step actions on their own) — a single task can cost several, even dozens of times what a plain model would.</li><li><strong>In one line:</strong> the price of “smart” is dropping, yet your bill keeps rising.</li><li><strong>The way out:</strong> give a cheap model good scaffolding (route by task, add a knowledge base, add automated checks) so it can hold its own against a smart one — except almost nobody does the work, and that’s hidden cost 5.</li></ul><h3>Hidden cost 5: the people who make AI work are scarce and expensive</h3><p>The way out above — build scaffolding so a cheap model does a smart model’s job — is itself scarce, expensive labor.</p><ul><li><strong>Scarce:</strong> engineers who can build this (routing, knowledge bases, evals, agent workflows) are thin on the ground. The supply/demand ratio for LLM-algorithm roles is about 0.17 — roughly six openings per candidate (Liepin 2025).</li><li><strong>Expensive:</strong> new LLM-algorithm postings average ¥70,107/month (<a href="https://www.nbd.com.cn/articles/2025-03-25/3804085.html">NBD 2025</a>); AI scientists ~¥127k/month; Beijing pegs a median “AI model architect” at ¥42k/month.</li><li><strong>Growing your own isn’t cheap either:</strong> it’s slow and costly, and once trained they get poached (add another replacement cost).</li><li><strong>It cuts both ways:</strong> don’t build, and you pay the “use the strongest model” premium on every task forever; do build, and you sink a large, scarce-talent cost up front, betting it pays back in lower token bills.</li></ul><h3>A worked example: an engineering team adopts AI</h3><p>The five costs get concrete inside one scenario. Say a 10-person backend team (1 lead, 6 mid/senior, 3 junior), roughly ¥300k/month in payroll. The plan: adopt AI coding, cut the 3 juniors, save ¥60k/month.</p><p>What you save:</p><ul><li><strong>Tokens are pocket change.</strong> Ten people coding on a cheap Chinese model might spend ¥1,000–3,000/month on tokens.</li><li><strong>The productivity lift is real</strong> — if the team knows how to use it (see the +11% case).</li></ul><p>What you add:</p><ul><li><strong>Cost 4 — default to the strongest overseas model plus agents,</strong> and the token bill can jump from a few thousand to ¥10k-30k/month.</li><li><strong>Cost 1 — AI code needs review.</strong> Mid/senior engineers spend more time each day checking AI’s output, eating into the gains.</li><li><strong>Cost 2 — a team that can’t use it well</strong> captures almost none of the +11%, and may create noise.</li><li><strong>Cost 3 — the 3 cut juniors owned modules nobody else understands,</strong> so bugs and slow shipping follow. Lose a customer or refund a contract and it can dwarf the ¥360k saved over six months.</li><li><strong>Cost 5 — to make a cheap model reliably write your code</strong> (instead of brute-forcing it with an expensive one) you need someone to set internal conventions, build a knowledge base, and add automated checks. That person costs ¥340–560/hour and is hard to hire.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*XagwOUXjc_gIdFv2YRmu0Q.png" /></figure><p>The tally: tokens are the small money. The real spend lands in review hours, training, the transition dip, and that scarce person who builds the scaffolding. <strong>The +11% lift is real — but it’s a reward for teams that build and use AI well, not a rebate you collect by cutting headcount.</strong></p><h3>A cost ladder: replacing people often just moves the cost up</h3><p>Put those labor costs side by side (fully-loaded hourly ≈ monthly ×1.4 ÷ 174, covering social insurance and overhead; the same role varies a lot by city and seniority, so these are order-of-magnitude bands from job-posting data, treated as approximate):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*tOQG2C0zhGdxffVfapg-TA.png" /></figure><p>Here’s the point: you drop a few ¥25–65/hour review seats, but often need one ¥340–560/hour engineer to make the AI actually run. Replacing people with AI frequently doesn’t erase the human cost — it moves it up to a pricier, harder-to-hire tier. Whether that pays depends on your volume and company size, not on how cheap the tokens are.</p><p>(Note: this compares <em>hourly rates</em>, not a claim that one AI engineer replaces several reviewers. Small companies often hire no scaffolding role at all — the founder absorbs that cost as their own time.)</p><h3>So how should you mix it? By company size</h3><p>The question was never “AI or people.” It’s: which task, at what volume, with a team of what skill level, at what size of company. A framework:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*9E4Xd8bXvQeurYAH4Gjs5g.png" /></figure><p>Two more axes sharpen the call. <strong>Reversibility:</strong> if a mistake can’t be undone, is customer-facing, or high-risk, keep a human on it; if it’s editable, internal, and low-risk, automate. <strong>Volume:</strong> at low volume people are often cheaper (no setup or review overhead); only past a certain scale does AI’s per-unit edge win out.</p><p>For small companies the takeaway is sharpest: you can’t afford the scaffolding role and you’re the most tempted to default to the priciest model — so lean on AI as an amplifier, keep the mix light, and don’t try a replacement you can’t sustain.</p><h3>A few suggestions</h3><ul><li><strong>Measure before you move.</strong> Know where your tokens go — which product, model, and task — before you optimize. You can’t cut a cost you can’t see.</li><li><strong>Pick the model per task; don’t default to the strongest.</strong> Save the flagship for genuinely hard work.</li><li><strong>Keep a human on the irreversible stuff;</strong> fully automate only the high-volume, reversible work.</li><li><strong>Don’t lead with layoffs.</strong> Let your existing people do more with AI, watch a quarter or two, then decide on headcount.</li><li><strong>Treat the productivity lift as a capability to build, not a feature to buy.</strong> Train people, build the knowledge base — the +11% goes to teams that can use it.</li></ul><h3>Before you decide any of this, make the bill visible</h3><p>All five hidden costs share a trait: most of them are invisible. Which product, model, or task is driving your AI spend? Which slice is quietly climbing? Most teams can’t say — and a cost you can’t see is a cost you can’t cut.</p><p>That’s why we build <a href="https://www.mofcloud.com/">MofCloud</a>: to make cloud and AI spend visible and attributable — Alibaba, Tencent, Huawei, Volcengine, Baidu, plus AWS, Azure, and GCP in one view, with the token cost of DeepSeek, Qwen, GLM, and Kimi in the same picture. Turn the hidden bills into visible ones first; optimization comes after. Once the numbers are in front of you, whether to replace people with AI is your call.</p><h3>FAQ</h3><p><strong>Is AI actually cheaper than people?</strong> On tokens alone, yes. Add human review, training, the transition dip, and scaffolding talent, and it’s not a given. High-volume, reversible work favors AI; low-volume, high-risk, judgment work often favors people.</p><p><strong>Why is the answer different in China than in US articles?</strong> US pieces compare against reviewers costing tens of dollars an hour; in China that work runs tens of RMB an hour, and the models are cheaper too. With both sides lower, the break-even point moves — where labor is cheap, mixing usually beats replacing.</p><p><strong>Should a small company replace people with AI?</strong> Better to treat AI as an amplifier than a replacement. Small companies carry the largest transition risk relative to revenue and can least afford scarce scaffolding talent. Cheap models and self-serve tools that help your existing people do more are the safer bet.</p><p><strong>Why does the bill rise even as per-token prices fall?</strong> Because people default to the smartest model, and smarter models burn several times the tokens per task (they reason at length and run their own steps). Unit price drops, per-task consumption rises faster, so the bill goes up. The fix is routing by task plus good scaffolding.</p><p><em>Current as of August 2026. Model prices and salary bands move quickly — check each vendor’s official page and current hiring data. Figures marked “illustrative” or “estimated” are scenario math, not measured results. Check against your own business before deciding.</em></p><p><em>Originally published at </em><a href="https://mofcloud.com/blog/2026-08-22-ai-vs-human-cost-china"><em>https://mofcloud.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=521eac64d858" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FinOps tools for Chinese clouds (2026)]]></title>
            <link>https://medium.com/@mofcloud/finops-tools-for-chinese-clouds-2026-2f76c64ec4b2?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f76c64ec4b2</guid>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Thu, 20 Aug 2026 13:00:26 GMT</pubDate>
            <atom:updated>2026-08-20T13:00:26.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*ACfzK9-NkeWpmclK6l-Nlg.png" /></figure><p>If you run workloads on Alibaba Cloud, Tencent Cloud, Volcengine, or Huawei Cloud and you went looking for a FinOps tool, you probably hit a wall fast. The well-known cloud cost platforms are built around AWS, Azure, and Google Cloud — and quietly stop there.</p><p>This is the honest 2026 landscape, with the caveats that most “top FinOps tools” listicles skip.</p><h3>The short answer</h3><ul><li><strong>Western FinOps tools barely touch Chinese clouds.</strong> At best they reach<strong>Alibaba Cloud</strong> — and even that is rare and often partial. <strong>None of them</strong> support<strong>Tencent Cloud, Huawei Cloud, Volcengine, or Baidu Cloud.</strong></li><li><strong>Chinese platforms do cover those clouds</strong> (and usually AWS/Azure too) — but they’re<strong>heavy cloud-management (CMP) / MSP platforms</strong>, sold enterprise-first and deployed by integrators.</li><li><strong>Each cloud’s native tool</strong> (e.g. Alibaba Cost Manager) is free but only sees its own cloud.</li></ul><p>So the real question isn’t “which is the best FinOps tool” — it’s “which one even speaks the clouds you actually run on, without a heavy enterprise rollout.”</p><h3>Comparison at a glance</h3><p>Two things matter as much as the feature list. First, <strong>where the tool is from</strong> — a US or Israeli FinOps tool usually can’t connect to Chinese clouds at all. Second, <strong>what kind of tool it is</strong>: a pure <em>FinOps</em> tool is focused on cost, while a <em>CMP</em> (cloud-management platform), <em>MSP</em> (managed service), or <em>AIOps</em> (automated-operations) platform folds cost into a much larger suite — which usually means heavier deployment and enterprise-only sales.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*VI7QYzAv8dhMysd9mllBXQ.png" /></figure><p><strong>✓</strong> supported · <strong>◐</strong> partial (see the tool’s notes) · <strong>✗</strong> not supported. Per-tool details — exactly which clouds, pricing, and self-host — are in the sections below.</p><p>The bottom line: <strong>none of the mainstream Western tools we checked read the full Chinese cloud stack.</strong> The best any of them manage is Alibaba — natively in CloudHealth, via CSV in Finout, list-price-only in Kubecost — while Tencent, Huawei, Volcengine, and Baidu appear nowhere on the Western side.</p><h3>The Western FinOps tools, one by one</h3><p>Excellent products for a US-cloud stack — with Chinese-cloud support ranging from <em>none</em> to <em>one cloud, partially</em>.</p><h4><a href="https://www.vantage.sh/">Vantage</a></h4><p>The developer’s FinOps tool: transparent pricing, a free tier, and the broadest catalog of integrations (cloud + SaaS + AI vendors), plus an open-source MCP server for agent-driven cost work.</p><ul><li>Founded: 2020</li><li>Chinese clouds: None (you could import via a custom FOCUS/CSV provider, but there’s no native connector)</li><li>Pricing: Free up to $2,500 tracked spend; Pro $30/mo; Business $200/mo; Enterprise custom</li><li>Self-host: SaaS; only the MCP server is open source</li><li>Best for: developer-led teams on AWS/Azure/GCP who want self-serve, transparent FinOps</li><li>Watch out: no Chinese clouds; the core platform is SaaS-only</li></ul><h4><a href="https://www.cloudzero.com/">CloudZero</a></h4><p>Unit-economics FinOps — cost per customer, per feature, per product — aimed at engineering teams rather than finance reports, with heavy Kubernetes and AI/LLM spend focus.</p><ul><li>Founded: 2016</li><li>Chinese clouds: None</li><li>Pricing: custom quote; no public price, no free tier</li><li>Self-host: SaaS only</li><li>Best for: SaaS and engineering orgs that want cost tied to business units</li><li>Watch out: no Chinese clouds; opaque enterprise pricing</li></ul><h4><a href="https://www.ibm.com/products/cloudability">Cloudability</a> (IBM Apptio)</h4><p>The mature enterprise suite — deep AWS Reserved Instance / Savings Plan optimization, rightsizing, and showback/chargeback, part of the Apptio TBM portfolio now under IBM.</p><ul><li>Founded: Cloudability 2011 (Apptio 2007)</li><li>Chinese clouds: None (an open IBM feature request to <em>add</em> Alibaba confirms it isn’t supported)</li><li>Pricing: custom enterprise quote; no free tier</li><li>Self-host: SaaS only</li><li>Best for: large enterprises standardized on AWS/Azure/GCP</li><li>Watch out: no Chinese clouds; enterprise-only, heavyweight</li></ul><h4><a href="https://www.nops.io/">nOps</a></h4><p>AWS-first optimization and automation — automated commitment/rate management (RIs, Savings Plans, Spot), with a “don’t save, don’t pay” model.</p><ul><li>Founded: 2017</li><li>Chinese clouds: None</li><li>Pricing: flat fee for visibility + share-of-savings for optimization</li><li>Self-host: SaaS only</li><li>Best for: AWS-heavy teams that want automated rate optimization</li><li>Watch out: AWS-centric; no Chinese clouds</li></ul><h4><a href="https://www.finout.io/">Finout</a></h4><p>Multi-cloud allocation and visibility built on patented Virtual Tagging — its “MegaBill” unifies cloud + Kubernetes + SaaS/AI spend for 100% showback.</p><ul><li>Founded: 2020 (public launch 2021)</li><li>Chinese clouds: Alibaba is listed, but appears to be a CSV/custom-cost import, not a native billing connector; no Tencent/Huawei/Volcengine</li><li>Pricing: flat annual fee by committed spend tier (not % of spend, unlimited users)</li><li>Self-host: SaaS only</li><li>Best for: multi-cloud allocation and chargeback at scale</li><li>Watch out: its only Chinese-cloud path is CSV; no self-host</li></ul><h4><a href="https://www.vmware.com/products/app-platform/tanzu-cloudhealth">CloudHealth</a> (Broadcom / VMware Aria Cost)</h4><p>The closest exception: a broad multi-cloud FinOps and governance platform with native Alibaba Cloud support, now under Broadcom and rebranding toward VMware Aria Cost.</p><ul><li>Founded: 2012</li><li>Chinese clouds: Alibaba Cloud — natively supported. Tencent/Huawei/Volcengine/Baidu — not</li><li>Pricing: percentage of spend / partner quote (sold largely via partners)</li><li>Self-host: SaaS only</li><li>Best for: large enterprises that need Alibaba plus Western clouds in one governance suite</li><li>Watch out: Alibaba is the <em>only</em> Chinese cloud it covers; enterprise/partner-sold and heavy</li></ul><h4><a href="https://spot.io/">Spot by Flexera</a></h4><p>Compute and Kubernetes optimization automation — Elastigroup for Spot/VM management and Ocean for K8s node autoscaling. Flexera acquired NetApp’s Spot portfolio in 2025.</p><ul><li>Founded: 2015 (as Spotinst)</li><li>Chinese clouds: None</li><li>Pricing: savings-based</li><li>Self-host: SaaS only</li><li>Best for: teams automating compute/Kubernetes cost on Western clouds</li><li>Watch out: no Chinese clouds; optimization automation, not broad visibility</li></ul><h4><a href="https://www.kubecost.com/">Kubecost</a> (IBM)</h4><p>Kubernetes-native cost allocation (namespace/label/pod), with out-of-cluster cloud cost via billing APIs. Free and self-hostable through the OpenCost (CNCF) project.</p><ul><li>Founded: 2019</li><li>Chinese clouds: Alibaba — list-price estimation only, not full billing</li><li>Pricing: free self-hosted / OSS tier; enterprise is a custom quote</li><li>Self-host: yes — a core strength (OpenCost is Apache-2.0)</li><li>Best for: Kubernetes cost allocation</li><li>Watch out: K8s-centric; Alibaba support is list-price only</li></ul><h4><a href="https://www.prosperops.com/">ProsperOps</a></h4><p>Autonomous commitment management — it actively manages your RI/Savings-Plan/CUD portfolio to maximize savings, priced on results.</p><ul><li>Founded: 2018</li><li>Chinese clouds: None</li><li>Pricing: a percentage of <em>realized savings</em> (not of spend)</li><li>Self-host: SaaS only</li><li>Best for: automating discounts on AWS/Azure/GCP</li><li>Watch out: no Chinese clouds; narrow scope (commitments, not full FinOps)</li></ul><h3>The Chinese platforms</h3><p>Chinese vendors read the clouds Western tools miss — Alibaba, Tencent, Huawei, Volcengine — and several read AWS/Azure/GCP too. They range from lightweight, cost-native tools to heavy CMP/MSP suites.</p><h4><a href="https://mofcloud.com/">MofCloud</a></h4><p>Full disclosure: this is our blog. We built MofCloud for the gap the table leaves open — teams on Chinese clouds (often <em>plus</em> AWS/GCP for overseas) who want FinOps that’s light, not a platform an integrator has to stand up.</p><ul><li>Chinese clouds: Alibaba, Tencent, Huawei, Volcengine, Baidu — the full stack</li><li>Overseas: AWS, Azure, GCP — all normalized into one view</li><li>Pricing: Subscription (self-serve) and Enterprise</li><li>Self-host: yes; your billing data can stay in your environment</li><li>Best for: teams that want Chinese-cloud FinOps without CMP/MSP weight</li><li>Coming soon: Mofis, our cloud-architect Agent, which will read your live bills and name the specific move to make — plus Chinese AI-model cost tracking (DeepSeek, Qwen, GLM, Kimi). Join the waitlist below.</li></ul><p>Put simply: the coverage of a Chinese platform, the developer experience of Vantage, minus the weight — with a cloud-architect Agent on the way.</p><h4><a href="https://www.cloudchef.io/">CloudChef</a> (骞云, SmartCMP)</h4><p>A full cloud-management suite — governance, automation, CMDB — with FinOps as one module. Per its own site, it manages a wide stack: Alibaba, Tencent, Huawei, Kingsoft, and UCloud, plus AWS, Azure, and Google Cloud, private clouds (VMware, OpenStack, QingCloud), and Kubernetes.</p><ul><li>Best for: large groups that want one platform to govern and automate many clouds</li><li>Watch out: FinOps is one piece of a heavy CMP; enterprise deployment</li></ul><h4><a href="https://www.pancloud.com.cn/">PanCloud</a> (联蔚盘云)</h4><p>FinOps depth plus MSP services, with strong practice managing AWS and Azure cost for large and global-500 clients.</p><ul><li>Best for: enterprises that want a managed-service partner for cost governance</li><li>Watch out: MSP-led model; sales cycle and services engagement</li></ul><h4><a href="https://www.itqm.com/">Qimo</a> (奇墨科技)</h4><p>An AIOps + FinOps platform (ITQM): smart IT operations bundled with cost visibility, allocation, and forecasting, plus full-cloud management and MSP services. It was the first to pass CAICT’s hybrid multi-cloud FinOps assessment.</p><ul><li>Best for: enterprises wanting cost management inside a broader IT-ops suite</li><li>Watch out: FinOps is one module of a broad AIOps/IT-ops platform; enterprise-oriented</li></ul><h4><a href="https://www.lccomputing.com/">LCComputing</a> (贝联珠贯)</h4><p>An AI-native operations company founded by an ex-Alibaba architect. Its LCC line handles multi-cloud cost and compute optimization (Cost Explorer, Optimizer), alongside SREAgent, an L4 autonomous-ops product. Alibaba led its recent funding.</p><ul><li>Best for: teams that want cost + compute optimization tied to automated ops</li><li>Watch out: cost is one part of an AIOps / compute-optimization platform, not a standalone FinOps tool</li></ul><h4><a href="https://www.canway.net/">Canway</a> (嘉为科技)</h4><p>A multi-cloud management platform strong on Alibaba, Tencent, and Huawei, aimed at large groups that need one governance view across clouds.</p><ul><li>Best for: large enterprises consolidating Chinese-cloud management</li><li>Watch out: CMP-scale; FinOps is part of a broader ops suite</li></ul><h3>The native cloud tools</h3><p>Every major Chinese cloud ships a free cost console — Alibaba Cost Manager, Tencent and Volcengine billing centers, and so on. They’re accurate for that one cloud, but can’t give you a single view across clouds, cross-cloud allocation, or a normalized picture when you run on more than one.</p><h3>How to actually choose</h3><p>Cut through the listicles with five questions:</p><ol><li>Which of <em>your</em> clouds does it read natively? Tencent, Volcengine, Huawei specifically — not “multi-cloud” in the abstract.</li><li>Report only, or recommend too? A dashboard tells you <em>what</em> you spent; the harder value is <em>what to do about it</em>.</li><li>How heavy is it to run? Self-serve and self-hostable, or a CMP rollout with an integrator?</li><li>How is it priced? Transparent tiers vs a percentage of spend vs an enterprise-only quote.</li><li>Does it cover your AI-model spend? DeepSeek, Qwen, GLM, and Kimi tokens are part of the bill now too.</li></ol><h3>Frequently asked questions</h3><p><strong>Does Vantage support Alibaba Cloud?</strong> No. Vantage covers AWS, Azure, Google Cloud, Oracle Cloud, and Kubernetes plus many SaaS/AI vendors, but no Chinese clouds natively.</p><p><strong>Which FinOps tool supports Tencent Cloud, Huawei Cloud, or Volcengine?</strong> Among the well-known Western tools, none as of 2026. Chinese platforms (CloudChef, PanCloud, etc.) and MofCloud do.</p><p><strong>Does any Western tool support Alibaba Cloud?</strong> CloudHealth (Broadcom) supports it natively; Finout ingests it via CSV; Kubecost shows Alibaba list prices only. The rest do not.</p><p><strong>Do I need a big enterprise platform to do FinOps on Chinese clouds?</strong> No — that’s the gap MofCloud fills: Chinese-cloud coverage without the CMP/MSP weight.</p><p><em>Landscape as of {August 2026}. Cloud-cost tools change fast — pricing, cloud coverage, and ownership especially — so treat the specifics as a snapshot and check each vendor’s current docs before you commit.</em></p><p><em>Originally published at </em><a href="https://mofcloud.com/blog/2026-08-21-finops-tools-for-chinese-clouds"><em>https://mofcloud.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f76c64ec4b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[rk-boot/v2: Error model design in Go]]></title>
            <link>https://medium.com/@mofcloud/rk-boot-v2-error-model-design-in-go-c6fbbdcbabb6?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6fbbdcbabb6</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[rk-boot]]></category>
            <category><![CDATA[error-handling]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Sun, 19 Jun 2022 13:01:44 GMT</pubDate>
            <atom:updated>2022-06-19T13:01:44.607Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXOHmKPTruMZrp8jG7nLDw.png" /></figure><p>It is always not easy to define a user-friendly API. However, errors could happen anywhere.</p><p>In order to return standard error type to user, it is <strong>important</strong> to define an error type.</p><p>We introduce <a href="https://github.com/rookie-ninja/rk-boot"><strong>rk-boot/v2</strong></a> which is a library to create Golang micro-service from YAML file. It contains a convenient way to define error builder from YAML.</p><h3>Introduction</h3><p>We will use <a href="https://github.com/rookie-ninja/rk-boot"><strong>rk-boot/v2</strong></a><strong> </strong>to start <a href="https://github.com/gin-gonic/gin"><strong>gin-gonic/gin</strong></a> micro-service for demonstration.</p><p>By default, panic middleware will handle unexpected panic and respond with google style error format:</p><ul><li>Google style</li></ul><pre><strong>{</strong><br>  <strong>&quot;error&quot;:{</strong><br>    <strong>&quot;code&quot;:500,</strong><br>    <strong>&quot;status&quot;:</strong>&quot;Internal Server Error&quot;<strong>,</strong><br>    <strong>&quot;message&quot;:</strong>&quot;Panic occurs&quot;<strong>,</strong><br>    <strong>&quot;details&quot;:[</strong><br>      &quot;panic manually&quot;<br>    <strong>]</strong><br>  <strong>}</strong><br><strong>}</strong></pre><ul><li>Amazon style</li></ul><pre><strong>{</strong><br>    <strong>&quot;response&quot;:{</strong><br>        <strong>&quot;errors&quot;:[</strong><br>            <strong>{</strong><br>                <strong>&quot;error&quot;:{</strong><br>                    <strong>&quot;code&quot;:500,</strong><br>                    <strong>&quot;status&quot;:</strong>&quot;Internal Server Error&quot;<strong>,</strong><br>                    <strong>&quot;message&quot;:</strong>&quot;Panic occurs&quot;<strong>,</strong><br>                    <strong>&quot;details&quot;:[</strong><br>                        &quot;panic manually&quot;<br>                    <strong>]</strong><br>                <strong>}</strong><br>            <strong>}</strong><br>        <strong>]</strong><br>    <strong>}</strong><br><strong>}</strong></pre><ul><li>Custom style: see examples bellow.</li></ul><h4>Docs</h4><ul><li><a href="https://github.com/gin-gonic/gin"><strong>gin-gonic/gin</strong></a>: <a href="https://docs.rkdev.info/cn/docs/rk-boot/user-guide/gin/advanced/error-type/">Official docs</a></li><li><a href="https://grpc.io/docs/languages/go/"><strong>gRPC</strong></a>: <a href="https://docs.rkdev.info/cn/docs/rk-boot/user-guide/grpc/advanced/error-type/">Official docs</a></li><li><a href="https://github.com/labstack/echo"><strong>labstack/echo</strong></a>: <a href="https://docs.rkdev.info/cn/docs/rk-boot/user-guide/echo/advanced/error-type/">Official docs</a></li><li><a href="https://github.com/gogf/gf"><strong>gogf/gf</strong></a>: <a href="https://docs.rkdev.info/cn/docs/rk-boot/user-guide/gf/advanced/error-type/">Official docs</a></li><li><a href="https://github.com/gofiber/fiber"><strong>gofiber/fiber</strong></a>: <a href="https://docs.rkdev.info/cn/docs/rk-boot/user-guide/fiber/advanced/error-type/">Official docs</a></li><li><a href="https://github.com/zeromicro/go-zero"><strong>zeromicro/go-zero</strong></a>: <a href="https://docs.rkdev.info/cn/docs/rk-boot/user-guide/zero/advanced/error-type/">Official docs</a></li><li><a href="https://github.com/gorilla/mux"><strong>gorilla/mux</strong></a>: <a href="https://docs.rkdev.info/cn/docs/rk-boot/user-guide/mux/advanced/error-type/">Official docs</a></li></ul><h3>Quick start</h3><h4>1. Install</h4><pre>$ go get github.com/rookie-ninja/rk-boot/v2<br>$ go get github.com/rookie-ninja/rk-gin/v2</pre><h4>2. Create boot.yaml</h4><pre><strong>gin:</strong><br>  - <strong>name:</strong> greeter<br>    <strong>port:</strong> <strong>8080</strong><br>    <strong>enabled:</strong> <strong>true</strong></pre><h4>3. Create main.go</h4><pre>package main<br><br>import (<br>   &quot;context&quot;<br>   &quot;github.com/gin-gonic/gin&quot;<br>   &quot;github.com/rookie-ninja/rk-boot/v2&quot;<br>   &quot;github.com/rookie-ninja/rk-entry/v2/error&quot;<br>   &quot;github.com/rookie-ninja/rk-gin/v2/boot&quot;<br>   &quot;net/http&quot;<br>)<br><br>func main() {<br>   // Create a new boot instance.<br>   boot := rkboot.NewBoot()<br>   <br>   // Register handler<br>   entry := rkgin.GetGinEntry(&quot;greeter&quot;)<br>   entry.Router.GET(&quot;/v1/greeter&quot;, Greeter)<br><br>   // Bootstrap<br>   boot.Bootstrap(context.TODO())<br><br>   boot.WaitForShutdownSig(context.TODO())<br>}<br><br>func Greeter(ctx *gin.Context) {<br>   err := rkmid.GetErrorBuilder().New(http.StatusAlreadyReported, &quot;Trigger manually!&quot;,<br>      &quot;This is detail.&quot;,<br>      false, -1,<br>      0.1)<br><br>   ctx.JSON(http.StatusAlreadyReported, err)<br>}</pre><h4>4. Validate</h4><pre>$ curl &quot;localhost:8080/v1/greeter?name=rk-dev&quot;<br>{<br>    &quot;error&quot;:{<br>        &quot;code&quot;:208,<br>        &quot;status&quot;:&quot;Already Reported&quot;,<br>        &quot;message&quot;:&quot;Trigger manually!&quot;,<br>        &quot;details&quot;:[<br>            &quot;This is detail.&quot;,<br>            false,<br>            -1,<br>            0.1<br>        ]<br>    }<br>}</pre><h3>Amazon style</h3><ul><li>boot.yaml</li></ul><pre><strong>gin:</strong><br>  - <strong>name:</strong> greeter<br>    <strong>port:</strong> <strong>8080</strong><br>    <strong>enabled:</strong> <strong>true</strong><br>    <strong>middleware:</strong><br>      <strong>errorModel:</strong> amazon</pre><p><strong>Result:</strong></p><pre><strong>{</strong><br>    <strong>&quot;response&quot;:{</strong><br>        <strong>&quot;errors&quot;:[</strong><br>            <strong>{</strong><br>                <strong>&quot;error&quot;:{</strong><br>                    <strong>&quot;code&quot;:208,</strong><br>                    <strong>&quot;status&quot;:</strong>&quot;Already Reported&quot;<strong>,</strong><br>                    <strong>&quot;message&quot;:</strong>&quot;Trigger manually!&quot;<strong>,</strong><br>                    <strong>&quot;details&quot;:[</strong><br>                        &quot;This is detail.&quot;<strong>,</strong><br>                        <strong>false,</strong><br>                        <strong>-1,</strong><br>                        <strong>0.1</strong><br>                    <strong>]</strong><br>                <strong>}</strong><br>            <strong>}</strong><br>        <strong>]</strong><br>    <strong>}</strong><br><strong>}</strong></pre><h3>Custom style</h3><p>User can register custom error builder and register it into Entry.</p><p>Please implement bellow interface.</p><pre><strong>type</strong> ErrorInterface <strong>interface</strong> <strong>{</strong><br>	Error<strong>()</strong> <strong>string</strong><br><br>	Code<strong>()</strong> <strong>int</strong><br><br>	Message<strong>()</strong> <strong>string</strong><br><br>	Details<strong>()</strong> <strong>[]interface{}</strong><br><strong>}</strong><br><br><strong>type</strong> ErrorBuilder <strong>interface</strong> <strong>{</strong><br>	New<strong>(</strong>code <strong>int,</strong> msg <strong>string,</strong> details <strong>...interface{})</strong> ErrorInterface<br><br>	NewCustom<strong>()</strong> ErrorInterface<br><strong>}</strong></pre><h4>1. main.go</h4><pre><strong>package</strong> main<br><br><strong>import</strong> <strong>(</strong><br>  &quot;context&quot;<br>  &quot;fmt&quot;<br>  &quot;github.com/gin-gonic/gin&quot;<br>  &quot;github.com/rookie-ninja/rk-boot/v2&quot;<br>  &quot;github.com/rookie-ninja/rk-entry/v2/error&quot;<br>  &quot;github.com/rookie-ninja/rk-entry/v2/middleware&quot;<br>  &quot;github.com/rookie-ninja/rk-gin/v2/boot&quot;<br>  &quot;net/http&quot;<br><strong>)</strong><br><br><strong>func</strong> main<strong>()</strong> <strong>{</strong><br>  <em>// Create a new boot instance.<br>  </em>boot <strong>:=</strong> rkboot<strong>.</strong>NewBoot<strong>()</strong><br><br>  <em>// Register handler<br>  </em>entry <strong>:=</strong> rkgin<strong>.</strong>GetGinEntry<strong>(</strong>&quot;greeter&quot;<strong>)</strong><br>  entry<strong>.</strong>Router<strong>.</strong>GET<strong>(</strong>&quot;/v1/greeter&quot;<strong>,</strong> Greeter<strong>)</strong><br><br>  <em>// Bootstrap<br>  </em>boot<strong>.</strong>Bootstrap<strong>(</strong>context<strong>.</strong>TODO<strong>())</strong><br><br>  <em>// Set default error builder after bootstrap<br>  </em>rkmid<strong>.</strong>SetErrorBuilder<strong>(&amp;</strong>MyErrorBuilder<strong>{})</strong><br><br>  boot<strong>.</strong>WaitForShutdownSig<strong>(</strong>context<strong>.</strong>TODO<strong>())</strong><br><strong>}</strong><br><br><strong>func</strong> Greeter<strong>(</strong>ctx <strong>*</strong>gin<strong>.</strong>Context<strong>)</strong> <strong>{</strong><br>  err <strong>:=</strong> rkmid<strong>.</strong>GetErrorBuilder<strong>().</strong>New<strong>(</strong>http<strong>.</strong>StatusAlreadyReported<strong>,</strong> &quot;Trigger manually!&quot;<strong>,</strong><br>    &quot;This is detail.&quot;<strong>,</strong><br>    <strong>false,<br>    -1,</strong><br>    <strong>0.1)</strong><br><br>  ctx<strong>.</strong>JSON<strong>(</strong>http<strong>.</strong>StatusAlreadyReported<strong>,</strong> err<strong>)</strong><br><strong>}</strong><br><br><strong>type</strong> MyError <strong>struct</strong> <strong>{</strong><br>  ErrCode    <strong>int</strong><br>  ErrMsg     <strong>string</strong><br>  ErrDetails <strong>[]interface{}</strong><br><strong>}</strong><br><br><strong>func</strong> <strong>(</strong>m MyError<strong>)</strong> Error<strong>()</strong> <strong>string</strong> <strong>{</strong><br>  <strong>return</strong> fmt<strong>.</strong>Sprintf<strong>(</strong>&quot;%d-%s&quot;<strong>,</strong> m<strong>.</strong>ErrCode<strong>,</strong> m<strong>.</strong>ErrMsg<strong>)</strong><br><strong>}</strong><br><br><strong>func</strong> <strong>(</strong>m MyError<strong>)</strong> Code<strong>()</strong> <strong>int</strong> <strong>{</strong><br>  <strong>return</strong> m<strong>.</strong>ErrCode<br><strong>}</strong><br><br><strong>func</strong> <strong>(</strong>m MyError<strong>)</strong> Message<strong>()</strong> <strong>string</strong> <strong>{</strong><br>  <strong>return</strong> m<strong>.</strong>ErrMsg<br><strong>}</strong><br><br><strong>func</strong> <strong>(</strong>m MyError<strong>)</strong> Details<strong>()</strong> <strong>[]interface{}</strong> <strong>{</strong><br>  <strong>return</strong> m<strong>.</strong>ErrDetails<br><strong>}</strong><br><br><strong>type</strong> MyErrorBuilder <strong>struct{}</strong><br><br><strong>func</strong> <strong>(</strong>m <strong>*</strong>MyErrorBuilder<strong>)</strong> New<strong>(</strong>code <strong>int,</strong> msg <strong>string,</strong> details <strong>...interface{})</strong> rkerror<strong>.</strong>ErrorInterface <strong>{</strong><br>  <strong>return</strong> <strong>&amp;</strong>MyError<strong>{</strong><br>    ErrCode<strong>:</strong>    code<strong>,</strong><br>    ErrMsg<strong>:</strong>     msg<strong>,</strong><br>    ErrDetails<strong>:</strong> details<strong>,</strong><br>  <strong>}</strong><br><strong>}</strong><br><br><strong>func</strong> <strong>(</strong>m <strong>*</strong>MyErrorBuilder<strong>)</strong> NewCustom<strong>()</strong> rkerror<strong>.</strong>ErrorInterface <strong>{</strong><br>  <strong>return</strong> <strong>&amp;</strong>MyError<strong>{</strong><br>    ErrCode<strong>:</strong>    http<strong>.</strong>StatusInternalServerError<strong>,</strong><br>    ErrMsg<strong>:</strong>     &quot;Internal Error&quot;<strong>,</strong><br>    ErrDetails<strong>:</strong> <strong>[]interface{}{},</strong><br>  <strong>}</strong><br><strong>}</strong></pre><h4>2. Validate</h4><pre>$ curl &quot;localhost:8080/v1/greeter?name=rk-dev&quot;<br><strong>{</strong><br>    &quot;ErrCode&quot;:208,<br>    &quot;ErrMsg&quot;:&quot;Trigger manually!&quot;,<br>    &quot;ErrDetails&quot;:<strong>[</strong><br>        &quot;This is detail.&quot;,<br>        false,<br>        -1,<br>        0.1<br>    <strong>]</strong><br><strong>}</strong></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6fbbdcbabb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[rk-boot/v2: Simplify Golang microservice dependencies]]></title>
            <link>https://medium.com/@mofcloud/rk-boot-v2-simplify-golang-microservice-dependencies-3343ba801520?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/3343ba801520</guid>
            <category><![CDATA[rk-boot]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Fri, 20 May 2022 17:38:51 GMT</pubDate>
            <atom:updated>2022-05-20T17:38:51.696Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*3RLyLRu98A488N-QpeSqQw.png" /></figure><h3>Overview</h3><p><a href="https://github.com/rookie-ninja/rk-boot">rk-boot/v2</a> aims to simplify dependencies while user creating Golang micro services with YAML config.</p><p>rk-boot is now upgraded to v2. We will introduce rk-boot/v2 via an example of Gin framework.</p><h3>Understand rk-boot/v2</h3><ul><li><a href="https://github.com/rookie-ninja/rk-boot">Github</a></li><li><a href="https://rkdev.info/">Official site</a></li><li><a href="https://docs.rkdev.info/cn/docs/">Docs</a></li></ul><h3><strong>Quick start</strong></h3><h4>Visite rkdev.info</h4><p>Download demo package via <a href="https://rkdev.info/">rkdev.info</a> site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*0tEHkkWzc4bhAmmoNqzy3Q.png" /></figure><h4>Validate</h4><p>Unzip rk-demo.zip file and run main.go</p><pre>$ go run main.go<br>2022-05-21T00:35:17.530+0800    INFO    boot/gin_entry.go...<br>2022-05-21T00:35:17.530+0800    INFO    boot/gin_entry.go...<br>2022-05-21T00:35:17.530+0800    INFO    boot/gin_entry.go...<br>2022-05-21T00:35:17.530+0800    INFO    boot/gin_entry.go...<br>2022-05-21T00:35:17.530+0800    INFO    boot/gin_entry.go...<br>...</pre><ul><li>Access Swagger UI via localhost:8080/sw/</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*2rR7PtvA76sssJWvZKmA8A.png" /></figure><ul><li>Access rapiDocs UI via localhost:8080/docs/</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*4OChTPdNqIOiYOQVvqPAYw.png" /></figure><ul><li>Access prometheus client via localhost:8080/metrics</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*FV2no0IPyQyVbxVfej4VRQ.png" /></figure><h4>Explanation of boot.yaml</h4><pre>gin:<br>  - name: rk-demo            # Name of gin instance<br>    port: 8080               # Port of gin service<br>    enabled: true            # Enable gin service<br>    commonService:           <br>      enabled: true          # Enable common API <br>    sw:<br>      enabled: true          # Enable Swagger UI<br>    docs:<br>      enabled: true          # Enable API Docs UI<br>    prom:<br>      enabled: true          # Enable Prometheus client<br>    middleware:<br>      logging:<br>        enabled: true        # Enable API logging middleware<br>        enabled: true        # Enable API prometheus middleware</pre><h4>Explanation of main.go</h4><p>rk-boot/v2 did not wrap gin framework. User can use gin as native way.</p><pre>func main() {<br>   // Create boot instance<br>   boot := rkboot.NewBoot()<br><br>   // Get GinEntry<br>   entry := rkgin.GetGinEntry(&quot;rk-demo&quot;)<br>   // Get Router and register API<br>   entry.Router.GET(&quot;/v1/greeter&quot;, Greeter)<br><br>   // Start service<br>   boot.Bootstrap(context.TODO())<br><br>   // Wait for shutdown sig, ctrl-c<br>   boot.WaitForShutdownSig(context.TODO())<br>}</pre><h3>rk-boot/v2</h3><p>There are other plugins can be used while using rk-boot/v2 start golang microservices. Please visit <a href="https://rkdev.info/">https://rkdev.info</a> for details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rOfV4bMt7cw4OnDfp9NfnA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3343ba801520" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[rk-boot/v2: A clean way of prometheus monitoring in Golang]]></title>
            <link>https://medium.com/@mofcloud/rk-boot-v2-a-clean-way-of-prometheus-monitoring-in-golang-95a5e52038c7?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/95a5e52038c7</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[rk-boot]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Fri, 25 Mar 2022 21:23:47 GMT</pubDate>
            <atom:updated>2022-03-25T21:23:47.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*8VjVXCOBVSj7ouyKHb63Ww.png" /></figure><p><a href="https://prometheus.io/"><strong>Prometheus</strong></a> is one of the most popular tools in monitoring. In the mean time, <a href="https://thanos.io/"><strong>Thanos</strong></a> solved the longer term storage solution for Prometheus as well.</p><p>Cloud providers like <strong>AWS</strong> also introduced on-cloud Prometheus services for convenience which means operation workloads has beens resolved already for monitoring.</p><p>Now, there is another problem while developers deal with monitoring.</p><ul><li>What to monitor</li><li>What kind of labels do I need?</li><li>How to make reasonable dashboard?</li></ul><p>It’s not an easy job to define all above problems. I believe we can code it into our functions in a short period of time. But I can nearly promise that the <strong>CODE</strong> will be <strong>UGLY</strong> if we inject monitoring code in every function.</p><h3>A clean way</h3><p>We introduce <strong>rk-boot/v2 + Prometheus + Grafana</strong> as the solution. The solution is really simple where we will wrap the prometheus client logic into simple functions and make it work in default <strong>Grafana</strong> dashboards.</p><p>What we aims to do is reduce code complexity with <strong>rk-boot/v2</strong></p><h3>Quick Start</h3><h4>1. Start prometheus with Docker</h4><p>We need to create <strong>prometheus.yml</strong> file to collect demo program metrics.</p><pre>global:<br>  scrape_interval: 1s<br><br>scrape_configs:<br>  - job_name: &#39;greeter&#39;<br>    scrape_interval: 1s<br>    metrics_path: &quot;/metrics&quot;<br>    static_configs:<br>      - targets: [&#39;host.docker.internal:8080&#39;]</pre><p>And let’s start prometheus with docker.</p><pre>$ docker run -p 9090:9090 -v &lt;path&gt;/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus</pre><h4>2. Start Grafana &amp; configure prometheus as datasource</h4><p>The username/password will be both admin.</p><pre>$ docker run -p 3000:3000 grafana/grafana</pre><p>Access <a href="http://localhost:3000/"><strong>localhost:3000</strong></a><strong> </strong>and configure datasource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*boPbbJcu73reaLlalDmaTw.png" /><figcaption>Add datasource</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QS0LWRxfmHEGvmHxAtPhvQ.png" /><figcaption>Select prometheus as datasource type</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m_m2P6S13CLVcw9PGUSUUw.png" /><figcaption>Use <a href="http://host.docker.internal:9090/">http://host.docker.internal:9090</a></figcaption></figure><h4>3. Install rk-boot/v2</h4><p><a href="https://github.com/rookie-ninja/rk-boot"><strong>rk-boot/v2</strong></a> is a library which can be used to start <strong>Golang</strong> microservices with YAML configuration. It supports the most popular frameworks as plugin.</p><p>In this example, we will use <a href="https://github.com/gin-gonic/gin"><strong>gin-gonic</strong></a> as web framework which needs to install <a href="https://github.com/rookie-ninja/rk-gin"><strong>rk-gin/v2</strong></a> either.</p><pre>$ go get github.com/rookie-ninja/rk-boot/v2<br>$ go get github.com/rookie-ninja/rk-gin/v2</pre><h4>4. Create boot.yaml</h4><p>boot.yaml will tell <a href="https://github.com/rookie-ninja/rk-boot"><strong>rk-boot/v2</strong></a><strong> </strong>how to configure Gin while starting.</p><p>In this example, we enabled prometheus client and API middleware to record metrics.</p><pre>---<br>gin:<br>  - name: greeter<br>    port: 8080<br>    enabled: true<br>    prom:<br>      enabled: true<br>    middleware:<br>      prom:<br>        enabled: true</pre><h4>5. Create a service &amp; an API</h4><p>Let’s create an API of <strong>/v1/greeter</strong> and verify how <strong>rk-cursor</strong> has been used.</p><p>What we have done for monitoring is two lines of code.</p><pre>pointer := rkginctx.GetCursor(ctx).Click()<br>defer pointer.Release()</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/633413764a5ae521e8c2ece0cc8d7d51/href">https://medium.com/media/633413764a5ae521e8c2ece0cc8d7d51/href</a></iframe><h4>5. Run main.go and send request</h4><pre>$ go run main.go<br>$ curl localhost:8080/v1/greeter</pre><h4>6. Validate in Grafana</h4><p>Now it’s time to validate metrics in Grafana. As we can see, there are only two lines of code for prometheus monitoring in target function.</p><p>There two builtin dashboards we can monitor.</p><ul><li><a href="https://grafana.com/grafana/dashboards/15111"><strong>rk-prom</strong></a>: For prometheus metrics middleware which records metrics for every API.</li><li><a href="https://grafana.com/grafana/dashboards/15937"><strong>rk-cursor</strong></a>: The metrics we injected in our codes.</li></ul><p>Let’s import rk-prom dashboard(15111)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EEvtn0fzW7qAkRKqN2fCKg.png" /><figcaption>Move to Dashboards/Manage</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ovhIbkJSv5dy4o5jk0S7rQ.png" /><figcaption>Load dashboard of 15111</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XbPm4yss-83VFO8c7_dK1g.png" /><figcaption>Select prometheus as datasource</figcaption></figure><p>Now, let’s see what kind of metrics we can monitor in <strong>rk-prom dashboard</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWB7Qk-0aQi_D3cvxxHK_w.png" /><figcaption>Dashboard of rk-prom</figcaption></figure><p>Use the same way, we can import <strong>rk-cursor dashboard</strong>(15937) to monitor custom metrics of functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*To1f-ippAy7W0IDcLyWS_A.png" /><figcaption>Dashboard of rk-cursor</figcaption></figure><h3>Introduction of rk-cursor</h3><p><strong>rk-prom</strong> dashboard is very easy to understand, which is nothing but records API duration, errors and availability by default.</p><p>Let’s focus on <strong>rk-cursor</strong>. It records time elapsed, error and level one tracing of function.</p><h4>I. Monitor function error</h4><p>In order to record error of function, we need to call <strong>pointer.ObserveError()</strong> while error occurs.</p><pre>func Greeter(ctx *gin.Context) {<br>   pointer := rkginctx.GetCursor(ctx).Click()<br>   defer pointer.Release()<br><br>   // Record errors for deamonstration<br>   if time.Now().Second()%2 == 0 {<br>      pointer.ObserveError(errors.New(&quot;manually triggered error&quot;))<br>   }<br>   <br>   ctx.JSON(http.StatusOK, &amp;GreeterResponse{<br>      Message: fmt.Sprintf(&quot;Hello %s!&quot;, ctx.Query(&quot;name&quot;)),<br>   })<br>}</pre><p>The dashboard would be something like bellow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkU96gscAL878yCX9C5OaA.png" /><figcaption>Functions with error recorded</figcaption></figure><h4>II. Monitor level one tracing</h4><p>It seems like impossible do the tracing with prometheus. However, we can achieve tracing with <strong>rk-cursor</strong>. It will call runtime.Caller() function and add labels of parent=&lt;caller&gt; in to every metrics. A simple trick in bellow case.</p><p>For example, <strong>Greeter()</strong> calls function of <strong>B()</strong> and <strong>C()</strong>, and what we hope to know is how much time does it cost while calling <strong>B()</strong> and <strong>C()</strong> and what is the percentage of time distribution.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54f672b40a0444571584ce1232801f3d/href">https://medium.com/media/54f672b40a0444571584ce1232801f3d/href</a></iframe><p>In this example, the parent caller of main.Greeter() is from Gin context which we will mark as [-].</p><p>So [-] only has one child function call which is main.Greeter().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I7W_5NBEKm0M52a2egquCA.png" /><figcaption>Parent of -</figcaption></figure><p>In the meantime, parent of <strong>B()</strong> and <strong>C()</strong> is <strong>main.Greeter()</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxLLa5vNQe_GmxJgRruReg.png" /><figcaption>Parent of main.Greeter</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95a5e52038c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gorilla/mux 101 (rk-boot): Error handling]]></title>
            <link>https://medium.com/@mofcloud/gorilla-mux-101-rk-boot-error-handling-304d0611cecf?source=rss-97d2c3c4f086------2</link>
            <guid isPermaLink="false">https://medium.com/p/304d0611cecf</guid>
            <category><![CDATA[gorilla-mux]]></category>
            <category><![CDATA[rk-boot]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[mofcloud]]></dc:creator>
            <pubDate>Tue, 15 Feb 2022 09:26:31 GMT</pubDate>
            <atom:updated>2022-02-15T09:26:31.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*l7a5iMcqO36DrE837lEyzQ.png" /></figure><p>We will use <a href="https://github.com/rookie-ninja/rk-boot"><strong>rk-boot</strong></a> to start and handle API errors in <a href="https://github.com/gorilla/mux"><strong>gorilla/mux</strong></a> framework.</p><h3>Consideration</h3><p>A reasonable error handling should consider bellow factors:</p><ul><li>Includes error code and message</li><li>Error message should be scalable</li><li>Readability</li><li>Error should be able to parsed from client side by code</li><li>Tolerate panic</li></ul><h3>Recommended error format</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*3nvMoCFE4lijL_tq.png" /></figure><pre>{<br>    &quot;error&quot;:{<br>        &quot;code&quot;:500,<br>        &quot;status&quot;:&quot;Internal Server Error&quot;,<br>        &quot;message&quot;:&quot;Panic manually!&quot;,<br>        &quot;details&quot;:[]<br>    }<br>}</pre><h3>Introduce rk-boot</h3><p><a href="https://github.com/rookie-ninja/rk-boot"><strong>rk-boot</strong></a> is a library used to create goLang micro-service with <a href="https://github.com/gorilla/mux"><strong>gorilla/mux</strong></a> framework easily.</p><h3>Install rk-boot</h3><pre>go get github.com/rookie-ninja/rk-boot/mux</pre><h3>Quick start</h3><p>In this example, we will return an error to API caller with recommended error format.</p><h4>I. Create boot.yaml</h4><p><strong>boot.yaml</strong> file tells <strong>rk-boot</strong> metadata of <a href="https://github.com/gorilla/mux"><strong>gorilla/mux</strong></a> framework.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a59674aa43d1e163f6ac0a1f77f8a346/href">https://medium.com/media/a59674aa43d1e163f6ac0a1f77f8a346/href</a></iframe><h4>II. Create main.go</h4><p>Return error to <strong>/v1/greeter</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37727fa12f78993c923190d472d93ec9/href">https://medium.com/media/37727fa12f78993c923190d472d93ec9/href</a></iframe><h4>III. Start main.go</h4><pre>$ go run main.go</pre><h4>IV. Validate</h4><pre>$ curl &quot;localhost:8080/v1/greeter?name=rk-dev&quot;<br>{<br>    &quot;error&quot;:{<br>        &quot;code&quot;:208,<br>        &quot;status&quot;:&quot;Already Reported&quot;,<br>        &quot;message&quot;:&quot;Trigger manually!&quot;,<br>        &quot;details&quot;:[<br>            &quot;This is detail.&quot;,<br>            false,<br>            -1,<br>            0.1<br>        ]<br>    }<br>}</pre><h3>Catch panic</h3><p>In this case, let’s <strong>panic</strong> in <strong>/v1/greeter handler</strong>.</p><p><strong>rk-boot</strong> already integrates <strong>panic middleware</strong> which will catch panic and wrap it with recommended error in response.</p><h4>I. Modify main.go</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c86f3e718e525b787d8a0c3a6bf73bf3/href">https://medium.com/media/c86f3e718e525b787d8a0c3a6bf73bf3/href</a></iframe><h4>II. Validate</h4><pre>$ curl &quot;localhost:8080/v1/greeter?name=rk-dev&quot;<br>{<br>    &quot;error&quot;:{<br>        &quot;code&quot;:500,<br>        &quot;status&quot;:&quot;Internal Server Error&quot;,<br>        &quot;message&quot;:&quot;Panic manually!&quot;,<br>        &quot;details&quot;:[]<br>    }<br>}</pre><h3>Source code</h3><p>The error wrapper was defined in <a href="https://github.com/rookie-ninja/rk-common/tree/master/error"><strong>rk-common/error</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=304d0611cecf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>