electrolux-oss / infrawallet

Backstage plugin that controls your cloud costs just in the way how you control your bank accounts
https://demo.infrawallet.io
Apache License 2.0
50 stars 3 forks source link

Issue: Error with BackendFeature Function After Upgrading to Backstage v1.29 #54

Open jonathan-arenas opened 1 month ago

jonathan-arenas commented 1 month ago

Hello,

I'm in the process of upgrading my instance of Backstage to version 1.29. However, I've encountered an issue related to the deprecation of the BackendFeature function.

In previous versions of Backstage, my plugin used BackendFeature without any issues. But after upgrading to version 1.29, I’ve encountered multiple errors in my code due to this function being deprecated, as mentioned in the v1.29.0 release notes.

I would appreciate it if there is a specific migration guide or recommended replacement for BackendFeature in this new version. I’m looking for the best way to update my plugin without breaking existing functionality.

Thank you for your attention and for the excellent work on Backstage.

No se puede asignar un argumento de tipo "Promise<typeof import("/backstage/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")>" al parámetro de tipo "BackendFeature | Promise<{ default: BackendFeature; }>". El tipo 'Promise<typeof import("/backstage/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")>' no se puede asignar al tipo 'Promise<{ default: BackendFeature; }>'. El tipo 'typeof import("/backstage/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")' no se puede asignar al tipo '{ default: BackendFeature; }'. Los tipos de propiedad 'default' no son compatibles. El tipo '() => BackendFeature' no se puede asignar al tipo 'BackendFeature'.ts(2345)

Best regards, Jonathan A

gluckzhang commented 1 month ago

Hi Jonathan, thanks for reporting this. I will try InfraWallet with Backstage v1.29 and get back to you soon :)

holiiveira commented 1 month ago

@jonathan-arenas Alternatively you can ignore this message by adding in yourpackages/backend/src/index.ts:

+// @ts-ignore
backend.add(import('@electrolux-oss/plugin-infrawallet-backend'));
gluckzhang commented 1 month ago

Hi @jonathan-arenas , I tested InfraWallet using Backstage 1.29.0 and 1.30.4 but I could not reproduce the behavior.

As () => BackendFeature is a deprecation instead of a breaking change, could you check whether the functionalities are affected or not?

nia-potato commented 1 week ago

hi @gluckzhang

i just got time to revisit the issue https://github.com/electrolux-oss/infrawallet/issues/44 we discussed earlier and start developing, i am on backstage version 1.30.4 and i am also getting this error when trying to add the backend via the new backend in the index.ts, are we missing a type somewhere?

Argument of type 'Promise<typeof import("backstage/src/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")>' is not assignable to parameter of type 'BackendFeature | Promise<{ default: BackendFeature; }>'.
  Type 'Promise<typeof import("backstage/src/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")>' is not assignable to type 'Promise<{ default: BackendFeature; }>'.
    Type 'typeof import("backstage/src/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")' is not assignable to type '{ default: BackendFeature; }'.
      Types of property 'default' are incompatible.
        Type '() => BackendFeature' is not assignable to type 'BackendFeature'.ts(2345)

However i am not sure if its actually just my configuration issue.

   infraWallet:
    integrations:
      gcp:
        - name: "gcp-bq-dataset"
          keyFilePath: "/Users/user1/place/xxxxd316801e.json"
          projectId: "bq-project-id"
          datasetId: "bq-project-id.billing"
          tableId: "bq-project-id.billing.gcp_billing_export_resource_v2_xxXXXXXX"

i've tried both with quotes and without quotes, but when i check the website console log and the local yarn dev stream logs, i dont see any errors indicating that it is not working, its just that it is on a blank page when i click in the plugin. i've waited for around 10mins, so i dont think its data still importing. Is there a better way to see if im running to any errors related to the config?

gluckzhang commented 1 week ago

Hi @nia-potato , I upgraded my local environment to Backstage v1.30.4 and used our GCP environment to test. Unfortunately, I could not reproduce the error. Could you check the following points?

nia-potato commented 1 week ago

ok yea, it was my problem, i mislooked, our gcp project name was not the same value as its project id.

Thanks @gluckzhang!

nia-potato commented 1 week ago

it is now running just fine with the deprecation notice, i dont know whats cause my setup to trigger it. il let you know once i figure it out.

emillg commented 1 week ago

@nia-potato What deprecation notice do you see? Is it from Google or Backstage? Can you provide more details?

nia-potato commented 1 week ago

@emillg the deprecation notice is from backstage, and unfortunately it is still the one where @gluckzhang cant reproduce, so i dont quite know what other information we might need to reproduce this on your end.

but i believe the current workaround is enough with +// @ts-ignore

yarn tsc                                                                                                
packages/backend/src/index.ts:115:13 - error TS2345: Argument of type 'Promise<typeof import("backstage/src/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")>' is not assignable to parameter of type 'BackendFeature | Promise<{ default: BackendFeature; }>'.
  Type 'Promise<typeof import("backstage/src/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")>' is not assignable to type 'Promise<{ default: BackendFeature; }>'.
    Type 'typeof import("backstage/src/node_modules/@electrolux-oss/plugin-infrawallet-backend/dist/index")' is not assignable to type '{ default: BackendFeature; }'.
      Types of property 'default' are incompatible.
        Type '() => BackendFeature' is not assignable to type 'BackendFeature'.

115 backend.add(import('@electrolux-oss/plugin-infrawallet-backend'));
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 1 error in packages/backend/src/index.ts:xxx
nia-potato commented 2 days ago

@gluckzhang @emillg after some digging, i believe it is because of this deprecation

d425fc4: BREAKING: The return values from createBackendPlugin, createBackendModule, and createServiceFactory are now simply BackendFeature and ServiceFactory, instead of the previously deprecated form of a function that returns them. For this reason, createServiceFactory also no longer accepts the callback form where you provide direct options to the service. This also affects all coreServices.* service refs.

This may in particular affect tests; if you were effectively doing createBackendModule({...})() (note the parentheses), you can now remove those extra parentheses at the end. You may encounter cases of this in your packages/backend/src/index.ts too, where you add plugins, modules, and services. If you were using createServiceFactory with a function as its argument for the purpose of passing in options, this pattern has been deprecated for a while and is no longer supported. You may want to explore the new multiton patterns to achieve your goals, or moving settings to app-config.

As part of this change, the IdentityFactoryOptions type was removed, and can no longer be used to tweak that service. The identity service was also deprecated some time ago, and you will want to [migrate to the new auth system](https://backstage.io/docs/tutorials/auth-service-migration) if you still rely on it.

https://github.com/backstage/backstage/blob/master/docs/releases/v1.31.0-changelog.md#minor-changes