Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55223

unable to create a metricskey via the api

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Hello,

      I am unable to use the dedicated method setAccessKeys() to add a new metric key.
      -> the goal is to define the key via the code instead of overriding the generated xml file.

       

      def monitoringKey = new jenkins.metrics.api.MetricsAccessKey ("jenkins_metrics", "monitoring", true, false, true, true, null)
      List<jenkins.metrics.api.MetricsAccessKey> metricKeys = new ArrayList<jenkins.metrics.api.MetricsAccessKey> ()
      metricKeys.add (monitoringKey)
      jenkins.metrics.api.MetricsAccessKey.DescriptorImpl.setAccessKeys (metricKeys)

       

      result:

      groovy.lang.MissingMethodException: No signature of method: static jenkins.metrics.api.MetricsAccessKey$DescriptorImpl.setAccessKeys() is applicable for argument types: (java.util.ArrayList) values: [[MetricsAccessKey\{key='monitoring', description='jenkins_metrics', canPing=true, canHealthCheck=true, canMetrics=true, canThreadDump=false, origins='null'}]]
      Possible solutions: setAccessKeys(java.util.List), getAccessKeys(), getAccessKey(java.lang.String)

       

        Attachments

          Activity

          Hide
          amatignon arnold matignon added a comment -

          basically, I guess we cannot set any new key directly on the DescriptionImpl. We need to get the singleton.

           

          This seems to be available in metrics, but then there is no direct access to the Descriptor, nor any method to add a new key:

          https://github.com/jenkinsci/metrics-plugin/blob/bb4a572004bb708136a57d2d359a930c934786b1/src/main/java/jenkins/metrics/api/Metrics.java

          Show
          amatignon arnold matignon added a comment - basically, I guess we cannot set any new key directly on the DescriptionImpl. We need to get the singleton.   This seems to be available in metrics, but then there is no direct access to the Descriptor, nor any method to add a new key: https://github.com/jenkinsci/metrics-plugin/blob/bb4a572004bb708136a57d2d359a930c934786b1/src/main/java/jenkins/metrics/api/Metrics.java
          Hide
          amatignon arnold matignon added a comment -

          ok, need to access the descriptor this way:

          Jenkins.getInstance().getDescriptorByType(jenkins.metrics.api.MetricsAccessKey.DescriptorImpl.class)

          Show
          amatignon arnold matignon added a comment - ok, need to access the descriptor this way: Jenkins.getInstance().getDescriptorByType(jenkins.metrics.api.MetricsAccessKey.DescriptorImpl.class)

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            amatignon arnold matignon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: