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

Backend metrics redefinition required in Product #597

Open
pbriet opened this issue Mar 31, 2021 · 2 comments
Open

Backend metrics redefinition required in Product #597

pbriet opened this issue Mar 31, 2021 · 2 comments

Comments

@pbriet
Copy link

pbriet commented Mar 31, 2021

Hello,

I have the following use case :

  • Metrics and mapping rules are defined in the backend
  • Product simply "consumes" the backend, and define application plans

I encounter the following issue : the Product CRD fails to be processed with the following message :

'[spec.applicationPlans[free].limits[1].metricMethodRef: Invalid value: "callsToPremium": limit does not have valid local metric or method reference., spec.applicationPlans[payAsYouGo].pricingRules[0].metricMethodRef: Invalid value: "callsToPremium": Pricing rule does not have valid local metric or method reference., spec.applicationPlans[payAsYouGo].pricingRules[1].metricMethodRef: Invalid value: "callsToPremium": Pricing rule does not have valid local metric or method reference., spec.applicationPlans[payAsYouGo].pricingRules[2].metricMethodRef: Invalid value: "callsToV2": Pricing rule does not have valid local metric or method reference.]'

It requires to redefine the metrics on product-side, which is - in theory? - unnecessary

Backend CRD :

apiVersion: capabilities.3scale.net/v1beta1
kind: Backend
metadata:
  name: micro-api-backend
  namespace: api-gateways
spec:
  mappingRules:
    - httpMethod: GET
      increment: 1
      metricMethodRef: callsToPremium
      pattern: '/{version}/premium-service'
    - httpMethod: GET
      increment: 1
      metricMethodRef: callsToV2
      pattern: /v2/
    - httpMethod: GET
      increment: 1
      metricMethodRef: callsToV1
      pattern: /v1/
  metrics:
    hits:
      description: Number of API hits
      friendlyName: Hits
      unit: hit
    callsToV2:
      description: Number of calls to API V2
      friendlyName: V2 Calls
      unit: hit
    callsToV1:
      description: Number of calls to API V2
      friendlyName: V1 Calls
      unit: hit
    callsToPremium:
      description: Number of premium API calls
      friendlyName: Premium Calls
      unit: hit
  name: MicroApi Backend
  privateBaseURL: 'http://micro-api'
  systemName: micro-api-backend
  providerAccountRef:
    name: threescale-provider-account

Product CRD (failing version) :

apiVersion: capabilities.3scale.net/v1beta1
kind: Product
metadata:
  name: public-api
spec:
  name: PublicAPI
  systemName: "public_api"
  backendUsages:
    micro-api-backend:
      path: ''
  applicationPlans:
    free:
      name: "Free plan"
      limits:
        - period: day
          value: 10
          metricMethodRef:
            systemName: callsToV2
            backend: micro-api-backend
        - period: month
          value: 0
          metricMethodRef:
            systemName: callsToPremium
    premium:
      name: "Premium plan"
      setupFee: "14.56"
      trialPeriod: 0
      costMonth: "50.00"
    payAsYouGo:
      name: "PAYG plan"
      setupFee: "0.00"
      trialPeriod: 0
      costMonth: "0.00"
      pricingRules:
        - from: 1
          to: 100
          pricePerUnit: "0.20"
          metricMethodRef:
            systemName: callsToPremium
        - from: 101
          to: 99999999
          pricePerUnit: "0.10"
          metricMethodRef:
            systemName: callsToPremium
        - from: 1
          to: 99999999
          pricePerUnit: "0.01"
          metricMethodRef:
            systemName: callsToV2

Thanks,

@eguzki
Copy link
Member

eguzki commented Apr 19, 2021

My guess is that it is missing the reference to the backend in the limit. Note that the first defined limit (request per day) has reference to backend. If backend is not referenced, the operator tries to link to a metric defined in the product itself. If the metric is not found in the product, raises the shown error.

apiVersion: capabilities.3scale.net/v1beta1
kind: Product
metadata:
  name: public-api
spec:
  name: PublicAPI
  systemName: "public_api"
  backendUsages:
    micro-api-backend:
      path: ''
  applicationPlans:
    free:
      name: "Free plan"
      limits:
        - period: day
          value: 10
          metricMethodRef:
            systemName: callsToV2
            backend: micro-api-backend
        - period: month
          value: 0
          metricMethodRef:
            systemName: callsToPremium
            backend: micro-api-backend    <- missing

@eguzki
Copy link
Member

eguzki commented Apr 19, 2021

Note that the references of metrics from the pricing rules are also missing backend reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants