launchdarkly / ld-find-code-refs

Build tool for automatically sending feature flag code references to LaunchDarkly
https://launchdarkly.com
Other
46 stars 34 forks source link

Having trouble getting flag key aliases to find references #222

Closed erodewald closed 2 years ago

erodewald commented 2 years ago

Trying my best to avoid using Issues as a support forum, but I have completely hit a wall on practical usage of this feature.

Let me start with a problem statement: Using either the cli or the GitHub Action implementing this CLI, I can't get my aliases to find any references besides the original string definition.

Command as executed from CLI:

ld-find-code-refs --debug --dryRun --repoName=servicename -t=NOT_A_REAL_TOKEN -d=.

Key in LaunchDarkly:

servicename-enable-aws-sdk-v2-for-account-create

.launchdarkly/coderefs.yaml:

projKey: servicename
aliases: # a catch-all, to try everything possible
- type: camelcase
- type: pascalcase
- type: snakecase
- type: uppersnakecase
- type: kebabcase
- type: dotcase
delimiters: # default definition, I'll play with this later!
  disableDefaults: false

Project structure:

.launchdarkly
  |_ coderefs.yaml
service-web
  |_ project files

Example class which does find the reference:

package com.servicename;

public class ServiceNameConstants {
    public static final String SERVICENAME_ENABLE_AWS_SDK_V2_FOR_ACCOUNT_CREATE = "servicename-enable-aws-sdk-v2-for-account-create";
}

Another class, which does not find get picked up by any of the aliases:

import static com.servicename.Constants.SERVICENAME_ENABLE_AWS_SDK_V2_FOR_ACCOUNT_CREATE;

public class AccountDAO {
    public Operation saveAccount(AccountEntity account) {
        if (ldService.getServiceBooleanFlag(SERVICE_NAME, SERVICENAME_ENABLE_AWS_SDK_V2_FOR_ACCOUNT_CREATE)) {
        }
    }
}

I would expect to catch this, as it matches uppersnakecase (although, for the record, I prefer "screaming snakecase").

The only glimmer of hope I've gotten is that I do get additional references popping up when I set: delimiters.disableDefaults: true. I suspect this might be the "nuclear option" that you'll advise against using, so I'm looking for some guidance on whether or not I'm misusing this correctly.

Thanks for any help you can provide.

carmenquan commented 2 years ago

Hi @erodewald! Thanks for reaching out.

This is a side effect of how we generate our aliases. The expected uppersnakecase alias of servicename-enable-aws-sdk-v2-for-account-create is generated as SERVICENAME_ENABLE_AWS_SDK_V_2_FOR_ACCOUNT_CREATE, and not SERVICENAME_ENABLE_AWS_SDK_V2_FOR_ACCOUNT_CREATE as you expected. Note the extra _ between V and 2.

Sorry for this confusion, I can see how that is unexpected behavior. I've filed a bug on our side to track how we can improve this. A workaround for this could be to rename your flag, or add a literal alias:

- type: literal
  flags:
    servicename-enable-aws-sdk-v2-for-account-create:
      - SERVICENAME_ENABLE_AWS_SDK_V2_FOR_ACCOUNT_CREATE

Feel free to re-open this issue if you have any more questions or feedback that I can take back to our team! Carmen

erodewald commented 2 years ago

Thanks @carmenquan that got me moving again. :)