DevOpsDay
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 快速迭代:如何使用 feature toggle 來開發佈署應用程式 - Aki wang Noah hsu {%hackmd @DevOpsDay/B1cnefOI0 %} #### 》[議程介紹](https://devopsdays.tw/2024/session-page/3098) #### 》[填寫議程滿意度問卷|回饋建言給辛苦的講者](https://forms.gle/66hToGrb1V7hL5gV9) > 共筆從這開始 ### Prerequisite - Docker Engine: 23+ - Java: JDK 11+ (recommand 17) - sdk and sample code: [line/Flagship4j](https://github.com/line/Flagship4j) ## feature toggle 因為使用多個branch做開發,有時候有些branch太早開發,但太晚merge進去,中間會有很多其他小開發完成,這樣就會產生merge conflict。 這時候就要去處理這樣的問題 但feature toggle可以有相關的解方。 ### feature切換 常常button換顏色的時候要換來換去,這樣也很苦惱 ## feature toggle 優勢與特色 - Invisibility - 沒有enable的話code是看不到的 - Speed - 加速開發週期 - 先merge什麼都沒做的source code,再merge做了一半的source code) - Experimentation - 體驗性,例如切換不同顏色的button,也可以設定權限) - 可以做很多切換體驗不同的效果 - Safety - 程式碼安全,可以快速關閉跟開啟功能 - Live Update - 可以快速的real time將流量導過去,讓影響降低到最低。 ## [toggle type](https://martinfowler.com/articles/feature-toggles.html) - release toggles - 開發到一半的功能先關閉,開發完之後再出現 - 大概幾週的時間去處理 - ops toggle - 某些功能比較複雜,可能會造成程式的 crash,先關掉也不會造成影響 - 可能會留在上面比較長的時間,驗證更改前後的狀況,比較效能上面的問題。 - experiment toggles - 將user去分群給予不同畫面去體驗處理。 - permission toggles - 今天可能去驗證身份,給予不同的權限去看不同的介面 ## 是第二個好方法,最終要去盡量避免 > "feature toggle is second best solution. the best solution is to find a way to gradually intergrate without feature branches and feature toggles" by Martin Fowler ## [Flagship4j](https://github.com/line/Flagship4j) LINE Taiwan 開發的,已經開源出來了 ## open feature 有三個特點: 1. one SDK, any backend - 今天開 interface 出來, - 統一一個介面,去使用 feature toggle 2. support your favorite tools 3. speak your language - 多種語言 ## openFlagr AB testing,用go來撰寫的。performance非常的好。 ### Prerequisite - Docker Engine: 23+ - Java: JDK 11+ (recommand 17) - sdk and sample code: [line/Flagship4j](https://github.com/line/Flagship4j) ###### tags: `DevOpsDays Taipei 2024` 第一個是未完成Code 的 Merege 問題 第二個是新需求的Adopt,新舊功能都留著 Invisibility Speed Experimentation Safety Live Update Realse Toggle : 承上 Ops Toggles : 流量大有另外函數 Permission Toggles : 權限控制 Experiment Toggles : 使用者體驗 ### Toggle remove toggle測試結束的時候最終要拿掉,不然會累積太多很難處理,會把code跟toggle feature一起拿掉。 ### testing 基本上會希望非開發人員可以去處理,QA或是project owner可以去改變跟測試 ### Demo step 1. 下載專案 sdk and sample code: [line/Flagship4j](https://github.com/line/Flagship4j) 2. install library ``` ./gradlew publishToMavenLocal ``` 3. start a new spring boot application (with web and lombok) or use the example in the downloaded project ```groovy implementation "com.linecorp.flagship4j:flagship4j-openfeature-spring-boot-starter:0.1.40-SNAPSHOT" ``` 4. create a controller with openfeature client 5. 5. create flag setting on the openflagr UI (release toggle) 6. trun toggle to permission togggle (constraints by `role`) 7. add `MutableContext` as a third parameter when call client.getBooleanValue() ### throw Exception ```java @RestController @RequiredArgsConstructor public class LayoutController { private final Client flagrClient; @GetMapping("/layouts/product") public ResponseEntity<?> getLayoutProduct() { return ResponseEntity.ok(buildLayoutProduct()); } private Map<?, ?> buildLayoutProduct() { throw new UnsupportedOperationException("Not implemented yet"); } } ``` ### On / Off with not found ```java @RestController @RequiredArgsConstructor public class LayoutController { private final Client flagrClient; @GetMapping("/layouts/product") public ResponseEntity<?> getLayoutProduct() { if (flagrClient.getBooleanValue("layout-prdocut-enabled", false)) { return ResponseEntity.ok(buildLayoutProduct()); } return ResponseEntity.notFound().build(); } private Map<?, ?> buildLayoutProduct() { return Map.of("btnBuyColor", "blue", "btnBuyRadius", "8px", "btnBuyPos", "page"); } } ``` ### WhiteList ```java @RestController @RequiredArgsConstructor public class LayoutController { private final Client flagrClient; @GetMapping("/layouts/product") public ResponseEntity<?> getLayoutProduct(@RequestHeader(name = "x-user-name", required = false) String userName) { MutableContext context = new MutableContext(); if (userName != null && userName.equals("aki")) { context.add("entityContext", Structure.mapToStructure(Map.of("role", "ROLE_QA"))); } if (flagrClient.getBooleanValue("layout-prdocut-enabled", false, context)) { return ResponseEntity.ok(buildLayoutProduct()); } return ResponseEntity.notFound().build(); } private Map<?, ?> buildLayoutProduct() { return Map.of("btnBuyColor", "blue", "btnBuyRadius", "8px", "btnBuyPos", "page"); } } ``` ### A/B Testing ```java @RestController @RequiredArgsConstructor public class LayoutController { private final Client flagrClient; @GetMapping("/layouts/product") public ResponseEntity<?> getLayoutProduct(@RequestHeader(name = "x-user-name", required = false) String userName) { MutableContext context = new MutableContext(); if (userName != null && userName.equals("aki")) { context.add("entityContext", Structure.mapToStructure(Map.of("role", "ROLE_QA"))); } if (flagrClient.getBooleanValue("layout-prdocut-enabled", false, context)) { String theme = flagrClient.getStringValue("layout-product-theme", "themeA", new MutableContext(userName)); switch (theme) { case "themeA": return ResponseEntity.ok(buildThemeALayoutProduct()); case "themeB": return ResponseEntity.ok(buildThemeBLayoutProduct()); default: return ResponseEntity.notFound().build(); } } return ResponseEntity.notFound().build(); } private Map<?, ?> buildThemeALayoutProduct() { return Map.of("btnBuyColor", "blue", "btnBuyRadius", "8px", "btnBuyPos", "page"); } private Map<?, ?> buildThemeBLayoutProduct() { return Map.of("btnBuyColor", "green", "btnBuyRadius", "0px", "btnBuyPos", "bottomNav"); } } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully