Repository: apache/camel-k
Pull request #1726 (2020-10-01 15:54:06)

[fix] Use bigger timeout to start querying metrics in test

llowinge: @astefanutti 
astefanutti: Hum, it seems the GitHub action has deleted the CHANGELOG.md file.
oscerd: > Hum, it seems the GitHub action has deleted the CHANGELOG.md file.

It should be because the changelog should be generated only on master branch, there was a PR from @christophd yesterday
astefanutti: @oscerd yes, I find it surprising that the file got deleted.

@llowinge would you mind force push your branch to override the second commit?
llowinge: @astefanutti Done, thank you.

Patch:
diff --git a/pkg/apis/camel/v1/knative/types.go b/pkg/apis/camel/v1/knative/types.go
index 430c2239a..c4147d6a8 100644
--- a/pkg/apis/camel/v1/knative/types.go
+++ b/pkg/apis/camel/v1/knative/types.go
@@ -33,11 +33,14 @@ func NewCamelEnvironment() CamelEnvironment {
 
 // CamelServiceDefinition defines the parameters to connect to Knative service. It's also used for exposed services
 type CamelServiceDefinition struct {
-	ServiceType CamelServiceType  `json:"type"`
-	Name        string            `json:"name"`
-	Host        string            `json:"host,omitempty"`
-	Port        *int              `json:"port,omitempty"`
-	Metadata    map[string]string `json:"metadata,omitempty"`
+	ServiceType CamelServiceType `json:"type"`
+	Name        string           `json:"name"`
+	// Deprecated: use URL instead
+	Host string `json:"host,omitempty"`
+	// Deprecated: use URL instead
+	Port     *int              `json:"port,omitempty"`
+	URL      string            `json:"url,omitempty"`
+	Metadata map[string]string `json:"metadata,omitempty"`
 }
 
 // CamelEndpointKind --
@@ -73,11 +76,6 @@ func (s CamelServiceType) ResourceDescription(subject string) string {
 // Meta Options
 const (
 	CamelMetaServicePath = "service.path"
-	CamelMetaServiceID   = "service.id"
-	CamelMetaServiceName = "service.name"
-	CamelMetaServiceHost = "service.host"
-	CamelMetaServicePort = "service.port"
-	CamelMetaServiceZone = "service.zone"
 
 	CamelMetaKnativeKind       = "knative.kind"
 	CamelMetaKnativeAPIVersion = "knative.apiVersion"
diff --git a/pkg/apis/camel/v1/knative/types_support.go b/pkg/apis/camel/v1/knative/types_support.go
index 796b89d3b..f98677436 100644
--- a/pkg/apis/camel/v1/knative/types_support.go
+++ b/pkg/apis/camel/v1/knative/types_support.go
@@ -20,19 +20,15 @@ package knative
 import (
 	"encoding/json"
 	"net/url"
-	"strconv"
 )
 
 // BuildCamelServiceDefinition creates a CamelServiceDefinition from a given URL
 func BuildCamelServiceDefinition(name string, endpointKind CamelEndpointKind, serviceType CamelServiceType,
 	serviceURL url.URL, apiVersion, kind string) (CamelServiceDefinition, error) {
 
-	port := 80
-
 	definition := CamelServiceDefinition{
 		Name:        name,
-		Host:        serviceURL.Host,
-		Port:        &port,
+		URL:         serviceURL.String(),
 		ServiceType: serviceType,
 		Metadata: map[string]string{
 			CamelMetaEndpointKind:      string(endpointKind),
@@ -40,17 +36,6 @@ func BuildCamelServiceDefinition(name string, endpointKind CamelEndpointKind, se
 			CamelMetaKnativeKind:       kind,
 		},
 	}
-	portStr := serviceURL.Port()
-	if portStr != "" {
-		port, err := strconv.Atoi(portStr)
-		if err != nil {
-			return CamelServiceDefinition{}, err
-		}
-		definition.Port = &port
-	}
-	if serviceURL.Path != "" {
-		definition.Metadata[CamelMetaServicePath] = serviceURL.Path
-	}
 
 	return definition, nil
 }
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index 5ff9c46cd..ed41b6b62 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -21,15 +21,16 @@ import (
 	"fmt"
 	"net/url"
 	"reflect"
+	"strconv"
 	"strings"
 
-	"github.com/apache/camel-k/pkg/util/kubernetes"
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	knativeapi "github.com/apache/camel-k/pkg/apis/camel/v1/knative"
 	"github.com/apache/camel-k/pkg/metadata"
 	"github.com/apache/camel-k/pkg/util"
 	"github.com/apache/camel-k/pkg/util/envvar"
 	knativeutil "github.com/apache/camel-k/pkg/util/knative"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/pkg/errors"
 	corev1 "k8s.io/api/core/v1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -243,6 +244,21 @@ func (t *knativeTrait) Apply(e *Environment) error {
 			}
 		}
 
+		// Convert deprecated Host and Port fields to URL field
+		// Can be removed once CamelSource controller migrate to the new API
+		for i, service := range env.Services {
+			if service.URL == "" {
+				URL := "http://" + service.Host
+				if service.Port != nil {
+					URL = URL + ":" + strconv.Itoa(*service.Port)
+				}
+				service.URL = URL
+				service.Host = ""
+				service.Port = nil
+				env.Services[i] = service
+			}
+		}
+
 		if err := t.configureChannels(e, &env); err != nil {
 			return err
 		}


Test patch:
diff --git a/e2e/yaks/monitoring/metrics.feature b/e2e/yaks/monitoring/metrics.feature
index 4c6cf18da..451f0ccad 100644
--- a/e2e/yaks/monitoring/metrics.feature
+++ b/e2e/yaks/monitoring/metrics.feature
@@ -6,7 +6,7 @@ Feature: Camel K can serve metrics to Prometheus
   Scenario: Integration gets the message from the timer
     Given integration metrics is running
     Then integration metrics should print Successfully processed
-    Then sleep 10000 ms
+    Then sleep 120000 ms
 
   Scenario: Thanos is able to serve custom microprofile annotation metrics
     Given HTTP request header Authorization is "Bearer TOKEN"
diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go
index 63586c95a..6bea95333 100644
--- a/pkg/trait/knative_test.go
+++ b/pkg/trait/knative_test.go
@@ -123,28 +123,28 @@ func TestKnativeEnvConfigurationFromTrait(t *testing.T) {
 
 	cSource1 := ne.FindService("channel-source-1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeChannel, "messaging.knative.dev/v1beta1", "Channel")
 	assert.NotNil(t, cSource1)
-	assert.Empty(t, cSource1.Host)
+	assert.Empty(t, cSource1.URL)
 
 	cSink1 := ne.FindService("channel-sink-1", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeChannel, "messaging.knative.dev/v1beta1", "Channel")
 	assert.NotNil(t, cSink1)
-	assert.Equal(t, "channel-sink-1.host", cSink1.Host)
+	assert.Equal(t, "http://channel-sink-1.host/", cSink1.URL)
 
 	eSource1 := ne.FindService("endpoint-source-1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service")
 	assert.NotNil(t, eSource1)
-	assert.Empty(t, eSource1.Host)
+	assert.Empty(t, eSource1.URL)
 
 	eSink1 := ne.FindService("endpoint-sink-1", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service")
 	assert.NotNil(t, eSink1)
-	assert.Equal(t, "endpoint-sink-1.host", eSink1.Host)
+	assert.Equal(t, "http://endpoint-sink-1.host/", eSink1.URL)
 	eSink2 := ne.FindService("endpoint-sink-2", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service")
 	assert.NotNil(t, eSink2)
-	assert.Equal(t, "endpoint-sink-2.host", eSink2.Host)
+	assert.Equal(t, "http://endpoint-sink-2.host/", eSink2.URL)
 
 	eEventSource := ne.FindService("default", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEvent, "eventing.knative.dev/v1beta1", "Broker")
 	assert.NotNil(t, eEventSource)
 	eEventSink := ne.FindService("default", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeEvent, "eventing.knative.dev/v1beta1", "Broker")
 	assert.NotNil(t, eEventSink)
-	assert.Equal(t, "broker-default.host", eEventSink.Host)
+	assert.Equal(t, "http://broker-default.host/", eEventSink.URL)
 }
 
 func TestKnativeEnvConfigurationFromSource(t *testing.T) {
@@ -243,8 +243,7 @@ func TestKnativeEnvConfigurationFromSource(t *testing.T) {
 
 	source := ne.FindService("s3fileMover1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service")
 	assert.NotNil(t, source)
-	assert.Empty(t, source.Host)
-	assert.Nil(t, source.Port)
+	assert.Empty(t, source.URL)
 	assert.Empty(t, source.Metadata[knativeapi.CamelMetaKnativeReply])
 
 	channel := ne.FindService("channel-source-1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeChannel, "", "")