Skip to content

Commit

Permalink
feat/app-deployment-plugin (#390)
Browse files Browse the repository at this point in the history
* feat/app-deployment-plugin

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feature-flag enhancements

* flags list api

* fix/Enhancement changes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix/pre-commit hook fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* sonar fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix/sonar

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* REST drf changes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* router updated

* flags review comment improvement

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* pre-commit hooks fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Empty-Commit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rahul Johny <[email protected]>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent 2e5f872 commit b3afbcc
Show file tree
Hide file tree
Showing 27 changed files with 2,809 additions and 721 deletions.
1 change: 1 addition & 0 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
path("", include("tool_instance.urls")),
path("", include("pipeline.urls")),
path("", include("apps.urls")),
path("", include("feature_flag.urls")),
path("workflow/", include("workflow_manager.urls")),
path("platform/", include("platform_settings.urls")),
path("api/", include("api.urls")),
Expand Down
19 changes: 15 additions & 4 deletions backend/feature_flag/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
This module defines the URL patterns for the feature_flags app.
"""

import feature_flag.views as views
from django.urls import path
from feature_flag.views import FeatureFlagViewSet
from rest_framework.urlpatterns import format_suffix_patterns

urlpatterns = [
path("evaluate/", views.evaluate_feature_flag, name="evaluate_feature_flag"),
]
feature_flags_list = FeatureFlagViewSet.as_view(
{
"post": "evaluate",
"get": "list",
}
)

urlpatterns = format_suffix_patterns(
[
path("evaluate/", feature_flags_list, name="evaluate_feature_flag"),
path("flags/", feature_flags_list, name="list_feature_flags"),
]
)
67 changes: 29 additions & 38 deletions backend/feature_flag/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,43 @@

import logging

from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.request import Request
from rest_framework import status, viewsets
from rest_framework.response import Response

from unstract.flags.client import EvaluationClient
from utils.request.feature_flag import check_feature_flag_status, list_all_flags

logger = logging.getLogger(__name__)


@api_view(["POST"])
def evaluate_feature_flag(request: Request) -> Response:
"""Function to evaluate the feature flag.
To-Do: Refactor to a class based view, use serializers (DRF).
class FeatureFlagViewSet(viewsets.ViewSet):
"""A simple ViewSet for evaluating feature flag."""

Args:
request: request object
def evaluate(self, request):
try:
flag_key = request.data.get("flag_key")

Returns:
evaluate response
"""
try:
namespace_key = request.data.get("namespace_key")
flag_key = request.data.get("flag_key")
entity_id = request.data.get("entity_id")
context = request.data.get("context")
if not flag_key:
return Response(
{"message": "Request parameters are missing."},
status=status.HTTP_400_BAD_REQUEST,
)

if not namespace_key or not flag_key or not entity_id:
flag_enabled = check_feature_flag_status(flag_key)
return Response({"flag_status": flag_enabled}, status=status.HTTP_200_OK)
except Exception as e:
logger.error("No response from server: %s", e)
return Response(
{"message": "Request paramteres are missing."},
status=status.HTTP_400_BAD_REQUEST,
{"message": "No response from server"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

evaluation_client = EvaluationClient()
response = evaluation_client.boolean_evaluate_feature_flag(
namespace_key=namespace_key,
flag_key=flag_key,
entity_id=entity_id,
context=context,
)

return Response({"enabled": response}, status=status.HTTP_200_OK)
except Exception as e:
logger.error("No response from server: %s", e)
return Response(
{"message": "No response from server"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
def list(self, request):
try:
namespace_key = request.query_params.get("namespace", "default")
feature_flags = list_all_flags(namespace_key)
return Response({"feature_flags": feature_flags}, status=status.HTTP_200_OK)
except Exception as e:
logger.error("No response from server: %s", e)
return Response(
{"message": "No response from server"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
17 changes: 16 additions & 1 deletion backend/utils/request/feature_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from typing import Optional

from unstract.flags.client import EvaluationClient
from unstract.flags.client.evaluation import EvaluationClient
from unstract.flags.client.flipt import FliptClient


def check_feature_flag_status(
Expand Down Expand Up @@ -38,3 +39,17 @@ def check_feature_flag_status(
except Exception as e:
print(f"Error: {str(e)}")
return False


def list_all_flags(
namespace_key: str,
) -> dict:
try:
flipt_client = FliptClient()
response = flipt_client.list_feature_flags(
namespace_key=namespace_key,
)
return response
except Exception as e:
print(f"Error: {str(e)}")
return {}
2 changes: 2 additions & 0 deletions frontend/src/assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ReactComponent as OrgSelection } from "./org-selection.svg";
import { ReactComponent as RedGradCircle } from "./red-grad-circle.svg";
import { ReactComponent as YellowGradCircle } from "./yellow-grad-circle.svg";
import { ReactComponent as ExportToolIcon } from "./export-tool.svg";
import { ReactComponent as PlaceholderImg } from "./placeholder.svg";

export {
SunIcon,
Expand Down Expand Up @@ -66,4 +67,5 @@ export {
RedGradCircle,
YellowGradCircle,
ExportToolIcon,
PlaceholderImg,
};
20 changes: 20 additions & 0 deletions frontend/src/assets/placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions frontend/src/components/navigations/side-nav-bar/SideNavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { Sider } = Layout;

import Workflows from "../../../assets/Workflows.svg";
import apiDeploy from "../../../assets/api-deployments.svg";
import appdev from "../../../assets/appdev.svg";
import CustomTools from "../../../assets/custom-tools-icon.svg";
import EmbeddingIcon from "../../../assets/embedding.svg";
import etl from "../../../assets/etl.svg";
Expand All @@ -18,10 +17,17 @@ import VectorDbIcon from "../../../assets/vector-db.svg";
import TextExtractorIcon from "../../../assets/text-extractor.svg";
import { useSessionStore } from "../../../store/session-store";

let getMenuItem;
try {
getMenuItem = require("../../../plugins/app-deployments/app-deployment-components/helpers/getMenuItem");
} catch (err) {
// Plugin unavailable.
}

const SideNavBar = ({ collapsed }) => {
const navigate = useNavigate();
const { sessionDetails } = useSessionStore();
const { orgName } = sessionDetails;
const { orgName, flags } = sessionDetails;

const data = [
{
Expand All @@ -36,15 +42,6 @@ const SideNavBar = ({ collapsed }) => {
path: `/${orgName}/api`,
active: window.location.pathname.startsWith(`/${orgName}/api`),
},
{
id: 1.2,
title: "App Deployments",
description: "Standalone unstructured data apps",
icon: BranchesOutlined,
image: appdev,
path: `/${orgName}/app`,
active: window.location.pathname.startsWith(`/${orgName}/app`),
},
{
id: 1.3,
title: "ETL Pipelines",
Expand Down Expand Up @@ -147,6 +144,10 @@ const SideNavBar = ({ collapsed }) => {
},
];

if (getMenuItem && flags.app_deployment) {
data[0].subMenu.splice(1, 0, getMenuItem.default(orgName));
}

return (
<Sider
trigger={null}
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions frontend/src/components/pipelines-or-deployments/header/Header.css

This file was deleted.

Loading

0 comments on commit b3afbcc

Please sign in to comment.