apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
29.08k stars 10.2k forks source link

Length of namespace is mis-calculated when creating new private namespace #5073

Closed easyfold closed 8 months ago

easyfold commented 8 months ago

Describe the bug In v2.2.0, when creating new private namespace, namespace length is calculated as prefix + namespace. This bug should have be fixed in #2784, but it's reverted in 109c98d

dosubot[bot] commented 8 months ago

🤖

Hello @easyfold! 👋

I'm Dosu, an AI here to assist you with Apollo bugs and queries while we wait for a human maintainer. I can also guide you in contributing to the apollo repository. Remember, no issue is too big or too small for us to handle together! 😉

Let's get this bug squashed! 🐛

The issue you're experiencing with the namespace length being calculated as prefix + namespace when creating a new private namespace in Apollo v2.2.0 is due to the shouldAppendNamespacePrefix() function returning $scope.appendNamespacePrefix, which is set to true by default. This is evident in the following code snippet from the NamespaceController.js file:

$scope.appendNamespacePrefix = true;

function shouldAppendNamespacePrefix() {
    return  $scope.appendNamespacePrefix;
}

When creating a new namespace, the concatNamespace() function is called, which checks the shouldAppendNamespacePrefix() function and if it returns true, it appends the prefix to the namespace:

$scope.concatNamespace = function () {
    if (!$scope.appBaseInfo) {
        return '';
    }
    var appNamespaceName = $scope.appNamespace.name ? $scope.appNamespace.name : '';
    if (shouldAppendNamespacePrefix()) {
        return $scope.appBaseInfo.namespacePrefix + appNamespaceName;
    }
    return appNamespaceName;
};

So, even though the issue was supposed to be fixed in #2784, it appears to have been reverted in 109c98d, and the namespace length is still being calculated as prefix + namespace.

The prefix + namespace calculation in the Apollo v2.2.0 codebase is used to construct the URL for the various API endpoints. For example, in the createNamespace method, the URL is constructed as follows:

url: AppUtil.prefixPath() + '/apps/:appId/namespaces',

Here, AppUtil.prefixPath() returns the base URL and '/apps/:appId/namespaces' is the specific endpoint for creating a new namespace. The :appId is a placeholder that will be replaced with the actual appId when the method is called. This approach allows for flexibility and maintainability in the code. If the base URL changes, it only needs to be updated in one place (AppUtil.prefixPath() function) and all the API calls will still work correctly. This is evident in the NamespaceService.js file.

I hope this clarifies the issue. If you have any further questions, feel free to ask.

Best regards, Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

nobodyiam commented 8 months ago

Thanks for reporting this issue. This is a bug introduced in https://github.com/apolloconfig/apollo/commit/109c98d2f6417ee39568c0eb0ad33b0bcdf92dff.