From b5414496e349a095561ecfa21f5f35789073251c Mon Sep 17 00:00:00 2001 From: GitLab Development <gitlab@local.local> Date: Wed, 27 Nov 2019 19:29:29 +0000 Subject: [PATCH] Upgrade to knative 0.8.1 --- app/models/clusters/applications/knative.rb | 2 +- changelogs/unreleased/knative-0-9-update.yml | 5 ++ config/prometheus/common_metrics.yml | 2 +- ...209215316_knative_0_9_prometheus_update.rb | 13 +++++ db/schema.rb | 2 +- .../serverless/functions_controller_spec.rb | 16 ++++++ .../queries/knative_invocation_query_spec.rb | 4 +- .../clusters/applications/knative_spec.rb | 2 +- spec/support/helpers/kubernetes_helpers.rb | 54 ++++++++++++++++++- 9 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 changelogs/unreleased/knative-0-9-update.yml create mode 100644 db/post_migrate/20191209215316_knative_0_9_prometheus_update.rb diff --git a/app/models/clusters/applications/knative.rb b/app/models/clusters/applications/knative.rb index 89ffb72a22f89..387503bee540d 100644 --- a/app/models/clusters/applications/knative.rb +++ b/app/models/clusters/applications/knative.rb @@ -3,7 +3,7 @@ module Clusters module Applications class Knative < ApplicationRecord - VERSION = '0.7.0' + VERSION = '0.9.0' REPOSITORY = 'https://storage.googleapis.com/triggermesh-charts' METRICS_CONFIG = 'https://storage.googleapis.com/triggermesh-charts/istio-metrics.yaml' FETCH_IP_ADDRESS_DELAY = 30.seconds diff --git a/changelogs/unreleased/knative-0-9-update.yml b/changelogs/unreleased/knative-0-9-update.yml new file mode 100644 index 0000000000000..d25e9e90efe6c --- /dev/null +++ b/changelogs/unreleased/knative-0-9-update.yml @@ -0,0 +1,5 @@ +--- +title: Update Knative to 0.9.0 +merge_request: 21361 +author: cab105 +type: added diff --git a/config/prometheus/common_metrics.yml b/config/prometheus/common_metrics.yml index 795243fab49d5..314ee44ed7173 100644 --- a/config/prometheus/common_metrics.yml +++ b/config/prometheus/common_metrics.yml @@ -209,6 +209,6 @@ panel_groups: weight: 1 metrics: - id: system_metrics_knative_function_invocation_count - query_range: 'sum(ceil(rate(istio_requests_total{destination_service_namespace="%{kube_namespace}", destination_app=~"%{function_name}.*"}[1m])*60))' + query_range: 'sum(ceil(rate(istio_requests_total{destination_service_namespace="%{kube_namespace}", destination_service=~"%{function_name}.*"}[1m])*60))' label: invocations / minute unit: requests diff --git a/db/post_migrate/20191209215316_knative_0_9_prometheus_update.rb b/db/post_migrate/20191209215316_knative_0_9_prometheus_update.rb new file mode 100644 index 0000000000000..52127f71cd089 --- /dev/null +++ b/db/post_migrate/20191209215316_knative_0_9_prometheus_update.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class Knative09PrometheusUpdate < ActiveRecord::Migration[5.2] + DOWNTIME = false + + def up + ::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute + end + + def down + # no-op + end +end diff --git a/db/schema.rb b/db/schema.rb index d3e9f66c3880e..352dea7e1b5a8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_12_16_183532) do +ActiveRecord::Schema.define(version: 2019_12_17_160632) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" diff --git a/spec/controllers/projects/serverless/functions_controller_spec.rb b/spec/controllers/projects/serverless/functions_controller_spec.rb index 73fb0fad646a1..33d66f4ac5ac4 100644 --- a/spec/controllers/projects/serverless/functions_controller_spec.rb +++ b/spec/controllers/projects/serverless/functions_controller_spec.rb @@ -149,6 +149,14 @@ def params(opts = {}) include_examples 'GET #show with valid data' end + + context 'on Knative 0.9.0' do + before do + prepare_knative_stubs(knative_09_service(knative_stub_options)) + end + + include_examples 'GET #show with valid data' + end end end @@ -210,6 +218,14 @@ def params(opts = {}) include_examples 'GET #index with data' end + + context 'on Knative 0.9.0' do + before do + prepare_knative_stubs(knative_09_service(knative_stub_options)) + end + + include_examples 'GET #index with data' + end end def prepare_knative_stubs(knative_service) diff --git a/spec/lib/gitlab/prometheus/queries/knative_invocation_query_spec.rb b/spec/lib/gitlab/prometheus/queries/knative_invocation_query_spec.rb index 0936d89545319..fa2dccc7c92d5 100644 --- a/spec/lib/gitlab/prometheus/queries/knative_invocation_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/knative_invocation_query_spec.rb @@ -16,12 +16,12 @@ create(:prometheus_metric, :common, identifier: :system_metrics_knative_function_invocation_count, - query: 'sum(ceil(rate(istio_requests_total{destination_service_namespace="%{kube_namespace}", destination_app=~"%{function_name}.*"}[1m])*60))') + query: 'sum(ceil(rate(istio_requests_total{destination_service_namespace="%{kube_namespace}", destination_service=~"%{function_name}.*"}[1m])*60))') end it 'has the query, but no data' do expect(client).to receive(:query_range).with( - 'sum(ceil(rate(istio_requests_total{destination_service_namespace="test-ns", destination_app=~"test-name.*"}[1m])*60))', + 'sum(ceil(rate(istio_requests_total{destination_service_namespace="test-ns", destination_service=~"test-name.*"}[1m])*60))', hash_including(:start, :stop) ) diff --git a/spec/models/clusters/applications/knative_spec.rb b/spec/models/clusters/applications/knative_spec.rb index 5b45dc078de66..c1057af5f80a8 100644 --- a/spec/models/clusters/applications/knative_spec.rb +++ b/spec/models/clusters/applications/knative_spec.rb @@ -123,7 +123,7 @@ subject { knative.install_command } it 'is initialized with latest version' do - expect(subject.version).to eq('0.7.0') + expect(subject.version).to eq('0.9.0') end it_behaves_like 'a command' diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index a3b527e0ffe3d..ad4ae93a02792 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -351,7 +351,7 @@ def kube_knative_pods_body(name, namespace) def kube_knative_services_body(**options) { "kind" => "List", - "items" => [knative_07_service(options)] + "items" => [knative_09_service(options)] } end @@ -539,6 +539,58 @@ def knative_07_service(name: 'kubetest', namespace: 'default', domain: 'example. "podcount" => 0 } end + # noinspection RubyStringKeysInHashInspection + def knative_09_service(name: 'kubetest', namespace: 'default', domain: 'example.com', description: 'a knative service', environment: 'production') + { "apiVersion" => "serving.knative.dev/v1alpha1", + "kind" => "Service", + "metadata" => + { "annotations" => + { "serving.knative.dev/creator" => "system:serviceaccount:#{namespace}:#{namespace}-service-account", + "serving.knative.dev/lastModifier" => "system:serviceaccount:#{namespace}:#{namespace}-service-account" }, + "creationTimestamp" => "2019-10-22T21:19:13Z", + "generation" => 1, + "labels" => { "service" => name }, + "name" => name, + "namespace" => namespace, + "resourceVersion" => "289726", + "selfLink" => "/apis/serving.knative.dev/v1alpha1/namespaces/#{namespace}/services/#{name}", + "uid" => "988349fa-f511-11e9-9ea1-42010a80005e" }, + "spec" => { + "template" => { + "metadata" => { + "annotations" => { "Description" => description }, + "creationTimestamp" => "2019-10-22T21:19:12Z", + "labels" => { "service" => name } + }, + "spec" => { + "containers" => [{ + "env" => + [{ "name" => "timestamp", "value" => "2019-10-22 21:19:12" }], + "image" => "image_name", + "name" => "user-container", + "resources" => {} + }], + "timeoutSeconds" => 300 + } + }, + "traffic" => [{ "latestRevision" => true, "percent" => 100 }] + }, + "status" => + { "address" => { "url" => "http://#{name}.#{namespace}.svc.cluster.local" }, + "conditions" => + [{ "lastTransitionTime" => "2019-10-22T21:20:15Z", "status" => "True", "type" => "ConfigurationsReady" }, + { "lastTransitionTime" => "2019-10-22T21:20:15Z", "status" => "True", "type" => "Ready" }, + { "lastTransitionTime" => "2019-10-22T21:20:15Z", "status" => "True", "type" => "RoutesReady" }], + "latestCreatedRevisionName" => "#{name}-92tsj", + "latestReadyRevisionName" => "#{name}-92tsj", + "observedGeneration" => 1, + "traffic" => [{ "latestRevision" => true, "percent" => 100, "revisionName" => "#{name}-92tsj" }], + "url" => "http://#{name}.#{namespace}.#{domain}" }, + "environment_scope" => environment, + "cluster_id" => 5, + "podcount" => 0 } + end + # noinspection RubyStringKeysInHashInspection def knative_05_service(name: 'kubetest', namespace: 'default', domain: 'example.com', description: 'a knative service', environment: 'production') { "apiVersion" => "serving.knative.dev/v1alpha1", -- GitLab