Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The template parameter example isn't working #12

Closed
crivetechie opened this issue Jan 13, 2024 · 4 comments
Closed

The template parameter example isn't working #12

crivetechie opened this issue Jan 13, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@crivetechie
Copy link

Describe the bug

The example provided in https://pagerduty.github.io/backstage-plugin-docs/advanced/create-service-software-template/ doesn't work even after having followed the provided instructions to setup the plugin: the escalation_policy_id displays an error.

When using the suggested configuration

        escalation_policy_id:
          title: Escalation Policy ID
          type: string
          description: The ID of the escalation policy to associate with the service
          ui:field: SelectFieldFromApi 
          ui:options: 
            title: PagerDuty Escalation Policy
            description: Select an escalation policy from PagerDuty
            path: 'pagerduty/escalation_policies' 
            labelSelector: 'label'
            valueSelector: 'value'
            placeholder: '---'

The software template invokes the endpoint <backstagehost>/pagerduty/escalation_policies which returns a 404 and therefore prevent the field from rendering the escalation policies.

I tried to update the configuration to use the proxy path instead and the policies gets listed but it requires setting arraySelector option and changing labelSelector and valueSelector, working config:

    - title: PagerDuty
      properties:
        escalation_policy_id:
          title: Escalation Policy ID
          type: string
          description: The ID of the escalation policy to associate with the service
          ui:field: SelectFieldFromApi 
          ui:options: 
            title: PagerDuty Escalation Policy
            description: Select an escalation policy from PagerDuty
            path: 'proxy/pagerduty/escalation_policies' 
            labelSelector: 'name'
            valueSelector: 'id'
            placeholder: '---'
            arraySelector: 'escalation_policies'

The pagerduty configuration in app-config for Backstage is as follow:

proxy:
  '/pagerduty':
    target: https://api.pagerduty.com
    headers:
      Authorization: Token token=${PAGERDUTY_TOKEN}
    allowedMethods: ['GET']

pagerDuty:
  apiToken: ${PAGERDUTY_TOKEN}
@crivetechie crivetechie added the bug Something isn't working label Jan 13, 2024
@crivetechie
Copy link
Author

crivetechie commented Jan 13, 2024

I have found out what I was missing to get the documented template to work:

create the file packages/backend/src/plugins/pagerduty.ts with following content:

import { createRouter } from '@pagerduty/backstage-plugin-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  return await createRouter({
    logger: env.logger,
    config: env.config,
  });
}

And then add to packages/backend/src/index.ts:

// In packages/backend/src/index.ts
import pagerduty from './plugins/pagerduty';
// ...
async function main() {
  // ...
  const pagerdutyEnv = useHotMemoize(module, () => createEnv('pagerduty'));
  // ...
  apiRouter.use('/pagerduty', await todo(pagerdutyEnv));

I'd recommend updating the instructions to setup the backend.
Some other plugins have similar instructions (as an example, see TODO: https://github.com/backstage/backstage/tree/master/plugins/todo)

@t1agob
Copy link
Collaborator

t1agob commented Jan 15, 2024

Hello @crivetechie!
Sorry for the trouble here. I totally missed this part in the documentation.

Adding it immediately and will tag you here if you want to review it before I close this issue.

@t1agob
Copy link
Collaborator

t1agob commented Jan 15, 2024

@crivetechie the documentation has been updated 👉🏼 https://pagerduty.github.io/backstage-plugin-docs/getting-started/backstage/#add-the-backend-plugin-to-your-application

Let me know if that looks good to you and I'll close the ticket. Feel free to suggest any additional changes.

@crivetechie
Copy link
Author

@t1agob docs look great, thank you!

@t1agob t1agob closed this as completed Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants