본문 바로가기
IT팁

Feature toggle

by e-pd 2023. 10. 1.

 

https://martinfowler.com/articles/feature-toggles.html

 

Feature Toggles (aka Feature Flags)

Feature Flags can be categorized into several buckets; manage each appropriately. Smart implementation can help constrain complexity.

martinfowler.com

Feature Toggle

  • 코드의 변경없이 시스템을 수정.
  • 토글을 적용하고 관리하는 것으로 다양한 범주의 사용을 고려하게한다.
  • 토글을 구현하는 방식과 적절한 도구들을 사용하여 토글을 구성하고 복잡성을 관리할 수 있다.
  • 시스템 토글 수를 관리하는 것도 목표로 해야한다.

해당 기능과 관련된 플래그 용어(https://theproductmanager.com/topics/feature-flag-best-practices)

  • Release flags
  • Experiment flags
  • Kill flag
  • Permission flags

 

사례

피쳐 토글 - 빠르고 안정적인 릴리즈를 향한 도약 - 맘시터 기술블로그

 

피쳐 토글 - 빠르고 안정적인 릴리즈를 향한 도약 - 맘시터 기술블로그

맘편한세상에서 피쳐 토글을 어떻게 사용하고 있는지 공유합니다.

tech.mfort.co.kr

Feature Flag solutions in Jira | Atlassian

 

Feature Flag solutions in Jira | Atlassian

Feature flags is a software technique that enables teams to make changes without additional code. Read about benefits, use cases and more.

www.atlassian.com

 

어디에 쓰면 좋을까?

배포

  • 새로운 기능을 릴리즈 했을 때 위험을 줄일 수 있다.

A/B testing

제한된 접근

  • 기능을 미리 특정 사용자에게만 접근가능하도록 할 수 있다.
  • 사내 테스트, QA
  • 전체중 일부에게만 기능 실행

기능차단

  • 트래픽이 많아지면 기존 기능들을 관리할 수 있다.
  • 네이버 지도, 카카오 지도를 운영하다가 한쪽에 이슈가 생기면 전환한다.

 

 

어떻게 구현하면 될까?

  • Simple way
public void feature1() {
    boolean enableNewFeature = false;
    // 새로운 기능 플래그를 활성화 시키면 기능을 작동한다.
    if (enableNewFeature) {
        newFeature();
    } else {
        oldFeature();
    }
}
    
private void newFeature() {
    System.out.println("new feature");
}

private void oldFeature() {
    System.out.println("old feature");
}
  • 규모가 작으면 DB, 코드, 각종 Config 기능으로 설정
  • 메시지브로커의 Topic을 이용한다든지 방법은 여러가지.

 

솔루션은 없을까?

 

핵클(Hackle) | 비즈니스 최적화를 위한 단 하나의 솔루션

 

핵클(Hackle) | 비즈니스 최적화를 위한 단 하나의 솔루션

 

hackle.io

오픈소스 솔루션

https://posthog.com/blog/best-open-source-feature-flag-tools

 

The 7 best free and open-source feature flag tools - PostHog

Feature flags, aka feature toggles, turn specific functions on and off during runtime. Rather than maintaining multiple feature branches in your…

posthog.com

Unleash

  • 오픈소스
  • 실제로 사용하고 있는 회사와 10개 이상 커뮤니티 SDK 존재
  • 깃헙스타 9k

 

스프링부트에서 테스트해보기

https://github.com/etff/feature-toggle

 

GitHub - etff/feature-toggle: unleash 실습을 통한 feature-toggle 학습

unleash 실습을 통한 feature-toggle 학습. Contribute to etff/feature-toggle development by creating an account on GitHub.

github.com

  • 실습 코드

docker

git clone <https://github.com/Unleash/unleash.git>
cd unleash
docker-compose up -d

localhost:4242 접속

초기 계정 설정값

  • id: admin
  • pw: unleash4all

들어가면 project를 설정할 수 있다. 추가 프로젝트를 추가하려면 요금제를 설정해야한다.

feature를 설정하려면 toggle 생성을 누른다.

https://docs.getunleash.io/reference/sdks/java

 

피쳐를 만들었다.

Spring Boot 설정

  • application.yaml 부분을 관리자 페이지의 정보에서 가져와 채운다.
io:
  getunleash:
    app-name: 
    instance-id: 
    environment: 
    api-url: 
    api-token: 

환경은 development 로 설정하였다.

 

작성한 코드는 다음과 같다.

@Service
public class ToggleService {
    private final Unleash unleash;

    public ToggleService(Unleash unleash) {
        this.unleash = unleash;
    }

    public String getResult() {
        if (unleash.isEnabled("feature-001")) {
            return "feature-001";
        }
        else if (unleash.isEnabled("feature-002")) {
            return "feature-002";
        }
        return "old-feature";
    }
}

unleash의 현재 feature-001 이 설정되었으면 feature-001이 출력될 것이고

그렇지 않다면 old-feature 가 출력될 것이다.

이 나온다.

이제 토글을 통해 feature를 활성화 한다. 중요한 것은 현재 어플리케이션은 재시작하지 않고

관리자 페이지에서 토글만 활성화로 수정하였다.

다시 http://localhost:8080/toggle 에 접속하면

 


기능 동작상태로 출력된다.

Feature Toggle 개선고민

  • 비지니스 코드에 Toggle 기능을 덧붙이니 불필요한 코드가 늘어남. ⇒ AOP을 사용하여 관심사를 분리
  • 배포 후 제거가 되어야한다면 미루지 않고 제거.
  • 사용된 Toggle, 사용안한 Toggle도 결국은 관리 포인트가 됨. 원활하게 사용하기 위해서는 운영하는 사람들의 협력적인 히스토리 관리가 필요함.

'IT팁' 카테고리의 다른 글

대역 연습  (0) 2021.10.10
오라클 클라우드 무료사용하기  (0) 2021.08.12
FQCN (Fully Qualified Class Name)  (0) 2021.01.03
Server Side Rendering  (0) 2020.11.04
Bouncer Pattern  (0) 2020.08.19